Sonar analysis fails with cmake ninja build

I have been troubleshooting on running the build-wrapper for cmake. when I invoke the below shown commands , there will be no files been indexed by sonar scan and scan fails

  1. build-wrapper-linux-x86-64 --out-dir build-wrapper-output cmake -G Ninja …

  2. ninja dist

console o/p:

Using build-wrapper output: /users/integ/jenkins/sdc-c6b-1/workspace/Accelerator_Sonar/build-wrapper-output/build-wrapper-dump.json

java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed

12:56:21 INFO: 2/2 source files have been analyzed
12:56:21 INFO: Using build-wrapper output: /users/integ/jenkins/sdc-c6b-1/workspace/Accelerator_Sonar/build-wrapper-output/build-wrapper-dump.json
12:56:21 INFO: Available processors: 8
12:56:21 INFO: Using 2 threads for analysis according to value of “sonar.cfamily.threads” property.
12:56:36 INFO: Loading cache from: /users/integ/.sonar/cache/analysis_state
12:56:37 INFO: Subprocess(es) done in 54ms
12:56:37 INFO: Cache: 0/0 hits, 135 bytes
12:56:37 INFO: 0 compilation units analyzed
12:56:38 INFO: ------------------------------------------------------------------------
12:56:38 INFO: EXECUTION FAILURE
12:56:38 INFO: ------------------------------------------------------------------------
12:56:38 INFO: Total time: 1:41.619s
12:56:38 INFO: Final Memory: 65M/1279M
12:56:38 INFO: ------------------------------------------------------------------------
12:56:38 ERROR: Error during SonarQube Scanner execution
12:56:38 java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
12:56:38 * you are using the latest version of the build-wrapper and the CFamily analyzer
12:56:38 * you are correctly invoking the scanner with correct configuration
12:56:38 * your compiler is supported
12:56:38 * you are wrapping your build correctly
12:56:38 * you are wrapping a full/clean build
12:56:38 * you are providing the path to the correct build-wrapper output directory
12:56:38 * you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps
12:56:38 at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:385)
12:56:38 at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
12:56:38 at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
12:56:38 at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
12:56:38 at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
12:56:38 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
12:56:38 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
12:56:38 at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
12:56:38 at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
12:56:38 at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
12:56:38 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
12:56:38 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
12:56:38 at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
12:56:38 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
12:56:38 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
12:56:38 at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
12:56:38 at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
12:56:38 at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
12:56:38 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12:56:38 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
12:56:38 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
12:56:38 at java.lang.reflect.Method.invoke(Method.java:498)
12:56:38 at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
12:56:38 at com.sun.proxy.$Proxy0.execute(Unknown Source)
12:56:38 at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:185)
12:56:38 at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
12:56:38 at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
12:56:38 at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
12:56:38 at org.sonarsource.scanner.cli.Main.main(Main.java:61)
12:56:38 ERROR:
12:56:38 ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
12:57:45 WARN: Unable to locate ‘report-task.txt’ in the workspace. Did the SonarScanner succeed?
12:57:45 ERROR: SonarQube scanner exited with non-zero code: 1
12:58:00 Finished: FAILURE

Hello @vijay_kumar_kuruba,

Welcome to the community!

you should pass to build-wrapper the command that clean build your project.
cmake -G Ninja .. doesn’t build any file.

if ninja dist builds your project you should try something like:

cmake -G Ninja ..

build-wrapper-linux-x86-64 --out-dir build-wrapper-output ninja dist

Before running the scanner make sure that the build-wrapper command is building your project and that a non-empty .json file is generated.

Thanks,

thanks for update . but no luck . I see the same output after doing the changes to my command

cmake -G Ninja …

build-wrapper-linux-x86-64 --out-dir build-wrapper-output ninja dist

below is the .json file content

# © SonarSource SA, 2014-2020, info@sonarsource.com
# All SONARSOURCE programs and content are copyright protected.
# SONARSOURCE and SONARQUBE are trademarks of SonarSource SA. All rights are expressly reserved.
#
# This file is designed exclusively for use with the SONARSOURCE C / C++ / Objective-C Plugin.
# It may not be used in connection with any other software.
# Any other use is prohibited by law and may be grounds for immediate termination of your License.
{
"version":0,
"captures":[
]}

