Coverage for multiple builds with common modules

Server information:

  • Version: SonarQube Server Developer Edition v2025.1
  • Sonar Scanner CLI: 6.2.1.4610-linux-x64

My project (C code with CMake) has variables modules that can be included in a build. The project always has two builds, where both builds compile some of the same modules and also compile unique modules. So unit tests are run for both builds using gcov and the appropriate .gcno and .gcda files are produced for each build. Since there are duplicates between the two builds. What would be the best way to handle this?

I can generate the .gcov files for both builds, but now it’s just a matter of feeding it into SonarQube using the .properties file.

Hey there.

Beyond passing the directory to sonar.cfamily.gcov.reportsPath, what’s stopping you? Do you have two different paths based on the build? Something else?

Yes I have two build directories.

Hi @nathancsys,

At the moment, the property sonar.cfamily.gcov.reportsPath accepts only a single directory, and I assume that the file names in your gcov directories are identical (since they are derived from the names of the corresponding source files), so it is not simple to generate all the reports in the same directory. Therefore, I would suggest to try one of the following:

  1. Use an external tool like gcovr to merge coverage into a single report (as described in this page), then output a SonarQube xml file instead of the HTML (as described in this page). You can then feed that xml into SonarQube using the generic property sonar.coverageReportPaths.
  2. Place both of your report directories under a common directory, and pass that one to sonar.cfamily.gcov.reportsPath. The scanner will try to process all .gcov files under that directory recursively, so this may end up aggregating information from both. I never tried that before, but it may work.

I have also created CPP-7363 to support multiple build directories in the property in the future. Thanks for your feedback and let me know if any of the above suggestions works for you.

Best regards,
Michael

1 Like