(ommiting details like login, repo, project key, etc…)
sonar-scanner -Dsonar.pullrequest.base=master -Dsonar.pullrequest.branch=foo -Dsonar.coverageReportPaths=./build/code_coverage.xml -Dsonar.cfamily.compile-commands=./build/compile_commands.json
The problem with the above is if I try to add any sort of scoping rules via
sonar-project.properties, then all of the sudden the report starts filtering out header files and test files. This applies to both regular analysis and coverage analysis despite the documentation stating that analysis scoping rules don’t apply to coverage results.
sonar-project.properties file is specified, the header and test files appear in the analysis, and coverage is reported.
Here’s how the project is structured:
- project_foo/ - foo_utils/ - include/foo_utils/ - foo_util.h - src/ - version.cc.in (template for file generated as part of build) - test/ - test_foo_util.cc
This is a new project. Currently it consists of header-only code and tests for that code.
Here is a sample
sonar-project.properties file I’ve tried:
sonar.sourceEncoding=UTF-8 sonar.sources=\ foo_utils/src,\ foo_utils/include,\ sonar.tests=\ foo_utils/test
The resulting error:
[2022-07-14T04:04:26.211Z] ERROR: Error during SonarScanner execution [2022-07-14T04:04:26.211Z] java.lang.IllegalStateException: The Compilation Database JSON file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that: [2022-07-14T04:04:26.211Z] * you are correctly invoking the scanner with correct configuration [2022-07-14T04:04:26.211Z] * your compiler is supported [2022-07-14T04:04:26.211Z] * you are providing the path to the correct Compilation Database JSON [2022-07-14T04:04:26.211Z] * you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps
The behavior can be slightly different depending on the scoping rules. For instance in other scenarios we are not seeing any error, it’s just that the headers and test files are not included in the analysis.
Mainly I just want to understand why, when no scoping rules are present, the scanner seems to be able to handle headers just fine, but as soon as any are added, it starts ignoring them.