Bitbucket C++ Coverage SonarCloud

Hi all, having a terrible time trying to get over 0% coverage for C, C++, and python code in one repository. I can get the project to analyze, but only three of my 100+ issues are C family errors (we definitely are not that clean) and I cannot get over 0% coverage no matter what I try. Any help is appreciated. Current pipeline configuration with bitbucket:

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - sonar
        size: 2x  # Increase the size to get more memory (1x, 2x, 4x, etc.)
        script:
          - git config --global --add safe.directory /opt/atlassian/pipelines/agent/build
          - sudo chown -R evi:evi .
          - git lfs install || true
          - git lfs update --force
          - git lfs pull
          - tar xzf soup_redux.tgz --directory /path/to/ev && mv -v /path/to/soup
          - ls -ld /path/to/soup/boost_1_80_0/boost
          - ln -s $(pwd) path/to/shared-libs
          - find /path/to/soup -type d
          - echo "Starting sonarcloud scan"
          - export SONAR_SCANNER_VERSION=6.2.1.4610
          - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-x64
          - export BW_OUTPUT=$HOME/.sonar/bw-output
          - mkdir -p $BW_OUTPUT
          - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux-x64.zip
          - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
          - export PATH=$SONAR_SCANNER_HOME/bin:$PATH
          - curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
          - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
          - export PATH=$HOME/.sonar/build-wrapper-linux-x86:$PATH
          - mkdir -p build
          - cd build
          - source /path/to/sharedlibs/env.bashrc && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
          - make clean
          - build-wrapper-linux-x86-64 --out-dir $BW_OUTPUT make all || true
          - sonar-scanner -Dsonar.cfamily.compile-commands=$BW_OUTPUT/compile_commands.json
        artifacts:
          - compile_commands.json

What do the logs say about importing code coverage when you try?

Analyzing your logs should also be useful if you doubt your C/C++ analsyis results. Do you see all the files you see to expect (sonar-scanner -X helps here). Are you performing a clean build to produce your compile commands?

Seeing a lot of this even though I have these set:

- sonar.cfamily.gcov.reportsPath: <empty>
14:52:44.374 DEBUG 'llvm-cov' skipped because of missing configuration requirements.
Accessed configuration:
- sonar.cfamily.llvm-cov.reportPath: <empty>
- sonar.cfamily.gcov.reportsPath: <empty>
14:52:44.375 DEBUG 'cppunit' skipped because of missing configuration requirements.
Accessed configuration:
- sonar.cfamily.cppunit.reportsPath: <empty>
- sonar.cfamily.llvm-cov.reportPath: <empty>
- sonar.cfamily.gcov.reportsPath: <empty>
14:52:44.375 DEBUG 'VisualStudioCoverage' skipped because of missing configuration requirements.
Accessed configuration:
- sonar.cfamily.vscoveragexml.reportsPath: <empty>
- sonar.cfamily.cppunit.reportsPath: <empty>
- sonar.cfamily.llvm-cov.reportPath: <empty>
- sonar.cfamily.gcov.reportsPath: <empty>
14:52:44.375 DEBUG 'bullseye' skipped because of missing configuration requirements.
Accessed configuration:
- sonar.cfamily.vscoveragexml.reportsPath: <empty>
- sonar.cfamily.cppunit.reportsPath: <empty>
- sonar.cfamily.llvm-cov.reportPath: <empty>
- sonar.cfamily.bullseye.reportPath: <empty>
- sonar.cfamily.gcov.reportsPath: <empty>
14:52:44.375 DEBUG 'cobertura' skipped because of missing configuration requirements.
Accessed configuration:
- sonar.cfamily.vscoveragexml.reportsPath: <empty>
- sonar.cfamily.cppunit.reportsPath: <empty>
- sonar.cfamily.llvm-cov.reportPath: <empty>
- sonar.cfamily.cobertura.reportPaths: <empty>
- sonar.cfamily.bullseye.reportPath: <empty>
- sonar.cfamily.gcov.reportsPath: <empty>
14:52:44.376 DEBUG 'Valgrind' skipped because of missing configuration requirements.
Accessed configuration:
- sonar.cfamily.vscoveragexml.reportsPath: <empty>
- sonar.cfamily.cppunit.reportsPath: <empty>
- sonar.cfamily.llvm-cov.reportPath: <empty>
- sonar.cfamily.cobertura.reportPaths: <empty>
- sonar.cfamily.valgrind.reportsPaths: <empty>
- sonar.cfamily.bullseye.reportPath: <empty>
- sonar.cfamily.gcov.reportsPath: <empty>
14:52:44.376 DEBUG 'Import external issues report from SARIF file.' skipped because of missing configuration requirements.
Accessed configuration:
- sonar.cfamily.vscoveragexml.reportsPath: <empty>
- sonar.cfamily.cppunit.reportsPath: <empty>
- sonar.cfamily.llvm-cov.reportPath: <empty>
- sonar.cfamily.cobertura.reportPaths: <empty>
- sonar.cfamily.valgrind.reportsPaths: <empty>
- sonar.cfamily.bullseye.reportPath: <empty>
- sonar.sarifReportPaths: <empty>
- sonar.cfamily.gcov.reportsPath: <empty>

Also a lot of these:


14:51:35.372 DEBUG Analyzing file: file:///opt/atlassian/pipelines/agent/build/build/Apps/DDS/CMakeFiles/json_subscriber_app_autogen.dir/compiler_depend.ts
14:51:35.373 DEBUG Analyzing file "/opt/atlassian/pipelines/agent/build/build/Apps/DDS/CMakeFiles/json_subscriber_app_autogen.dir/compiler_depend.ts" with linterId "default"
14:51:35.373 DEBUG Parsing /opt/atlassian/pipelines/agent/build/build/Apps/DDS/CMakeFiles/json_subscriber_app_autogen.dir/compiler_depend.ts with @typescript-eslint/parser
14:51:35.374 DEBUG Failed to parse /opt/atlassian/pipelines/agent/build/build/Apps/DDS/CMakeFiles/json_subscriber_app_autogen.dir/compiler_depend.ts with TypeScript parser: Invalid character.
14:51:35.374 WARN  Failed to parse file [Apps/DDS/CMakeFiles/json_subscriber_app_autogen.dir/compiler_depend.ts] at line 1: Invalid character.
14:51:35.374 DEBUG Cache entry created for key 'jssecurity:ucfgs:SEQ:10.20.0.29356:evidentvascular_evi-shared-libs:Apps/DDS/CMakeFiles/json_subscriber_app_autogen.dir/compiler_depend.ts' containing 0 file(s)
14:51:35.374 DEBUG Cache entry created for key 'jssecurity:ucfgs:JSON:10.20.0.29356:evidentvascular_evi-shared-libs:Apps/DDS/CMakeFiles/json_subscriber_app_autogen.dir/compiler_depend.ts'
14:51:35.374 DEBUG Cache entry created for key 'js:filemetadata:10.20.0.29356:evidentvascular_evi-shared-libs:Apps/DDS/CMakeFiles/json_subscriber_app_autogen.dir/compiler_depend.ts'
14:51:35.374 DEBUG Cache strategy set to 'WRITE_ONLY' for file 'CMakeFiles/Nightly.dir/compiler_depend.ts' as current analysis requires all files to be analyzed
14:51:35.374 DEBUG Analyzing file: file:///opt/atlassian/pipelines/agent/build/build/CMakeFiles/Nightly.dir/compiler_depend.ts
14:51:35.375 DEBUG Analyzing file "/opt/atlassian/pipelines/agent/build/build/CMakeFiles/Nightly.dir/compiler_depend.ts" with linterId "default"
14:51:35.376 DEBUG Parsing /opt/atlassian/pipelines/agent/build/build/CMakeFiles/Nightly.dir/compiler_depend.ts with @typescript-eslint/parser
14:51:35.376 DEBUG Failed to parse /opt/atlassian/pipelines/agent/build/build/CMakeFiles/Nightly.dir/compiler_depend.ts with TypeScript parser: Invalid character.
14:51:35.376 WARN  Failed to parse file [CMakeFiles/Nightly.dir/compiler_depend.ts] at line 1: Invalid character.
14:51:35.376 DEBUG Cache entry created for key 'jssecurity:ucfgs:SEQ:10.20.0.29356:evidentvascular_evi-shared-libs:CMakeFiles/Nightly.dir/compiler_depend.ts' containing 0 file(s)
14:51:35.376 DEBUG Cache entry created for key 'jssecurity:ucfgs:JSON:10.20.0.29356:evidentvascular_evi-shared-libs:CMakeFiles/Nightly.dir/compiler_depend.ts'
14:51:35.376 DEBUG Cache entry created for key 'js:filemetadata:10.20.0.29356:evidentvascular_evi-shared-libs:CMakeFiles/Nightly.dir/compiler_depend.ts'
14:51:35.376 DEBUG Cache strategy set to 'WRITE_ONLY' for file 'eviCommon/version/tests/CMakeFiles/evi_version_test.dir/compiler_depend.ts' as current analysis requires all files to be analyzed

Which ones did you set, and where? A sonar-project.properties file? Command line arguments? Something else?

I mostly have this figured out - one last thing. I’m getting the below output despite only having one of these set. my sonar-project.properties is also below.

sonar.organization=evidentvascular
sonar.projectKey=evidentvascular_evi-shared-libs
sonar.host.url=https://sonarcloud.io
sonar.projectVersion=1.0
sonar.sources=.
sonar.inclusions=**/*.h,**/*.cc
sonar.exclusions=**/compiler_depend.ts,**/googletest-src/**,build/**/*
sonar.sourceEncoding=UTF-8
sonar.python.version=3.11
sonar.branch.name=master
sonar.cfamily.build-wrapper-output=build/bw-output
sonar.cfamily.threads=4
sonar.cfamily.cache.enabled=false
sonar.cfamily.gcov.reportsPath=build/coverage-reports

Error:

0:01:03.087 INFO  173/173 source files have been analyzed
20:01:03.088 INFO  Sensor EnterpriseTextAndSecretsSensor [textenterprise] (done) | time=3137ms
20:01:03.088 INFO  Sensor CFamily [cpp]
20:01:03.166 INFO  CFamily plugin version: 6.62.0.78645 (829eaa25b0b1054f587bbeeb168e51409c72f905)
20:01:03.169 ERROR 
One configuration property is expected, 2 were found:
  "sonar.cfamily.build-wrapper-output"
  "sonar.cfamily.compile-commands"
20:01:03.180 ERROR Error during SonarScanner Engine execution
java.lang.UnsupportedOperationException: 
One configuration property is expected, 2 were found:
  "sonar.cfamily.build-wrapper-output"
  "sonar.cfamily.compile-commands"
	at com.sonar.cpp.plugin.AnalysisConfiguration.setupAnalysisConfigurationMode(AnalysisConfiguration.java:758)
	at com.sonar.cpp.plugin.AnalysisConfiguration.setupPluginPropertiesConfig(AnalysisConfiguration.java:144)
	at com.sonar.cpp.plugin.AnalysisConfiguration.<init>(AnalysisConfiguration.java:117)
	at com.sonar.cpp.plugin.CFamilySensor.prepareAnalysisConfig(CFamilySensor.java:391)
	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:215)
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:190)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:63)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:51)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:190)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:186)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:157)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.ScannerContainer.doAfterStart(ScannerContainer.java:416)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.ScannerMain.runScannerEngine(ScannerMain.java:137)
	at org.sonar.scanner.bootstrap.ScannerMain.run(ScannerMain.java:52)
	at org.sonar.scanner.bootstrap.ScannerMain.main(ScannerMain.java:38)
20:01:03.186 DEBUG Cleanup org.eclipse.jgit.util.FS$FileStoreAttributes$$Lambda$281/0x00007f41bc2c6000@417d6615 during JVM shutdown
20:01:03.519 DEBUG Java command exited with code 1
20:01:03.519 INFO  EXECUTION FAILURE
20:01:03.521 INFO  Total time: 29.325s

I mostly have this figured out - one last thing. I’m getting the below output despite only having one of these set. my sonar-project.properties is also below.

sonar.organization=evidentvascular
sonar.projectKey=evidentvascular_evi-shared-libs
sonar.host.url=https://sonarcloud.io
sonar.projectVersion=1.0
sonar.sources=.
sonar.inclusions=**/*.h,**/*.cc
sonar.exclusions=**/compiler_depend.ts,**/googletest-src/**,build/**/*
sonar.sourceEncoding=UTF-8
sonar.python.version=3.11
sonar.branch.name=master
sonar.cfamily.build-wrapper-output=build/bw-output
sonar.cfamily.threads=4
sonar.cfamily.cache.enabled=false
sonar.cfamily.gcov.reportsPath=build/coverage-reports

Error:

0:01:03.087 INFO  173/173 source files have been analyzed
20:01:03.088 INFO  Sensor EnterpriseTextAndSecretsSensor [textenterprise] (done) | time=3137ms
20:01:03.088 INFO  Sensor CFamily [cpp]
20:01:03.166 INFO  CFamily plugin version: 6.62.0.78645 (829eaa25b0b1054f587bbeeb168e51409c72f905)
20:01:03.169 ERROR 
One configuration property is expected, 2 were found:
  "sonar.cfamily.build-wrapper-output"
  "sonar.cfamily.compile-commands"
20:01:03.180 ERROR Error during SonarScanner Engine execution
java.lang.UnsupportedOperationException: 
One configuration property is expected, 2 were found:
  "sonar.cfamily.build-wrapper-output"
  "sonar.cfamily.compile-commands"
	at com.sonar.cpp.plugin.AnalysisConfiguration.setupAnalysisConfigurationMode(AnalysisConfiguration.java:758)
	at com.sonar.cpp.plugin.AnalysisConfiguration.setupPluginPropertiesConfig(AnalysisConfiguration.java:144)
	at com.sonar.cpp.plugin.AnalysisConfiguration.<init>(AnalysisConfiguration.java:117)
	at com.sonar.cpp.plugin.CFamilySensor.prepareAnalysisConfig(CFamilySensor.java:391)
	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:215)
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:190)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:63)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:51)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:190)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:186)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:157)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.ScannerContainer.doAfterStart(ScannerContainer.java:416)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.ScannerMain.runScannerEngine(ScannerMain.java:137)
	at org.sonar.scanner.bootstrap.ScannerMain.run(ScannerMain.java:52)
	at org.sonar.scanner.bootstrap.ScannerMain.main(ScannerMain.java:38)
20:01:03.186 DEBUG Cleanup org.eclipse.jgit.util.FS$FileStoreAttributes$Lambda$281/0x00007f41bc2c6000@417d6615 during JVM shutdown
20:01:03.519 DEBUG Java command exited with code 1
20:01:03.519 INFO  EXECUTION FAILURE
20:01:03.521 INFO  Total time: 29.325s

Hey there.

One of your first posts showed you configuring sonar.cfamily.compile-commands in your GitHub Action.

Is it possible that’s still there?

For what it’s worth, sonar.cfamily.build-wrapper-output is deprecated and you should use sonar.cfamily.compile-commands going forward.

Yes, I realize that! Forgot to mention this is my new configuration. Noted about the compile-commands; however, if I remove build-wrapper and use compile-commands instead, I get the exact same error. I have double checked my repository/commits.