@vijay_kumar_kuruba What is the command line output that you get when you run: build-wrapper-linux-x86-64 --out-dir build-wrapper-output ninja dist? is it compiling your project from scratch?

below shown two commands used for compilation

scl enable devtoolset-7 rh-python36 'echo “Check Python Version” && python3 -V && cmake -G Ninja -S {BUILD_TOP}/flowtracer -B {BUILD_TOP}/RelBuild-ninja/ -D CMAKE_BUILD_TYPE=Release -D VENDORS_DIR={VENDORS} -D RLM_LICENSE={} -D VOV_EDITION_STRING={VOV_EDITION_STRING} -D VOV_EDITION_NUMBER=${P4_CHANGELIST} -D OPTION_DOCS_ENABLE_LINKCHECKER=YES -D OPTION_DOCS_GEN_INDEXHTML_ONLY=NO -D OPTION_DEBUG_MODE=ON -D OPTION_TBD_ENABLE_CMAKE_VENDORS=YES’console output.txt (1.2 MB)

scl enable devtoolset-7 rh-python36 'echo “====Starting ninja====” && cd RelBuild-ninja && ninja && if [ ? == 0 ]; then echo "====Starting ninja dist ===="; build-wrapper-linux-x86-64 --out-dir {BUILD_TOP}/build-wrapper-output ninja dist; fi’

@vijay_kumar_kuruba, can you share the build-wrapper.log file?

@vijay_kumar_kuruba, sorry i was confused with your “…” in build-wrapper-linux-x86-64 --out-dir build-wrapper-output cmake -G Ninja … I thought you meant previous dir (as sometimes the formatter change ... to .. .

can you wrap again the build comand (build-wrapper-linux-x86-64 --out-dir build-wrapper-output cmake -G Ninja -S {BUILD_TOP}/flowtracer -B {BUILD_TOP}/RelBuild-ninja/ -D CMAKE_BUILD_TYPE=Release -D VENDORS_DIR={VENDORS} -D RLM_LICENSE=7070@rlm1.int.rtda.com -D VOV_EDITION_STRING={VOV_EDITION_STRING} -D VOV_EDITION_NUMBER=${P4_CHANGELIST} -D OPTION_DEBUG_MODE=ON -D OPTION_TBD_ENABLE_CMAKE_VENDORS=YES’)

And share the new cmdline log + build-wrapper.log file.
build-wrapper should always wrap the command that build your project and “ninja dist” doesn’t in your case…

build-wrapper.log (232.7 KB) build-wrapper-dump.json (123.1 KB) console output.txt (1.2 MB)

@vijay_kumar_kuruba, From the .log, I can see that build-wrapper isn’t able to detect the last commands it stops just before:

  • export BUILD_TOP=/users/integ/jenkins/sdc-c6b-1/workspace/Accelerator_Sonar
  • BUILD_TOP=/users/integ/jenkins/sdc-c6b-1/workspace/Accelerator_Sonar
  • cd /users/integ/jenkins/sdc-c6b-1/workspace/Accelerator_Sonar
  • scl enable devtoolset-7 rh-python36 ‘echo “====Starting ninja====” && cd RelBuild-ninja && ninja && if [ $? == 0 ]; then echo “====Starting ninja dist ====”; ninja dist; fi’

how are you calling these commands? Is cmake executing postscript? what kind of script? would you mind sharing all these details?

As a quick workaround, you can just execute build-wrapper in your script on a lower level. instead of wrapping the cmake command, you can wrap the ninja command:
instead of

  • scl enable devtoolset-7 rh-python36 ‘echo “====Starting ninja====” && cd RelBuild-ninja && ninja && if [ $? == 0 ]; then echo “====Starting ninja dist ====”; ninja dist; fi’

  • scl enable devtoolset-7 rh-python36 ‘echo “====Starting ninja====” && cd RelBuild-ninja && build-wrapper-linux-x86-64 --out-dir build-wrapper-output ninja && if [ $? == 0 ]; then echo “====Starting ninja dist ====”; ninja dist; fi’

thanks @Abbas_Sabra ,
it really helped with that workaround…

1 Like

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