Is there any documentation available for C++ bazel sonarQube implementation?

it looks like Bazel generates coverage report in bazel-out/_coverage/_coverage_report.dat.
When I tried to use this coverage report in sonar using sonar.coverageReportPaths, it shows

19:20:50.743 INFO: Sensor Generic Coverage Report
19:20:50.743 INFO: Parsing /builds/repo/bazel-out/_coverage/_coverage_report.dat
19:20:50.813 INFO: ------------------------------------------------------------------------
19:20:50.813 INFO: ------------------------------------------------------------------------
19:20:50.813 INFO: Total time: 4:28.604s
19:20:50.951 ERROR: Error during SonarScanner execution
Error during parsing of the generic coverage report '/builds/nsx-allspark_users/m7/envoy-filters/bazel-out/_coverage/_coverage_report.dat'. Look at SonarQube documentation to know the expected XML format.

Are there any additional steps that need to be followed?
sonar info:

INFO: SonarScanner
INFO: Java 11.0.11 AdoptOpenJDK (64-bit)
INFO: Linux 5.4.0-122-generic amd64

Hey there.

SonarQube does not support importing Bazel .dat files. You can find out what SonarQube does support by looking at the documentation here:

Thanks for the reply. Is there a way to use that bazel coverage report in sonar? Somehow format/parse the file to XML based or covert the report to whichever format(llvm-cov) supported by sonar?

I haven’t tried this myself, but it looks like this could be useful:

Whether it supports C++? Looks like they used it for Java.

Also, for using llvm-cov should I mention all the files like this? linux-cmake-llvm-cov-gh-actions-sc/CMakeLists.txt at main · sonarsource-cfamily-examples/linux-cmake-llvm-cov-gh-actions-sc · GitHub

Because I’m having more than 200 files under diff sub-directories.
Is there any single line command in llvm-cov, to generate a coverage report by just mentioning the src (root) folder

Hi @Gobi_G ,

if I correctly understand you are looking to merge profile data files. As described in GitHub - sonarsource-cfamily-examples/linux-cmake-llvm-cov-gh-actions-sc: An example C++ repository built with CMake on Linux using GitHub Actions and analyzed on SonarCloud (test coverage by llvm-cov) you can use llvm-profdata merge.

1 Like

If you check the CMAKE file add_executable(coverage_test1 src/lib.cpp src/test1.cpp) they added the files for code coverage. In my case I have more than 200+ files for which a coverage report needs to generated. Should I have to add these here? Is there any option to directly point the directory and generate report?

Hi @Gobi_G ,

this line has nothing to do with coverage. This means that the build should produce an executable named coverage_test1 from the compilation of src/lib.cpp and src/test1.cpp.

Okay. Can I know the use of ./build/coverage_test1?

Currently, my project is configured with bazel and I don’t have any CMAKE file.
Can you please share the steps to create a coverage report?

Hi @Gobi_G ,

it executes the test which generates the coverage.

I am not a bazel expert, I am pretty sure that you can find many recipes on the web.

What I can tell you is that the steps to have coverage are:

  • you instrumentate your code to generate coverage information
  • you execute the instrumented binary which generates some information about executed code
  • you then transform the information about executed code to a report which can be imported