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

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
SonarQube Scanner 4.0.0.1744
 Java 11.0.3 AdoptOpenJDK (64-bit)
 Linux 5.4.0-91-generic amd64
 SonarQube server 8.9.1
CFamily plugin version: 6.20.1.32841
  • what are you trying to achieve
    I have a project which has kotlin, java and C++ code. Java and Kotlin code smells are working fine, but when it comes to C++ I am getting following error.
INFO: PCH: unique=0 use=0 (forceInclude=0,throughHeader=0,firstInclude=0) out of 0 (forceInclude=0,throughHeader=0)
INFO: SE: 0 out of 0
INFO: Subprocess(es) done in 24ms
INFO: 0 compilation units analyzed
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 56.770s
INFO: Final Memory: 42M/188M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found empty. Please make sure that:
  * you are using the latest version of the build-wrapper and the CFamily analyzer
  * your compiler is supported
  * you are wrapping your build correctly
  * you are wrapping a full/clean build
  * if you are building your project inside a Docker container, build-wrapper is wrapping the build process inside the container and not wrapping the external Docker process
        at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:442)
        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)
  • what have you tried so far to achieve this
    Instead of C++, if I enable CXX, it works fine, I mean I get the code smells and issues on dashboard.

=====================================================================

rm -f build-wrapper-linux-x86.zip

wget <build-wrapper-linux-x86.zip from server>
unzip build-wrapper-linux-x86.zip
export BUILDSCANNER=`pwd`/build-wrapper-linux-x86/
export PATH=$PATH:${BUILDSCANNER}

cd control
cmake --build . --target clean
build-wrapper-linux-x86-64 --out-dir ../build_output cmake -S . -B . 
cd ..

#Execution fails with above mentioned error,
sonar-scanner -X \
  -Dsonar.projectKey=<rootProj> \
  -Dsonar.host.url=<url> \
  -Dsonar.login=<login> \
  -Dsonar.branch.name=${BRANCH} \
  -Dsonar.c.file.suffixes=- \
  -Dsonar.cxx.file.suffixes=- \
  -Dsonar.cpp.file.suffixes=.cpp,.h \  
  -Dsonar.java.binaries=control/** \
  -Dsonar.java.libraries=**/** \
  -Dsonar.cfamily.threads=1 \
  -Dsonar.cfamily.cache.enabled=false \
  -Dsonar.cfamily.build-wrapper-output=build_output
  
  
   //Considers all .cpp as .cxx and works fine. No issues.
sonar-scanner \
  -Dsonar.projectKey=<rootProj> \
  -Dsonar.host.url=<url> \
  -Dsonar.login=<login> \
  -Dsonar.branch.name=${BRANCH} \
  -Dsonar.c.file.suffixes=- \
  -Dsonar.cpp.file.suffixes=- \
  -Dsonar.java.binaries=control/** \
  -Dsonar.java.libraries=**/** \
  -Dsonar.cfamily.threads=1 \
  -Dsonar.cfamily.cache.enabled=false \
  -Dsonar.cfamily.build-wrapper-output=build_output

=====================================================================

Due to security reasons, I can’t share build-wrapper.log or json
Alternate : I tried to copy C++ rules to CXX - Seems not possible. Is there anyway I can do that ?

Hi @VishwasKulkarni ,

you are now wrapping the build call with the build-wrapper, you are currently wrapping the cmake configuration call, to have correct C++ analysis you should change the sonar-scanner call to the following:

rm -f build-wrapper-linux-x86.zip

wget <build-wrapper-linux-x86.zip from server>
unzip build-wrapper-linux-x86.zip
export BUILDSCANNER=`pwd`/build-wrapper-linux-x86/
export PATH=$PATH:${BUILDSCANNER}

cd control
cmake -S . -B . 
build-wrapper-linux-x86-64 --out-dir ../build_output  cmake --build . --target clean
cd ..

