Sonarqube Static Analysis failing for C++ on windows

Hi Team,
I am trying to setup Static Analysis of a C++ based code , As per Documentation I have downloaded the build wrapper and ran the compile step but still getting below error
Error during SonarScanner CLI execution
java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed.
Please find attached json file
build-wrapper-dump.json (7.7 MB)
FYI Code is compiled using QT and qmake

Hey there.

Can you please share the complete analysis logs, preferably at DEBUG level (sonar-scanner -X)?

Hi Colin,

Please find the, sonar scanner debug log, attached.

Regards,

Beethika Pandey

Senior Devops Engineer, India

Cytiva

M +91 7411287206

linkedin

cytiva.com

(attachments)

sonar_scanner.log (61.4 KB)

First things first, you should fix this warning in your build.

13:44:09   08:14:09.418 WARN
13:44:09   File
13:44:09     C:\TeamCityAgent\work\bccfbf32d04bae73\bw-output\build-wrapper-dump.json
13:44:09   was generated using build-wrapper version 6.61,
13:44:09   which does not match the analyzer version 6.41.0.60884.
13:44:09   
13:44:09   Please download the matching version from the server
13:44:09     https://sonarqube.cytiva.net/static/cpp/build-wrapper-win-x86.zip

You’re probably downloading the build wrapper from https://sonarcloud.io/static/cpp/build-wrapper-win-x86.zip, which doesn’t match what is installed on your SonarQube server.

Here you go, I have updated the build wrapper download source.
Attaching the log

Regards,

Beethika Pandey

Senior Devops Engineer, India

Cytiva

M +91 7411287206

linkedin

cytiva.com

(attachments)

sonar_scanner_update.log (50.9 KB)

Hi @beethika ,

given that you fixed the warning could you please share the up to date build-wrapper-dump.json that goes with it?

Hi ,

Please find json and corresponding log attached

Regards,

Beethika Pandey

Senior Devops Engineer, India

Cytiva

M +91 7411287206

linkedin

cytiva.com

(attachments)

bw-output.zip (444 KB)

Hi @beethika ,

thanks for the files. You are not getting any file analyzed because they are indexed as test.

For C and C++ files, you should index them as main source files using sonar.sources and not using sonar.tests.

We have the behavior described only in recent versions of SonarQube: Customizing the analysis | SonarQube Server Documentation

Hi,

Sorry I was on vacation so couldn’t reply.
Below is the command (in TeamCity CI) that I am using for sonar analysis

sonar-scanner\sonar-scanner-6.2.1.4610-windows-x64\bin\sonar-scanner.bat -D"sonar.host.url=https://sonarqube.cytiva.net" -D"sonar.projectKey=GoSilico-OnPrem" -D"sonar.projectName=GoSilico-OnPrem" -D"sonar.sources=code" -D"sonar.inclusions=code/chromx_aux,code/chromx_cmd,code/chromx_lib,code/chromx_tests,code/chromx_ui" -D"sonar.exclusions=.vscode,dependencies,redist,resources,scripts,vs_code_config_templete,/thirdparty/,/CMakeFiles/,/moc_*.cpp,/ui_.h,**/qrc_.cpp" -D"sonar.language=c++" -D"sonar.login=" -D"sonar.cfamily.build-wrapper-output=bw-output" -X

Here I have pass -D"sonar.sources=code” still same error
06:06:57.959 ERROR Error during SonarScanner CLI execution

11:36:57 java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:

11:36:57 * you are using the latest version of the build-wrapper and the CFamily analyzer

11:36:57 * you are correctly invoking the scanner with correct configuration

11:36:57 * your compiler is supported

11:36:57 * you are wrapping your build correctly

11:36:57 * you are wrapping a full/clean build

11:36:57 * you are providing the path to the correct build-wrapper output directory

11:36:57 * you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps

Regards,

Beethika Pandey

Senior Devops Engineer, India

Cytiva

M +91 7411287206

linkedin

cytiva.com

(attachments)

bw-output.zip (438 KB)

Hi,

Any update on my below issue.

@beethika

I suggest sharing your full scanner logs after making the configuration changes, like you did before, instead of just a snippet.

Hi @beethika ,

sorry but I was on holiday.

The sonar.inclusions is not correct, it should be a list of patterns. Could you please try a run removing sonar.inclusions and sonar.exclusions?

Hi Massimo,

No problem, Wish you a very happy new year :blush:

I tried removing inclusion and exclusion parameter now I am getting below error:

ERROR Error during SonarScanner CLI execution

org.sonar.api.utils.MessageException: File code/chromx_tests/chromx_tests.pro can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

Regards,

Beethika Pandey

Senior Devops Engineer, India

Cytiva

M +91 7411287206

linkedin

cytiva.com

Hi @beethika

That means that *.pro files are indexed by two analyzers. You can set -Dsonar.exclusions=**/*.pro.

Hi Massimo,

Thanks for your help.
Your suggestion worked :blush: after adjusting exclusion pattern scanner worked .

Again thanks a lot.

Regards,

Beethika Pandey

Senior Devops Engineer, India

Cytiva

M +91 7411287206

linkedin

cytiva.com

Hi @beethika ,

thank you for the feedback. I hope you managed to setup a good analysis of your project.