compilation database question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

compilation database question

Joan Lluch via cfe-dev
hi Manuel,

i would like to clarify the compilation database format once more. i think the page 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 is broken, because the SOMEDEF is not JSON+shell escaped, but only JSON.

what do you think?

regards,
Laszlo 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: compilation database question

Joan Lluch via cfe-dev
On Mon, Aug 17, 2015 at 1:58 PM Laszlo Nagy <[hidden email]> wrote:
hi Manuel,

i would like to clarify the compilation database format once more. i think the page 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 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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev