[cfe-dev] compilation database question

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Fri Sep 4 04:37:08 PDT 2015


On Mon, Aug 17, 2015 at 1:58 PM Laszlo Nagy <rizsotto.mailinglist at gmail.com>
wrote:

> hi Manuel,
>
> i would like to clarify the compilation database format once more. i think
> the page <http://clang.llvm.org/docs/JSONCompilationDatabase.html> has a
> wrong example which might be misleading. i'm developing an application
> which tries to generate compilation database as output, so it would be nice
> to clarify the documentation a bit.
>
> here comes a simple test program.
>
>   void test(const char * const message) { }
>   int main() { test(MESSAGE); return 0; }
>
> this can be compiled from shell with this command:
>
>   $ clang -E test.c -DMESSAGE=\"hi\ there\" | grep -v ^#
>   void test(const char * const message) { }
>   int main() { test("hi there"); return 0; }
>
> to create a cmake file to compile this:
>
>   project(testing C)
>   cmake_minimum_required(VERSION 2.8)
>   add_definitions(-DMESSAGE="hi there")
>   add_executable(a.out test.c)
>
> from the console log i can see another compilation command. to see it does
> the same i checked manually...
>
>   $ clang -E -DMESSAGE="\"hi there\"" test.c | grep -v ^#
>   void test(const char * const message) { }
>   int main() { test("hi there"); return 0; }
>
> the cmake generated compile_commands.json looks like this:
>
>   [{
>     "directory": "/tmp",
>     "command": "/usr/bin/cc  -DMESSAGE=\"\\\"hi there\\\"\"   -o
> CMakeFiles/exec.dir/test.c.o   -c /tmp/test.c",
>     "file": "/tmp/test.c"
>   }]
>
> and it works with the clang tools (clang-check, clang-modernize,
> clang-tidy) the other working version would be this
>
>   [{
>     "directory": "/tmp",
>     "command": "/usr/bin/cc  -DMESSAGE=\\\"hi\\ there\\\"   -o
> CMakeFiles/a.out.dir/test.c.o   -c /tmp/test.c",
>     "file": "/tmp/test.c"
>   }]
>
> so, the example
> <http://clang.llvm.org/docs/JSONCompilationDatabase.html#format> is
> broken, because the SOMEDEF is not JSON+shell escaped, but only JSON.
>

Well, I thought the example would generate the command line:
-DSOMEDEF="With spaces, quotes and \-es."
which of course does not include the "s in the macro. If that is
unexpected, I'm happy for patches that clarify what exactly happens.

As you stumbled over this, it's obviously not clear enough and needs to be
improved!
 Cheers,
/Manuel

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150904/14844fb3/attachment.html>


More information about the cfe-dev mailing list