clang tool rejects compilation arguments from compilation database (incorrectly?)

Hello

I would like to introduce clang tooling to a fairly large code base with a custom build system. The first step i wanted to take is to manually create a compilation database file for one translation unit, and do some testing on that.

First, i added -### to the compilation flags, so i could get the actual compiler invocation. I took the ouput, and put it into a compile_command.json file. At this point, everything should have worked just fine, but it did not. My clang tool for testing is really simple, all it does is, it tries to run a clang::SyntaxOnlyAction on the given inputs.

If i try to run my tool on the TU that’s in my compilation database, i get errors. Here’s my compilation database: http://pastebin.com/6gsRHBEN and here is my output the tool gives me: http://pastebin.com/4AXfdF0r I also tried without the inner-quotes (http://pastebin.com/sWwyvbp8), the result’s the same.

What really bugs me is that if i open a terminal, switch to the ‘directory’, and copy-paste the content of the ‘command’ part (without JSON-escaping of course), clang compiles the file (and generates the object file) without any errors. Also, don’t know if relevant, but the project is built using an older xcode toolchain (based on clang 3.2), and i built my tool based on clang 3.5. Why does my tool reject totally valid arguments, what do i do wrong?

Thanks,
Peter

Clang has basically three command line flag parsing modes:
- the gcc-compatible clang driver, which is the standard command line interface
- the -cc1 command line interface, which is accessible via "clang -cc1
..." and is printed by -###
- the clang-cl command line interface, which is not relevant here

The tooling infrastructure expects your compilation database to
contain flags for the main gcc-style frontend, not the -cc1 subprocess
invocation. So -### won't help you here.

I believe we have some flag that prints the full clang command line
during the compile, but I've forgotten what it is.

To get a compilation database from a project:
https://github.com/rizsotto/Bear
might help.

Cheers,
/Manuel

Ø I believe we have some flag that prints the full clang command line
during the compile, but I’ve forgotten what it is.

If anyone could provide that information that would be useful to provide some understanding of how the clang driver (in various modes) remaps from gcc (or other style) options into the

internal options that the compiler really wants.

Thank you,

Kevin Smith