Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow configuring cc/cxx on analyze #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joprice
Copy link

@joprice joprice commented Mar 4, 2019

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 the cdb 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.

@rizsotto
Copy link
Owner

rizsotto commented Mar 4, 2019

Hey Joseph, did you try the --use-analyzer flag? That's suppose to be used to override the analyzer.

@joprice
Copy link
Author

joprice commented Mar 4, 2019

Yea but it never got that far to use the analyzer until I made this change.

@rizsotto
Copy link
Owner

rizsotto commented Mar 4, 2019

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.)

@joprice
Copy link
Author

joprice commented Mar 4, 2019

Right. I can try to make a repo to reproduce it if that helps. Maybe I'm missing something.

@joprice
Copy link
Author

joprice commented Mar 5, 2019

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.

@rizsotto
Copy link
Owner

rizsotto commented Mar 6, 2019

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?

@joprice
Copy link
Author

joprice commented Mar 6, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants