Exclude dont work with boost lib C++

9.7.1 (build 62043)
SonarQube deployed: zip

  • what are you trying to achieve
    I try to get a higher score of code coverage. I have C++ project, where make coverage show 73% coverage, then convert results in dir _coverage with gcov and run
sonar-scanner -Dsonar.cfamily.build-wrapper-output=_$BUILD_TYPE/.sonar --define sonar.cfamily.gcov.reportsPath="_coverage" --define sonar.branch.name=$CI_COMMIT_BRANCH \
    --define sonar.coverage.exclusions="app/**, /root/.hunter/_Base/17fd3b9/f845a29/f96017a/Install/include/boost/**/*.*, include/**, boost/**/*.*"

and sonarqube report shows 53% coverage.
I find this is because some files include Boost library files and sonar includes them in analysis.
for example log from make coverage
#17 0.197 ------------------------------------------------------------------------------
#17 0.197 GCC Code Coverage Report #17 0.197 Directory: .
#17 0.197 ------------------------------------------------------------------------------
#17 0.197 File Lines Exec Cover Missing
#17 0.197 ------------------------------------------------------------------------------
#17 0.197 libs/database/cursor.hpp 15 13 86% 29,57

and sonarqube log

761 NuPay
Coverage 80.0%
Bug 0
Vulnerability 0
Code Smell 13
Security Hotspot 0

But I exclude them higher.

What’s wrong?
here is log from sonarqube

The analyzer was not able to find file
#20 48.33   boost/endian/conversion.hpp
#20 48.33   included from file /builds/libs/database/cursor.hpp
#20 48.33   included from file /builds/libs/database/cursor.cpp
#20 48.33 
#20 48.33 This impacts the quality of the analysis and leads to inaccurate results.
#20 48.33 
#20 48.33 Please check that the file exists on your machine during the analysis:
#20 48.33 
#20 48.33 * if it doesn't, find a way to persist it after your build;
#20 48.33   all the files accessed during the build should be accessible during the analysis
#20 48.33 
#20 48.33 * if it does, please contact SonarSource support providing
#20 48.33   the full path to the file
#20 48.33     boost/endian/conversion.hpp
#20 48.33   and the file
#20 48.33     /builds/sonar-cfamily-reproducer.zip
#20 48.33 
#20 48.33 INFO: SE: 16 out of 154
#20 48.33 INFO: Z3 refutation rate: 0 out of 0
#20 48.33 WARN: 

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hello @Denis_Matveev and welcome to the community,

Could you please share the full output of the sonar-scanner command (preferably with the -X option)? This is helpful for us to identify the problem behind the exclusion of boost headers. Also, could you please share the files in your build-wrapper output directory (build-wrapper-dump.json and build-wrapper.log)? If these files contain sensitive data I can send you a message so that you can share them privately.

This error shouldn’t normally affect the coverage percentage, but it looks strange given that you are using the build-wrapper approach. The analyzer should be able to find boost headers as long as the compiler was able to during the wrapped build. Are you using an old build-wrapper output directory in -Dsonar.cfamily.build-wrapper-output? Do the scanner and the compiler both have access to the same filesystem (e.g. are you running them on different machines/containers, …)?

Please, send me a message and I can share logs with you.

Thanks for sharing the logs!

The problem is related to the fact that the “Coverage” reported on the dashboard is actually a hybrid metric that combines both “Line Coverage” and “Condition Coverage” in a single number. More details can be found here and here . This is why the number displayed by SonarQube is different from the one reported in the build, but “Line Coverage” and “Condition Coverage” on the metrics page match…

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.