Sonar Scanner cannot index cpp files even with build-wrapper and populated build-wrapper.json

Project information:

  • Versions
    • SonarQube: Community EditionVersion 8.9.1
    • Scanner: 4.6.2.2472
  • Deployed to AWS using cloudformation and an AMI with the bitnami community edition of sonarqube. An AWS build project runs the sonar-scanner CLI.
  • We are trying to get sonar scanner and sonarqube to recognize our cpp files and report our gcovr coverage report

So far we have tried:

  • fetching the state build-wrapper for cpp/linux and wrapping our make command in the command
  • passing --sonarqube <path/to/coverage.xml> to our gcovr command
  • moving our sonar-scanner command to run inside the container where the build happens
  • passing -Dsonar.cfamily.build-wrapper-output and -Dsonar.coverageReportPaths to the sonar-scanner command

Our current command looks like

java -jar sonar-scanner-4.6.2.2472/lib/sonar-scanner-cli-4.6.2.2472.jar \
    -Dsonar.projectKey=<project-key> \
    -Dsonar.host.url=${SONAR_URL} \
    -Dsonar.login=${SONAR_USERNAME} \
    -Dsonar.password=${SONAR_PASSWORD} \
    -Dsonar.branch.name=${BRANCH_NAME} \
    -Dsonar.cfamily.build-wrapper-output=./build_dir/build-wrapper \
    -Dsonar.coverageReportPaths=./build_dir/gcovr/sonarqube/coverage.xml \
    -Dsonar.sourceEncoding=UTF-8 \
    -Dsonar.sources=src \
    -Dsonar.verbose=true \

The build-wrapper.json is populated.

Here is a clean version of our log file:

INFO: Load active rules (done) | time=4702ms

DEBUG: Will ignore generated code
DEBUG: Will ignore generated code
INFO: Indexing files...
INFO: Project configuration:
DEBUG: loading config FileBasedConfig[/root/.config/jgit/config]
DEBUG: readpipe [/usr/bin/git, --version],/usr/bin
DEBUG: readpipe may return 'git version 2.34.1'
DEBUG: remaining output:
DEBUG: readpipe [/usr/bin/git, config, --system, --edit],/usr/bin
DEBUG: readpipe may return '/etc/gitconfig'
DEBUG: remaining output:
DEBUG: loading config FileBasedConfig[/etc/gitconfig]
DEBUG: loading config FileBasedConfig[/root/.gitconfig]
DEBUG: Thread[JGit-FileStoreAttributeReader-1,5,main]: start measure timestamp resolution /source (/dev/nvme0n1p1) in /source/.git
DEBUG: Thread[JGit-FileStoreAttributeReader-1,5,main]: end measure timestamp resolution /source (/dev/nvme0n1p1) in /source/.git; got PT0.000003S
DEBUG: Thread[JGit-FileStoreAttributeReader-1,5,main]: start measure minimal racy interval in /source/.git
DEBUG: Thread[main,5,main]: use fallback timestamp resolution for directory /source/.git
DEBUG: 551 non excluded files in this Git repository
DEBUG: 'src/CMakeLists.txt' indexed with no language
DEBUG: 'src/benchmark/BenchmarkTestData.cpp' indexed with no language
DEBUG: 'src/benchmark/BenchmarkTestData.h' indexed with no language
.... [Many other files here that I removed]
INFO: 400 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: ------------- Run sensors on module project-name
INFO: Load metrics repository
DEBUG: GET 200 ***/api/metrics/search?f=name,description,direction,qualitative,custom&ps=500&p=1 | time=215ms
INFO: Load metrics repository (done) | time=224ms
DEBUG: 'JavaSquidSensor' skipped because there is no related file in current project

INFO: Sensor CSS Rules [cssfamily]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor CSS Rules [cssfamily] (done) | time=1ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=4ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=1ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=2ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=4ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=1ms
INFO: Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor
INFO: Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor (done) | time=3ms
INFO: ------------- Run sensors on project

DEBUG: Sensors : Generic Coverage Report -> Zero Coverage Sensor
INFO: Sensor Generic Coverage Report
INFO: Parsing /source/build_dir/gcovr/sonarqube/coverage.xml
INFO: Imported coverage data for 0 files
INFO: Coverage data ignored for 155 unknown files, including:
[list of .cpp and .h files that we do want scanned]
INFO: Sensor Generic Coverage Report (done) | time=138ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=2ms
INFO: CPD Executor Calculating CPD for 0 files
INFO: CPD Executor CPD calculation finished (done) | time=0ms
DEBUG: SCM revision ID 'b2dae0d309602048ae5bf038057c0d57c78bbd4d'
INFO: Load New Code definition
DEBUG: GET 200 ***/api/new_code_periods/show.protobuf?project=project-name&branch=branch-name | time=231ms
INFO: Load New Code definition (done) | time=232ms
INFO: Analysis report generated in 289ms, dir size=94 KB
INFO: Analysis report compressed in 7ms, zip size=11 KB
INFO: Analysis report generated in /source/.scannerwork/scanner-report
DEBUG: Upload report
DEBUG: POST 200 ***/api/ce/submit?projectKey=project-name&characteristic=branch%3Dbranch-name&characteristic=branchType%3DBRANCH | time=274ms
INFO: Analysis report uploaded in 276ms
DEBUG: Report metadata written to /source/.scannerwork/report-task.txt
INFO: ANALYSIS SUCCESSFUL, you can browse 
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at 
DEBUG: Post-jobs : 
INFO: Analysis total time: 8.289 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 16.330s
INFO: Final Memory: 9M/47M
INFO: ------------------------------------------------------------------------

Do you have any debugging recommendations?

Thank you!

Hello,

I am afraid that the CFamily analyzer is not available on Community Edition. You would either need to switch to the Developer Edition (or higher) or use SonarCloud that supports C&C++ for free.

This said, SonarQube 8.9 is EOL. You should upgrade to 9.9 LTS whenever possible.

Thank you, that is good to know. I will try out the community plugin.

I will also suggest my team upgrade SonarQube soon.

Sorry to come back to this, but I have realized:

So, you are using build-wrapper? Normally it is downloaded from SonarQube, which would imply you have the CFamily analyzer. Is it really Community Edition?