Current pipeline configuration:

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - sonar
        size: 2x  # Increase the size to get more memory (1x, 2x, 4x, etc.)
        script:
          - git config --global --add safe.directory /opt/atlassian/pipelines/agent/build
          - sudo chown -R evi:evi .
          - git lfs install || true
          - git lfs update --force
          - git lfs pull
          - tar xzf soup_redux.tgz --directory /opt/evident && mv -v /opt/evident/soup_redux /opt/evident/soup
          - ls -ld /opt/evident/soup/boost_1_80_0/boost
          - ln -s $(pwd) /opt/evident/evi-shared-libs
          - find /opt/evident/soup -type d
          - echo "Starting sonarcloud scan"
          - source /opt/evident/evi-shared-libs/env.bashrc
          - echo $LD_LIBRARY_PATH
          - echo $SONAR_SCANNER_HOME
          - echo $BW_OUTPUT
          - mkdir -p $BW_OUTPUT
          - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.2.1.4610-linux-x64.zip
          - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
          - ls -la $HOME/.sonar/
          - curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
          - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
          - mkdir -p build
          - cd build
          - ls -la /opt/evident/evi-shared-libs
          - echo "Running cmake..."
          - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DENABLE_COVERAGE=ON ..
          - echo "Running build-wrapper..."
          - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir ../build/bw-output make all
          - echo "Running tests and generating coverage..."
          - ctest -E "(TestDialogManager|TestSingleFrameDisplay|CaseDataReader_TEST)"
          - pip install gcovr
          - export PATH=$PATH:/home/user/.local/bin
          - mkdir -p ../build/coverage-reports
          - gcovr -r .. --sonarqube ../build/coverage-reports/coverage.xml
          - cd ..
          - echo "Running sonar-scanner..."
          - $HOME/.sonar/sonar-scanner-6.2.1.4610-linux/bin/sonar-scanner
sonar.organization=organization
sonar.projectKey=key
sonar.host.url=https://sonarcloud.io
sonar.projectVersion=1.0
sonar.sources=.
sonar.inclusions=**/*.h,**/*.cc
sonar.exclusions=**/compiler_depend.ts,**/googletest-src/**,build/**/*
sonar.sourceEncoding=UTF-8
sonar.python.version=3.11
sonar.branch.name=master
sonar.cfamily.build-wrapper-output=build/bw-output
sonar.cfamily.threads=4
sonar.cfamily.cache.enabled=false
sonar.cfamily.gcov.reportsPath=build/coverage-reports

Thanks for the update! Can you check to see if maybe there’s some config left over in your project administration UI?

You can check under the project-level Administration > General Settings > Languages > C/C++/Objective-C

Wow, thank you. I didn’t know that was there. there was a path, so I deleted it, and swapped over to compile_commands.json. This is my current configuration for reference:

  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - sonar
        size: 2x  # Increase the size to get more memory (1x, 2x, 4x, etc.)
        script:
          - git config --global --add safe.directory /opt/atlassian/pipelines/agent/build
          - sudo chown -R evi:evi .
          - git lfs install || true
          - git lfs update --force
          - git lfs pull
          - tar xzf soup_redux.tgz --directory /opt/evident && mv -v /opt/evident/soup_redux /opt/evident/soup
          - ls -ld /opt/evident/soup/boost_1_80_0/boost
          - ln -s $(pwd) /opt/evident/evi-shared-libs
          - find /opt/evident/soup -type d
          - echo "Starting sonarcloud scan"
          - source /opt/evident/evi-shared-libs/env.bashrc
          - echo $LD_LIBRARY_PATH
          - echo $SONAR_SCANNER_HOME
          - mkdir -p build
          - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.2.1.4610-linux-x64.zip
          - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
          - ls -la $HOME/.sonar/
          - curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
          - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
          - cd build
          - ls -la /opt/evident/evi-shared-libs
          - echo "Running cmake..."
          - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DENABLE_COVERAGE=ON ..
          - echo "Running build-wrapper..."
          - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir . make all
          - echo "Verifying compile_commands.json:"
          - ls -l compile_commands.json
          - echo "Running tests and generating coverage..."
          - ctest -E "(TestDialogManager|TestSingleFrameDisplay|CaseDataReader_TEST)"
          - pip install gcovr
          - export PATH=$PATH:/home/user/.local/bin
          - mkdir -p ../build/coverage-reports
          - gcovr -r .. --sonarqube ../build/coverage-reports/coverage.xml
          - cd ..
          - echo "Running sonar-scanner..."
          - $HOME/.sonar/sonar-scanner-6.2.1.4610-linux-x64/bin/sonar-scanner -X
