Open joprice opened 5 years ago
Hey Joseph, did you try the --use-analyzer
flag? That's suppose to be used to override the analyzer.
Yea but it never got that far to use the analyzer until I made this change.
I'm confused, please help me to understand then. You have a JSON compilation database. (Could you show me one entry from it?) Then you want to run the static analyzer against those files. (That should not take --use-cc
or --use-cxx
flags, but the --use-analyzer
.)
Right. I can try to make a repo to reproduce it if that helps. Maybe I'm missing something.
Here's a repo that exhibits the issue https://github.com/joprice/bazel-ios-example. I have the compile_commands.json
checked in so you can see the structure. This file is generated by a python script, so I can easily change it to some other pattern that will work with scan-build.
Thanks Joseph. Was only looking at the repo, but did not run it (mainly because I have no OSX machine available). But one question interest me the most: Is that JSON compilation database works with any other programs? (clang-format? clang-tidy?)
I could not notice that the directory
field is referring to a temporary place. And the file
field (or the source file location in the command
field) is relative to that. Which raise me the concern that maybe the files are not there, no matter what compiler you try.
I did a little research on Bazel about a year before. It do bind mounts the needed source and header files before run the compiler. (This is how they guarantee that only those header files you see, what you were mentioned in the build file.) If the compilation database is created the way they execute the build, then scan-build (and other tools) will not work.
So, are the /private/var/tmp/_bazel_josephprice/a38239dd01545a603e73d1e5e6e896c9/execroot/__main__/src/main.m
and the /private/var/tmp/_bazel_josephprice/a38239dd01545a603e73d1e5e6e896c9/execroot/__main__/external/bazel_tools/tools/objc/objc_dummy.mm
exists?
When I make the above changes, all the paths work out and scan-build works for me. I have not tried with other tools yet. I can modify the example to be a plain c file.
When trying to use a compilation database generated from a bazel build, I found that analyze-build was finishing suspiciously quickly, and reporting no issues. After tracing this locally, I found that the code was trying to find 'cc' or 'c++' in the command for each entry. However, the command in the case of bazel is
external/local_config_cc/wrapped_clang
. I noticed that these strings are configurable via command line arguments when thecdb
flag is not being used, so I changed the argument parser to always include those flags. Not sure this is the right solution. If it is, I'd like to follow up with some tests.