Facing problem while analyzing C code

Sonar server - Enterprise Edition Version 8.5.1 (build 38104)
Sonar scanner - sonar-scanner-4.6.2.2472-linux

Observing below issue while performing code analysis for C code on linux platform

INFO: 0 compilation units analyzed
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 19.778s
INFO: Final Memory: 32M/296M
INFO: ------------------------------------------------------------------------
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.execute(CFamilySensor.java:419)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:393)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:389)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:144)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

Steps involved:

  1. I have a directory structure like below
    parent_dir/
    ├── build_script.sh
    └── dir_to_be_analyzed
    dir_to_be_analyzed consists C code.

  2. Executing build wrapper

# cd parent_dir
# build-wrapper-linux-x86-64 --out-dir build_output sh build_script.sh

Above script will compile dir_to_be_analyzed

  1. Executing sonar scanner binary
# cd parent_dir/dir_to_be_analyzed
# sonar-scanner

Above mentioned error is observed.

sonar-project-properties available in dir_to_be_analyzed

sonar.cfamily.build-wrapper-output=parent_dir/build_output
sonar.projectVersion=1.0
sonar.sources=parent_dir/dir_to_be_analyzed
sonar.sourceEncoding=UTF-8
sonar.host.url=http://SONARQUBE_URL
sonar.cfamily.threads=10
sonar.cfamily.cache.enabled=false

Hello @ashutosh_gangwar and welcome to our community!

First:
What is inside build_script.sh, i.e. what build command are you using and is your build clean?

Then:
In your second step, the build-wrapper output is: “parent_dir/build_output”.
Whereas, if sonar-project.properties is in “parent_dir/dir_to_be_analyzed”, the build-wrapper output taken into account for the analysis is: “parent_dir/dir_to_be_analyzed/parent_dir/build_output”, so there is an inconsistency.
Is sonar-project.properties really in “parent_dir/dir_to_be_analyzed”?

Thanks for the response.
1st - build_script.sh consists compilations steps to compile lot of C code available along with multiple subfolders in dir_to_be_analyzed. Script is required as there are few dependencies regarding cross compilation(aarch64).

2nd - Yes, I have kept sonar-project.properties in parent_dir/dir_to_be_analyzed.

So did you try making the two specified build wrapper outputs consistent with each other?
For example, if you are executing build wrapper in parent_dir and if sonar-project.properties is in dir_to_be_analyzed, you could use

build-wrapper-linux-x86-64 --out-dir dir_to_be_analyzed/build_output sh build_script.sh

and

sonar.cfamily.build-wrapper-output=build_output

And you did not answer my first question, that is what is the compiler you are using and is your build clean (i.e. it rebuilds the whole project)?

To answer your first question.
build_script.sh uses another precompiled SDK to compile dir_to_be_analyzed.
To be more precise here is how build_script is executed.

cd parent_dir
sh build_script.sh -some_option <path to pre-compiled SDK> -some_option dir_to_be_analyzed

So I am executing build wrapper as mentioned below

cd parent_dir
build-wrapper-linux-x86-64 --out-dir dir_to_be_analyzed/build_output sh build_script.sh -some_option <path to pre-compiled SDK> -some_option dir_to_be_analyzed

and then executing sonar scanner from inside dir_to_be_analyzed using above sonar-project properties file.

You mean with the property sonar.cfamily.build-wrapper-output that points to the correct path build_output?
By the way, the property sonar.sources seems odd to me: shouldn’t it be sonar.sources=. if all C code is in the same directory than the sonar-project.properties file?

When all paths seem correct to you, could you share:

  • the content of build_output (there should be two files: build-wrapper.log and build-wrapper-dump.json
  • your sonar-project.properties
  • the output of sonar-scanner -X

please?
I can send you a PM if needed

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.