How to create sonarscan for only .h file types

Hi Team,

i have source repository in git which has only .h files and i wanted to setup a sonar scan for the same but i am not able to do as my pipeline is failing with below error. can you please help me how to resolve this issue.

No report imported, no coverage information will be imported by JaCoCo XML Report Importer
2024-04-05T17:12:01.3002557Z 17:12:01.300 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2ms
2024-04-05T17:12:01.3003224Z 17:12:01.300 INFO: Sensor Python HTML templates processing [securitypythonfrontend]
2024-04-05T17:12:01.3078681Z 17:12:01.307 INFO: Sensor Python HTML templates processing [securitypythonfrontend] (done) | time=7ms
2024-04-05T17:12:01.3079528Z 17:12:01.307 INFO: Sensor IaC Docker Sensor [iac]
2024-04-05T17:12:01.3120366Z 17:12:01.311 INFO: 0 source files to be analyzed
2024-04-05T17:12:01.3594593Z 17:12:01.358 INFO: 0/0 source files have been analyzed
2024-04-05T17:12:01.3595102Z 17:12:01.359 INFO: Sensor IaC Docker Sensor [iac] (done) | time=52ms
2024-04-05T17:12:01.3595434Z 17:12:01.359 INFO: Sensor Serverless configuration file sensor [security]
2024-04-05T17:12:01.3600261Z 17:12:01.359 INFO: 0 Serverless function entries were found in the project
2024-04-05T17:12:01.3629453Z 17:12:01.362 INFO: 0 Serverless function handlers were kept as entrypoints
2024-04-05T17:12:01.3630949Z 17:12:01.363 INFO: Sensor Serverless configuration file sensor [security] (done) | time=3ms
2024-04-05T17:12:01.3631657Z 17:12:01.363 INFO: Sensor AWS SAM template file sensor [security]
2024-04-05T17:12:01.3638350Z 17:12:01.363 DEBUG: 0 SAM template configuration files were found in the project. 0 SAM function entries were found in total. 0 were kept as potential entrypoints.
2024-04-05T17:12:01.3638823Z 17:12:01.363 INFO: Sensor AWS SAM template file sensor [security] (done) | time=0ms
2024-04-05T17:12:01.3639111Z 17:12:01.363 INFO: Sensor AWS SAM Inline template file sensor [security]
2024-04-05T17:12:01.3644842Z 17:12:01.364 DEBUG: 0 SAM Inline template configuration files were found in the project. 0 SAM Inline function entries were found in total. 0 were kept as potential entrypoints.
2024-04-05T17:12:01.3645281Z 17:12:01.364 INFO: Sensor AWS SAM Inline template file sensor [security] (done) | time=1ms
2024-04-05T17:12:01.3645589Z 17:12:01.364 INFO: Sensor CFamily [cpp]
2024-04-05T17:12:01.4003199Z 17:12:01.399 INFO: CFamily plugin version: 6.41.1.62265
2024-04-05T17:12:01.4007050Z 17:12:01.400 INFO: Using build-wrapper output: /agent/_work/1/s/Cop/bw-outputs/build-wrapper-dump.json
2024-04-05T17:12:01.4017096Z 17:12:01.401 INFO: Available processors: 8
2024-04-05T17:12:01.4076250Z 17:12:01.407 INFO: Using 4 threads for analysis, according to value of "sonar.cfamily.threads" property.
2024-04-05T17:12:01.4182254Z 17:12:01.417 DEBUG: Total system memory: 29425037312
2024-04-05T17:12:01.4183172Z 17:12:01.418 DEBUG: Unpacking analyzer to: /agent/_work/1/s/Cop/.scannerwork/.sonartmp/10667744589072173654
2024-04-05T17:12:04.2299037Z 17:12:04.229 INFO: Found empty cache on server
2024-04-05T17:12:04.2467282Z 17:12:04.246 INFO: PCH: unique=0 use=0 (forceInclude=0,throughHeader=0,firstInclude=0) out of 0 (forceInclude=0,throughHeader=0)
2024-04-05T17:12:04.2467721Z 17:12:04.246 INFO: SE: 0 out of 0
2024-04-05T17:12:04.2467950Z 17:12:04.246 INFO: Z3 refutation rate: 0 out of 0

