[cfe-dev] Clang extra tools with compile_commands.json on windows

Hans Wennborg hans at chromium.org
Wed Jan 28 10:21:46 PST 2015


(Re-sending from the correct address; apologies if you receive this twice.)

On Wed, Jan 28, 2015 at 6:11 AM, Manuel Klimek <klimek at google.com> wrote:
>
>
> On Wed Jan 28 2015 at 2:57:26 PM adrien.courdavault
> <adrien.courdavault at gmail.com> wrote:
>>
>> Hello everyone.
>>
>> I would like to talk about an attempt to use clang-modernize and
>> clang-tidy,
>> and clang-analyzer on windows.
>> I'm using CMake 3 and Visual studio 2013.
>>
>> I would like to use the various great tools of clang to scan over my code
>> base, but these seems to take a compile_commands.json file as input (this
>> file should be in the build path provided by the "-p" option of those
>> tools).
>>
>> But sadly the CMAKE_EXPORT_COMPILE_COMMAND=ON option does not work with
>> the
>> visual generator (which I use)
>>
>> Some great people of Clang community are talking about  here
>>
>> <http://clang-developers.42468.n3.nabble.com/compile-commands-json-for-Windows-MSVC-tt4033848.html#none>
>>
>> Their point is that it could be in the future added to CMake, but that
>> they
>> would prefer to not rely on it. Anyway, because of this *"Richard" decided
>> to use the Log output of MSBuild to generate the compile_commands.json
>> file*
>> which he says should work.
>>
>> Therefore as I don't see any of this implemented yet in a public repo, I
>> decided to implement myself a little script to transform the output of the
>> MSBuild log (that i get using "/fl
>>
>> /fileLoggerParameters:LogFile=MSBuild.log;Append;Verbosity=normal;Encoding=UTF-8"
>> as options to MSBuild, and parse it to generate a compile_commands.json
>>
>> See here an example of a simple project which has only 1 cpp file:
>> compile_commands.json
>>
>> <http://clang-developers.42468.n3.nabble.com/file/n4043700/compile_commands.json>
>>
>> Then I used
>> *clang-modernize -p=<build-path> -summary -include=<src_dir>*
>> *clang-tidy -p=<build-path> src/main.cpp*
>> Which leads to a lot of warnings and an error because "<stdlib.h> could
>> not
>> be found.
>>
>> See the console log attached. log.log
>> <http://clang-developers.42468.n3.nabble.com/file/n4043700/log.log>
>>
>> Do you have any idea of what is wrong?
>>
>> Should I get as many errors, it looks like the tools don't understand the
>> flags?
>> Should this fail because of stdlib.h?
>> what could be a solution?
>> Is my use of the tools (command line parameters) right?
>
>
> There are 2 problems here:
> 1. you need to quote anything containing spaces, which includes the original
> command (you have spaces in the path)
> 2. clang needs to know it's in cl- mode; Hans might have an idea on how to
> solve this...


Right, I don't think anyone has been working on using these tools with
cl-style command-lines.

Getting the options parser to accept cl-style arguments is just a
matter of flipping a flag. The question is how to design it. Should
clang-tidy have an option for this? Should there be a clang-tidy-cl?
Should there be something in the json file?

The more difficult problem is that IIUC these tools don't go through
the Driver, in which clang-cl does stuff like figuring out include
paths, enabling -fms-extensions etc. Or maybe it does - how does
clang-tidy et al find system include files?

In any case, as it is today these tools are not ready to be used with
cl-style command-lines.

 - Hans



More information about the cfe-dev mailing list