sonar.organization=evidentvascular
sonar.projectKey=evidentvascular_evi-shared-libs
sonar.host.url=https://sonarcloud.io
sonar.projectVersion=1.0
sonar.sources=.
sonar.inclusions=**/*.h,**/*.cc
sonar.exclusions=**/compiler_depend.ts,**/googletest-src/**,build/**/*
sonar.sourceEncoding=UTF-8
sonar.python.version=3.11
sonar.branch.name=master

# Updated C++ analysis configuration
sonar.cfamily.compile-commands=/opt/atlassian/pipelines/agent/build/build/compile_commands.json
sonar.cfamily.threads=4
sonar.cfamily.cache.enabled=false
sonar.cfamily.gcov.reportsPath=build/coverage-reports

# Optional: Add debug logging to help troubleshoot
sonar.verbose=true
sonar.log.level=DEBUG

Error message in bitbucket at last sonar-scanner command:
18:05:58.757 INFO 0/173 files marked as unchanged

2650

18:05:58.758 INFO Analysis cache: 0/0 hits, 125 bytes

2651

18:05:58.793 ERROR Error during SonarScanner Engine execution

2652

java.lang.IllegalStateException: The Compilation Database JSON file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:

2653

* you are correctly invoking the scanner with correct configuration

2654

* your compiler is supported

2655

* you are providing the path to the correct Compilation Database JSON

2656

* you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps

2657

at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:314)

2658

at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:190)

2659

at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:63)

2660

at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)

2661

at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:51)

2662

at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)

2663

at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)

2664

at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)

2665

at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:190)

2666

at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:186)

2667

at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:157)

2668

at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)

2669

at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)

2670

at org.sonar.scanner.bootstrap.ScannerContainer.doAfterStart(ScannerContainer.java:416)

2671

at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)

2672

at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)

2673

at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)

2674

at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)

2675

at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)

2676

at org.sonar.scanner.bootstrap.ScannerMain.runScannerEngine(ScannerMain.java:137)

2677

at org.sonar.scanner.bootstrap.ScannerMain.run(ScannerMain.java:52)

2678

at org.sonar.scanner.bootstrap.ScannerMain.main(ScannerMain.java:38)

2679

``

2680

18:05:58.797 DEBUG Cleanup org.eclipse.jgit.util.FS$FileStoreAttributes$Lambda$281/0x00007fc0e02c6000@4bee18dc during JVM shutdown

2681

18:05:59.143 DEBUG Java command exited with code 1

2682

18:05:59.143 INFO EXECUTION FAILURE

2683

18:05:59.145 INFO Total time: 28.234s

Darn.

I’ll open up a private message with you. If you can share your compile_commands.json, one of our experts can have a look and figure out why the code isn’t getting scanned.

Hello @something_clever ,

You have

sonar.inclusions=**/*.h,**/*.cc

but from your compile_commands.json, I see files such as

<redacted>.cpp

Have you tried adding **/*.cpp to your list of inclusions?

1 Like

I have! I just ran it again with that change since I’ve had a lot of parallel changes. When I add that inclusion, the scan does complete, but I still have 0% coverage. The compile_commands.json for the last run, a full pipeline log, and screenshots from sonarcloud are attached.

compile_commands.json (1.8 MB)
pipelineLog-{07c16f27-102d-4732-8f8e-a42e3816f25e} (1).txt (4.7 MB)


You have

sonar.cfamily.gcov.reportsPath=build/coverage-reports

but in the logs, I can see

gcovr -r .. --sonarqube ../build/coverage-reports/coverage.xml

sonar.cfamily.gcov.reportsPath expects files generated by gcov, not by gcovr (which can be confusing indeed!)

Since you are already generating a report using SonarQube format, you can use the property sonar.coverageReportPaths (see for instance this example)