2024-04-05T17:12:04.2483891Z 17:12:04.248 INFO: 0/4 files marked as unchanged
2024-04-05T17:12:04.2484141Z 17:12:04.248 INFO: 0/1 test files marked as unchanged
2024-04-05T17:12:04.2484988Z 17:12:04.248 INFO: Cache: 0/0 hits, 124 bytes
2024-04-05T17:12:04.2485230Z 17:12:04.248 INFO: 0 compilation units analyzed
2024-04-05T17:12:04.2790585Z 17:12:04.278 INFO: ------------------------------------------------------------------------
2024-04-05T17:12:04.2790932Z 17:12:04.278 INFO: EXECUTION FAILURE
2024-04-05T17:12:04.2791321Z 17:12:04.278 INFO: ------------------------------------------------------------------------
2024-04-05T17:12:04.2792102Z 17:12:04.278 INFO: Total time: 18.276s
2024-04-05T17:12:04.3403933Z 17:12:04.340 INFO: Final Memory: 43M/154M
2024-04-05T17:12:04.3405086Z 17:12:04.340 INFO: ------------------------------------------------------------------------
2024-04-05T17:12:04.3405903Z 17:12:04.340 ERROR: Error during SonarScanner execution
2024-04-05T17:12:04.3407195Z java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
2024-04-05T17:12:04.3407656Z   * you are using the latest version of the build-wrapper and the CFamily analyzer
2024-04-05T17:12:04.3408011Z   * you are correctly invoking the scanner with correct configuration
2024-04-05T17:12:04.3408232Z   * your compiler is supported
2024-04-05T17:12:04.3408434Z   * you are wrapping your build correctly
2024-04-05T17:12:04.3408644Z   * you are wrapping a full/clean build
2024-04-05T17:12:04.3409007Z   * you are providing the path to the correct build-wrapper output directory
2024-04-05T17:12:04.3409350Z   * you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps
2024-04-05T17:12:04.3409689Z 	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:494)
2024-04-05T17:12:04.3410000Z 	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:215)
2024-04-05T17:12:04.3410328Z 	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
2024-04-05T17:12:04.3410692Z 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
2024-04-05T17:12:04.3411035Z 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:64)
2024-04-05T17:12:04.3411420Z 	at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
2024-04-05T17:12:04.3411801Z 	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
2024-04-05T17:12:04.3412181Z 	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
2024-04-05T17:12:04.3412549Z 	at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:403)
2024-04-05T17:12:04.3412924Z 	at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:399)
2024-04-05T17:12:04.3413309Z 	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:368)
2024-04-05T17:12:04.3413691Z 	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
2024-04-05T17:12:04.3414067Z 	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
2024-04-05T17:12:04.3414432Z 	at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:137)
2024-04-05T17:12:04.3414809Z 	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
2024-04-05T17:12:04.3415176Z 	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
2024-04-05T17:12:04.3415505Z 	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
2024-04-05T17:12:04.3415794Z 	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
2024-04-05T17:12:04.3416137Z 	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
2024-04-05T17:12:04.3416479Z 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2024-04-05T17:12:04.3416773Z 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2024-04-05T17:12:04.3417067Z 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2024-04-05T17:12:04.3417348Z 	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
2024-04-05T17:12:04.3417666Z 	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
2024-04-05T17:12:04.3417971Z 	at com.sun.proxy.$Proxy0.execute(Unknown Source)
2024-04-05T17:12:04.3418666Z 	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
2024-04-05T17:12:04.3419000Z 	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
2024-04-05T17:12:04.3419311Z 	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
2024-04-05T17:12:04.3419594Z 	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
2024-04-05T17:12:04.3419872Z 	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
2024-04-05T17:12:04.6762360Z 
2024-04-05T17:12:04.6814138Z ##[error]Bash exited with code '1'.
  • which versions are you using (SonarQube): * Enterprise Edition
  • Version 9.9 (build 65466)
  • how is SonarQube deployed: Docker

Hey there.

You can always adjust the analysis scope, but I think what you’re asking is: can you analyze .h files without a compilation (which is required for C/C++ analysis), and the answer to that is no.

Thanks @Colin for the response. actually our sonar-project.properties has common configuration for all the other C++ code as well so i am not sure how to make change . please refer the below snapshot.

# sonar.projectBaseDir=/component/

sonar.sources=.

sonar.exclusions=conanfile.py,azure-pipelines.yml,cmake-variants.yaml,**/unittest_results/**/*,**/gcov_sonar/**/*,package/**/*



sonar.cfamily.build-wrapper-output=outputs



sonar.sourceEncoding=UTF-8



sonar.scm.provider=git




sonar.tests=test_packages

sonar.cxx.xunit.reportPaths=unittest_results/*.xml



sonar.coverageReportPaths=gcov_sonar/sonarqube.xml

sonar.inclusions=**/*.h would do just fine

