Bazel C++ analysis

  • SonarQube Developer 8.0
  • SonarQube Scanner 4.2.0.1873

Hi,

I’m having difficulties analysing a C++ project (not mine) which is using Bazel. The documentation on cfamily seems outdated(?) as the --batch command is deprecated and Bazel complains when I use --spawn_strategy=standalone --genrule_strategy=standalone

I currently have something in CI like:

$ bazel clean
$ build-wrapper-linux-x86-64 --out-dir sonar-dir bazel build //...
$ sonar-scanner -X \
        -Dsonar.cfamily.build-wrapper-output=sonar-dir \
        -Dsonar.cfamily.threads=4

However I get the error:

14:11:49.316 INFO: 0 compilation units analyzed
14:11:49.345 INFO: ------------------------------------------------------------------------
14:11:49.345 INFO: EXECUTION FAILURE
14:11:49.345 INFO: ------------------------------------------------------------------------
14:11:49.346 INFO: Total time: 22.017s
14:11:49.414 INFO: Final Memory: 22M/120M
14:11:49.415 INFO: ------------------------------------------------------------------------
14:11:49.415 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found empty. Please make sure that:
* you are using the latest version of the build-wrapper and the SonarCFamily analyzer
* your compiler is supported
* you are wrapping your build correctly
* you are wrapping a full/clean build
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:247)

Are there any other details which is available for analysing a Bazel C++ project? or is there something which I am missing?

Thanks in advance!

Hi @lawrence,

they are deprecated and at the same time they work and don’t affect the build. build-wrapper must be able to follow build processes, bazel by default runs on a daemon which is incompatible with build-wrapper. It is required to use those options in order to be able to collect bazel build information.

1 Like

Hi @mpaladin

Thanks for the response!

I’m using bazel 1.2.1 and get the following error when running the command:

/workspace# bazel clean
Starting local Bazel server and connecting to it...
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.

/workspace# build-wrapper-linux-x86-64 --out-dir sonar-dir bazel --batch --spawn_strategy=standalone --genrule_strategy=standalone build //...
[FATAL 10:57:52.091 src/main/cpp/blaze.cc:1286] Unknown startup option: '--spawn_strategy=standalone'.
  For more info, run 'bazel help startup_options'.

Am I using too new a version of bazel perhaps?

Hi @lawrence,

indeed you are right, checking new bazel version the options should be as follow:

build-wrapper-linux-x86-64 --out-dir sonar-dir bazel --batch build --spawn_strategy=standalone --genrule_strategy=standalone //...

spawn_strategy and genrule_strategy should come after build. Could you please confirm it works? I am going to update the documentation.

2 Likes

Hi @mpaladin

Yup that was exactly it! Thank you for your help!

1 Like