The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed C++ project

Hello colleagues!
I’m trying to scan my core project using sonar-scanner. Building using a build wrapper is successful.
And I get this error:

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:446)
        at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:175)
        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:392)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:388)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:357)
        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:150)
        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:
I cloned the project from GitHub
Downloaded and unpacked the latest version of the build wrapper in the project directory
Downloaded and unpacked the latest version of the sonar scanner in the project directory
Ran build wrapper from the project directory via command:

./build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output make TARGET=x200 clean all pkg

This building step was completed successfully, and the directory bw-output with files build-wrapper.log and build-wrapper-dump.json appeared
Then I ran the sonar scanner step via command:

./sonar-scanner-4.7.0.2747-linux/bin/sonar-scanner -Dsonar.projectKey=myproj -Dsonar.sources=. -Dsonar.cfamily.build-wrapper-output=bw-output -Dsonar.host.url=https://sonarqube.projhost.com -Dsonar.login=xxxff30dcaee83dd359a77b0c8ad7b8e841be6e2 -Dsonar.sourceEncoding=utf-8 -Dsonar.cfamily.threads=4 -Dsonar.exclusions=**/*.java,**/*.html -Dsonar.cfamily.cache.enabled=false

And after that, I got the error that I described above.

My configuration:

uname -a
Linux 8def5200109a 5.15.0-1023-aws #27-Ubuntu SMP Thu Oct 20 16:44:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.6 LTS"
./sonar-scanner-4.7.0.2747-linux/bin/sonar-scanner --version
INFO: Scanner configuration file: /usr/src/loki/sonar-scanner-4.7.0.2747-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.14.1 Eclipse Adoptium (64-bit)
INFO: Linux 5.15.0-1023-aws amd64
./build-wrapper-linux-x86/build-wrapper-linux-x86-64 --version
build-wrapper, version 6.20 (linux-x86)
Copyright (C) 2014-2021 SonarSource SA, info@sonarsource.com

What about questions:

  • you are using the latest version of the build-wrapper and the CFamily analyzer
    Yes, I use the latest versions
  • 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
    Yes, I use the same commands for my previous project on the same machine, and everything works properly there. My compiler is supported, and I run cleaning before too
  • you are providing the path to the correct build-wrapper output directory
    Yes, the path is correct
  • you are building and analyzing the same source checkout
    Yes, I’m building and analyzing absolutely the same source checkout in the same directory
  • absolute paths must be identical in build and analysis steps
    I don’t understand what it means. I run commands in the same project directory. It looks like absolute paths are identical

Also, I saw identical issues on the community forum, but I couldn’t find a solution.
If I got it right indexed files don’t exist. However, I don’t understand why it happens and how I can fix it. Because I just run command as usually, as on my previous projects.

build-wrapper-dump.json and build-wrapper.log attached to the topic

Thank you very much in advance!
build-wrapper-dump.zip (691.1 KB)
build-wrapper.log

Hi @RaiserZX,

What you are facing is a generic error. Can you try the same workflow with the latest SonarQube 9.8 with the latest build-wrapper?

If It still fails, can you share the new build-wrapper.json with the build-wrapper.log and the full scanner output?

Let me know if you prefer to share them privately.

Thanks,

Thank you!
I downloaded build-wrapper from https://sonarqube.vizio-is.com/static/cpp/build-wrapper-linux-x86.zip
I suppose that It is the latest version of the wrapper
Unfortunately, I cannot change SonarQube server version, because a lot of teams use one
Yes, it still fails, I can send full fresh logs to you in a private message?

All logs:

Thank you!

Maybe I need to provide more information about the error and the environment?

Hi @RaiserZX,

  • Is your compiler prebuilt/toolchain/armv7a/usr/bin/clang-9 statically linked?
  • can you try to wrap the build with the latest version of build-wrapper and share the new json/log. No need to execute the analysis (you aren’t supposed to do that with an old SQ, but let’s try it for debugging).
    Thanks,

Thank you!
I’ve tried to build with the latest version of build-wrapper. Logs:

However, I got the same result after the scanner ran: “java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed”

hi @RaiserZX,

From the log it seems that your compiler is:

toolchain/armv7a/usr/bin/clang+±9.elf

When we try to probe it, we expect to get the defined macros. This step is failing according to the log:

WARN: Invalid probe found, skip analysis of files: [/usr/src/loki/thirdparty/yoga/YGNode.cpp]
The compiler probe ‘stdout’ is expected to contain at least one ‘#define’ directive:

You can rerun the scanner -X (with the matching build-wrapper), this should print the probing command and its output.

Thanks,

sonar-scan.zip (1.2 MB)

@RaiserZX,

As you can see in the shared log, we aren’t able to access the compiler:

18:29:24.841 DEBUG: Probing compiler: [/release/apollo/third_party/source/CAST_TV/prebuilt/toolchain/armv7a/lib/ld-linux-x86-64.so.2, -x, c++, --std, gnu++1z, -target, armv7a-cros-linux-gnueabihf, --sysroot=/usr/src/loki/build_MTK5583/sysroot, -mthumb, -v, -dM, -E, -]

18:29:24.854 DEBUG: stdout:

18:29:24.855 DEBUG: stderr:

-x: error while loading shared libraries: -x: cannot open shared object file

How are you running your analysis? Are you running sonar-scanner or your build inside a docker container?
if yes, then this explains the problem: build and analysis should be run within the same environment.
The analyzer needs to access the files used during the build.

If not, please tell me more about your environment, are using a VM? what is the host?

Thanks,

hello Abbas!
Thank you for your answer!
It’s quite strange
I really use Docker container for building, however, I run it in the interactive mode. All sources are mounted as a directory there. Then I go into the container to the directory with sources and run building via the build-wrapper and after that, I run a sonar-scanner in the same directory. Between these steps, I do not leave the container.
It looks like I run commands for building on the usual Ubuntu Linux
I use an AWS EC2 instance with Ubuntu