@Colin thanks for the solution, unfortunately when i made this change and ran the azure pipeline the Sonar project which was created for corresponding git repository got deleted automatically ? this was the 2nd instance where the sonar project is automatically getting deleted. i am not able to root cause what can trigger the deletion of the project in sonarqube portal. can you please help.

That doesn’t sound like normal behavior! I suggest creating a new thread describing the symptoms you’ve experienced over time (if this is the 2nd case). In the meantime, this thread should focus on the actual code analysis. I guess for now, recreate the deleted project.

@Colin thanks for the suggestion, i got the Conan repository created and ran the pipeline again with the changes you mentioned in previous post, but i am getting bellow error. can you please check and suggest.

INFO: Sensor CFamily [cpp] 
14:54:53.412 INFO: CFamily plugin version: 6.41.1.62265 
14:54:53.413 INFO: Using build-wrapper output: /agent/_work/17/s/Conanrepo/bw-outputs/build-wrapper-dump.json 
14:54:53.414 INFO: Available processors: 8 
14:54:53.419 INFO: Using 4 threads for analysis, according to value of "sonar.cfamily.threads" property. 
14:54:53.430 DEBUG: Total system memory: 29425016832 
14:54:53.430 DEBUG: Unpacking analyzer to: /agent/_work/17/s/Conanrepo/.scannerwork/.sonartmp/12672871904311270160 
14:54:56.662 INFO: Found empty cache on server 
14:54:56.679 INFO: PCH: unique=0 use=0 (forceInclude=0,throughHeader=0,firstInclude=0) out of 0 (forceInclude=0,throughHeader=0) 
14:54:56.679 INFO: SE: 0 out of 0 
14:54:56.679 INFO: Z3 refutation rate: 0 out of 0 
14:54:56.679 INFO: Subprocess(es) done in 17ms 
14:54:56.680 DEBUG: /agent/_work/17/s/Conanrepo/include/TlsProvider/dispatch.h not marked as unchanged: file added 
14:54:56.680 DEBUG: /agent/_work/17/s/Conanrepo/include/TlsProvider/signature.h not marked as unchanged: file added 
14:54:56.680 DEBUG: /agent/_work/17/s/Conanrepo/include/TlsProvider/provider.h not marked as unchanged: file added 
14:54:56.680 DEBUG: /agent/_work/17/s/Conanrepo/include/TlsProvider/keymgmt.h not marked as unchanged: file added 
14:54:56.681 INFO: 0/4 files marked as unchanged 
14:54:56.681 INFO: 0/1 test files marked as unchanged 
14:54:56.681 INFO: Cache: 0/0 hits, 124 bytes 
14:54:56.681 INFO: 0 compilation units analyzed 
14:54:56.956 INFO: ------------------------------------------------------------------------ 
14:54:56.956 INFO: EXECUTION FAILURE 
14:54:56.956 INFO: ------------------------------------------------------------------------ 
14:54:56.956 INFO: Total time: 18.622s 
14:54:56.999 INFO: Final Memory: 43M/160M 
14:54:56.999 INFO: ------------------------------------------------------------------------ 
14:54:56.999 ERROR: Error during SonarScanner execution 
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that: 
* you are using the latest version of the build-wrapper and the CFamily analyzer 
* you are correctly invoking the scanner with correct configuration 
* your compiler is supported 
* you are wrapping your build correctly 
* you are wrapping a full/clean build 
* you are providing the path to the correct build-wrapper output directory 
* you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps 
at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:494) 
at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:215) 
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64) 
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88) 
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:64) 
at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82) 
at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)

Hi @ajaya, and thanks for sharing the problem with us,

i have source repository in git which has only .h files.

How do you build your project then? As far as I can see, you are providing a non-empty build-wrapper output directory. Is this building your tests?

If this is the case, you can try adding your tests directory to your sonar.sources, and make sure the test source files are not excluded, so that the scanner can match the information collected during the build with the indexed files.

Additionally, please note that the sonar.tests property is not supported by the CFamily analyzer.

If adding your test directory to sonar.sources still doesn’t work. I would need to take a closer look at the produced build-wrapper output files (build-wrapper-dump.json and build-wrapper.log), and the verbose scanner output (sonar.verbose=true). Let me know if you would prefer to share these files in private, and I can start a private thread with you…

I hope this helps,

Best regards,
Michael

@michael.jabbour thanks for the response. can you please create a private thread for me, so that i can share the required details.

thanks