Error during SonarScanner execution- The "build-wrapper-dump.json" file was found but 0 C/C++/Object

Hello,

I have azure pipeline to build my project code on Ubuntu 22.0
log_files.zip (3.8 MB)
4 agent using gcc-arm-none-eabi-10.3-2021.10 compiler. I am in process to extend my pipeline to add sonarqube scanner. capabilities

I followed below steps:

  1. In Azure DevOps make Build Wrapper available on the build agent.
    curl ‘{SonarQube URL}/static/cpp/build-wrapper-linux-x86.zip’ --output build-wrapper.zip
    unzip build-wrapper.zip
  2. Added a new Prepare Analysis Configuration task before the build task.
  3. Modifed existing build bash task with wrapper
    chmod +x build-wrapper-linux-x86/build-wrapper-linux-x86-64
    build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw_output make clean all
    (Note, i added chmod as i was getting error - permission denied for build wrapper)
  4. Added a new Run Code Analysis task after the build task

I see build-wrapper-dump.json and build-wrapper.log is generated ( these files are not empty, and says 780 files are scanned). However, in run code analysis stage i get below error-

< ##[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: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)/>

I am using
Sonarqube version 5.17.2
SonarScanner version 4.8.1.3023
Build-wrapper-linux-x86-64

I am lost why is scanner failing here specially when the build-wrapper.jason file is generated.

Couple of questions,

  • Is build-wrapper-linux-x86-64 compatible to run on ubuntu 20.4 ?
  • How can i check if build-wrapper.jason file collected the information ? When i see this file i see all my files. so now wondering why scanner complaining on 0 c/c++ files were analyzed.

I am really stuck here so any help would be greatly appreciated,

Looking forward to some suggestions here.

Thanks

Query1920

Hi,

Your SonarScanner is a bit old; 5.0.1 is the current version. I doubt that’s the problem, but it wouldn’t hurt to upgrade it.

Can you take another shot at stating your SonarQube version? You’ll find it in your page footer.

And also, can you verify that:

 
Thx,
Ann

Hi Ann,

Thanks for suggestion.

SonarQube version:
image

I believe i am building & analyzing from the same directory:
image

Below is base & working directory
image

Thanks

Regards
Query1920

Hi,

I really need you to look in SonarQube at the page footer and give me the version information from there:

 
Thx,
Ann

Hi Ann,

Is this the information you are after-
image

Regards
Query1920

1 Like

Hi Ann,

Please let me know if you need any additional information from myside.

Regards
Query1920

Hi,

I’ve flagged this for more expert eyes.

 
Ann

Hi @query1920, and welcome to the community!

I had a look at the collected information in the build-wrapper dump you shared, and nothing looks suspicious there. I can also confirm that build-wrapper supports Ubuntu 20.4.

As the issue seems to happen during the scan, could you please share with us the full verbose scanner logs? The verbose logs can be obtained by adding any of -X , --verbose , or -Dsonar.verbose=true to your scanner command.

Best regards,
Michael

Hello Michael,

Attached is the log for your reference
Scanner_log.txt (23.0 KB)
.
I am really lost why the scanner is failing.
Please can you have a look and provide some suggestion.

Regards
Query1920

Hi @query1920, Could you please check that you have enabled verbose logging mode in the scanner?

  • I couldn’t see any debug messages in the logs you shared.
  • The error at the end of the logs still says:
    Re-run SonarScanner using the -X switch to enable full debug logging.
    

Best regards,
Michael

In Prepare Analysis configuration task in DevOps pipeline( this is where i am adding all sonar properties)
i added verbose as below

sonar.sourceEncoding=UTF-8

sonar.cfamily.build-wrapper-output=…/bw_output
sonar.cfamily.threads=2
sonar.projectBaseDir=…/
sonar.verbose= true

Did i miss anything here ?

Just for your info, the scanner is being called automatically from Run Code Analysis step from Azure DevOps as it connects with our organization server for sonarqube.

I updated my sonar properties with below statement
sonar.log.level=DEBUG

Attached is the log with Debug information
Scanner_log_debug.txt (471.6 KB)

I hope this gives you the information you are looking for.

Hi @query1920, thanks for attaching the debug logs!

I had a quick look and I could see that both build-wrapper and the scanner think they are running from the same directory /home/vsts/work/1:

{
"version":"6.41",
"captures":[
{
"compiler":"clang",
"cwd":"/home/vsts/work/1",

and the scanner logs:

INFO: Base dir: /home/vsts/work/1

However, the scanner log later says:

DEBUG: 's/wdp-hermes-app/Main.cpp' indexed with language 'cpp'
        ^^

Whereas, the build-wrapper dump json file references wdp-hermes-app/./Main.cpp without the s/ directory at the beginning.
Do you know where this extra s/ directory in the scanner environment comes from? Note that the paths of the files need to be identical while scanning and building in order for the scanner to use the information recoded during the wrapped build.

Hope this helps,

Best regards,
Michael

Hi Michael,

It was indeed the issue with the path for the scanner.
I always thought the scanner and wrapper were running via /home/vsts/work/1.
As you pointed out scanner was buried under the main directory from debug log. Now that i have moved scanner to run at the root directory in Prepare analysis Configuration step, Scanner execution was successful.

image

I was kind of stuck with this issue.
Thank you so much for your help.

Regards
Query1920

2 Likes

Hi @query1920,

Thanks for the update. Happy to know you got the analysis working!

Feel free to open a new thread if you have any additional feedback. :smile:

Best regards,
Michael

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