#Execution fails with above mentioned error,
sonar-scanner -X \
  -Dsonar.projectKey=<rootProj> \
  -Dsonar.host.url=<url> \
  -Dsonar.login=<login> \
  -Dsonar.branch.name=${BRANCH} \
  -Dsonar.java.binaries=control/** \
  -Dsonar.java.libraries=**/** \
  -Dsonar.c.file.suffixes=- \
  -Dsonar.cpp.file.suffixes=.h,.cc,.cpp,.cxx,.c++,.hh,.hpp,.hxx,.h++,.ipp \ 
  -Dsonar.cfamily.threads=$(nproc) \
  -Dsonar.cfamily.cache.enabled=false \
  -Dsonar.cfamily.build-wrapper-output=build_output

I tried with below command.

cd controller
cmake -S . -B . 
build-wrapper-linux-x86-64 --out-dir ../build_output  cmake --build . --target clean
exit_code_cxx=$?

cd ..
sonar-scanner \
  -Dsonar.projectKey=<rootProj> \
  -Dsonar.host.url=<url> \
  -Dsonar.login=<login> \
  -Dsonar.branch.name=${BRANCH} \
  -Dsonar.java.binaries=controller/** \
  -Dsonar.java.libraries=**/** \
  -Dsonar.c.file.suffixes=- \
  -Dsonar.cpp.file.suffixes=.h,.cc,.cpp,.cxx,.c++,.hh,.hpp,.hxx,.h++,.ipp \
  -**Dsonar.cfamily.threads=$(nproc)** \
  -Dsonar.cfamily.cache.enabled=false \
  -Dsonar.cfamily.build-wrapper-output=build_output

and it did not solve the issue. Got this error

Error during SonarQube Scanner execution **13:13:59** ERROR: Language of file 'controller/CMakeFiles/3.18.1/CompilerIdCXX/CMakeCXXCompilerId.cpp' can not be decided as the file matches patterns of both sonar.lang.patterns.cxx : **/*.cpp and sonar.lang.patterns.cpp : **/*.h,**/*.cc,**/*.cpp,**/*.cxx,**/*.c++,**/*.hh,**/*.hpp,**/*.hxx,**/*.h++,**/*.ipp

Trails:
I added "-Dsonar.cxx.file.suffixes=- " to disable CXX and tried again but got below error.

13:15:48 ERROR: Error during SonarQube Scanner execution
13:15:48 java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found empty. Please make sure that:
13:15:48   * you are using the latest version of the build-wrapper and the CFamily analyzer
13:15:48   * your compiler is supported
13:15:48   * you are wrapping your build correctly
13:15:48   * you are wrapping a full/clean build
13:15:48   * if you are building your project inside a Docker container, build-wrapper is wrapping the build process inside the container and not wrapping the external Docker process
13:15:48 	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:442)
13:15:48 	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:175)
13:15:48 	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)

I feel I am making a mistake in sonar scanner command but I am not able to pinpoint it exactly.

Hi @VishwasKulkarni ,

the sonar-cxx plugin is not supported by SonarSource, I recommend either uninstalling it or referring to their support channel if interferes with the SonarSource CFamily plugin.

@mpaladin ,
I recommend either uninstalling it or referring to their support channel if interferes with the SonarSource CFamily plugin.

  • If possible could you provide links to their support channel.

And if possible could you tell me with the command you suggested I got the following error. What could be cause or any solution you want me to try.

=============================

Error during SonarQube Scanner execution **13:13:59** ERROR: Language of file 'controller/CMakeFiles/3.18.1/CompilerIdCXX/CMakeCXXCompilerId.cpp' can not be decided as the file matches patterns of both sonar.lang.patterns.cxx : **/*.cpp and sonar.lang.patterns.cpp : **/*.h,**/*.cc,**/*.cpp,**/*.cxx,**/*.c++,**/*.hh,**/*.hpp,**/*.hxx,**/*.h++,**/*.ipp
=============================

Hi @VishwasKulkarni ,

I don’t think that they can co-exist, I highly recommend that you pick one or the other, just uninstall sonar-cxx and give it a try. About their support channel just use any search engine to find their page and their support channel.

@mpaladin
We un-installed sonar-cxx from MarketPlace in sonarqube UI. We tried different combinations of commands on sonar-scanner, but all of them ended on same error message.

But still facing the same error with following command

cd controller
cmake -S . -B . 
build-wrapper-linux-x86-64 --out-dir ../build_output  cmake --build . --target clean
exit_code_cxx=$?

sonar-scanner \
  -Dsonar.projectKey=<rootProj> \
  -Dsonar.host.url=<url> \
  -Dsonar.login=<login> \
  -Dsonar.branch.name=${BRANCH} \
  -Dsonar.java.binaries=controller/** \
  -Dsonar.java.libraries=**/** \
  -Dsonar.c.file.suffixes=- \
  -Dsonar.cpp.file.suffixes=.h,.cc,.cpp,.cxx,.c++,.hh,.hpp,.hxx,.h++,.ipp \
  -**Dsonar.cfamily.threads=$(nproc)** \
  -Dsonar.cfamily.cache.enabled=false \
  -Dsonar.cfamily.build-wrapper-output=build_output
15:44:26 ERROR: Error during SonarQube Scanner execution
15:44:26 java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found empty. Please make sure that:
15:44:26   * you are using the latest version of the build-wrapper and the CFamily analyzer
15:44:26   * your compiler is supported
15:44:26   * you are wrapping your build correctly
15:44:26   * you are wrapping a full/clean build
15:44:26   * if you are building your project inside a Docker container, build-wrapper is wrapping the build process inside the container and not wrapping the external Docker process
15:44:26 	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:442)
15:44:26 	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:175)

Are there any other trial methods we could try ?

Hi @VishwasKulkarni ,

I overlooked the command above which only runs clean target, it should be:

build-wrapper-linux-x86-64 --out-dir ../build_output  cmake --build . --clean-first
1 Like

Thank you @mpaladin . I appreciate it.

Just one more doubt, what if I have to link android NDK library liblog.so with cmake command like below

export ANDROID_NDK_LIB=/home/<builder>/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/28/liblog.so

cmake -S . -B . -D lib-log=${ANDROID_NDK_LIB}
build-wrapper-linux-x86-64 --out-dir ../build_output  cmake --build . --clean-first

I get following error message and complete C++ report. I did try different ways to link the library like below(example)

cmake -S . -B . -D log-lib=${ANDROID_NDK_LIB}
build-wrapper-linux-x86-64 --out-dir ../build_output cmake --build . --target clean
build-wrapper-linux-x86-64 --out-dir ../build_output cmake --build .

Result was same: Complete C++ report, and below error while compiling.
Logs:

**21:35:39** The analyzer was not able to find file **21:35:39** android/log.h **21:35:39** included from file /mnt/spinner/jenkins/workspace/Sonarqube/daip_sonarqube_bitbucket_PCV_gen2/controller/ext/include/android/log/log.h **21:35:39** included from file /mnt/spinner/jenkins/workspace/Sonarqube/daip_sonarqube_bitbucket_PCV_gen2/controller/../aosp/diraceffect/gef_log.h **21:35:39** included from file /mnt/spinner/jenkins/workspace/Sonarqube/daip_sonarqube_bitbucket_PCV_gen2/controller/../aosp/diraceffect/dirac_effect.h **21:35:39** included from file /mnt/spinner/jenkins/workspace/Sonarqube/daip_sonarqube_bitbucket_PCV_gen2/aosp/diraceffect/gef-effect.cpp

@mpaladin any suggestions ?

Hi @VishwasKulkarni ,

are you able to get a successful build without build-wrapper? Could you try to get a successful build without build-wrapper and post the commands sequence?