Hi there. First things first:
- ALM used: GitHub
- CI system used: GitHub Actions
- Languages of the repository: C++
I am developing a header-only C++ library and I want to analyze it using a free tier account at SonarCloud. I should say that I am also using a very similar configuration in another project where things work perfectly but the critical difference is that the other project has translation units of its own, that is, it is not a header-only library.
My problem is that SonarCloud apparently does not support analysis of pure headers isolated from the translation units they are included into. If I use the most straightforward configuration like this (the command line is broken into several lines for clarity here; authentication options not shown):
sonar-scanner
--define sonar.sources=include
--define sonar.cfamily.gcov.reportsPath=.
--define sonar.cfamily.cache.enabled=false
--define sonar.cfamily.threads=1
--define sonar.cfamily.build-wrapper-output=.
Then I get the obvious error:
The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed.
Okay, that is clear; indeed, there are no .cpp files under include/
. Upon reading the docs on “Narrowing the scope” I modified the invocation as follows:
sonar-scanner
--define sonar.sources=include,tests/integration,tests/unit,tests/util
--define sonar.inclusions=include
--define sonar.cfamily.gcov.reportsPath=.
--define sonar.cfamily.cache.enabled=false
--define sonar.cfamily.threads=1
--define sonar.cfamily.build-wrapper-output=.
The sonar-scanner reported success but the web UI says that the project contains zero lines of code.
How do I invoke sonar-scanner correctly for a header-only project considering that I don’t want to analyze my tests?
Thanks!
Edit: I also tried this which failed with “0 C++ files were analyzed”:
sonar-scanner
--define sonar.sources=include
--define sonar.tests=tests/integration,tests/unit,tests/util
--define sonar.cfamily.gcov.reportsPath=.
--define sonar.cfamily.cache.enabled=false
--define sonar.cfamily.threads=1
--define sonar.cfamily.build-wrapper-output=.