MacOS Sonar-Scanner error: Compilation DB was found but 0 C/C++/Objective-C files were analyzed

I’m using Sonar-Cloud for C++ code static analysis of my open-source project Methane Kit for several years already as a part of GitHub Actions CI system. CI Sonar Scan workflow runs separately for Windows, Linux and MacOS to cover platform and API dependent code and submit results to platform-dependent projects on Sonar-Cloud. CI Code Scan was working fine 3 weeks ago on all platforms, then it did not run for several weeks due to blocking code issue, but when code was fixed I’ve noticed that sonar-scanner started failing on MacOS with error “java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed”, while it was working fine for other platforms (Windows and Linux). According to the error message I though that the problem was caused by build-wrapper issue somehow related to changes in build environment, like updated Xcode version, so I decided to switch from build-wrapper approach to compilation database generated by CMake with Ninja generator. Surprisingly, after changing workflow to generate and use compilation database for sonar-scanner, I received similar error on MacOS “java.lang.IllegalStateException: The Compilation Database JSON file was found but 0 C/C++/Objective-C files were analyzed”, while scans on Windows and Linux were working fine. Could you please help me to find a root cause of this issue and may be propose a solution to fix it?

Command line

sonar-scanner -X --define sonar.host.url=https://sonarcloud.io --define sonar.organization=methane-powered --define sonar.projectKey=methane-powered-kit-macos --define sonar.projectVersion=0.7.1.246 --define sonar.cfamily.compile-commands=Build/Output/Ninja-Mac-MTL-Scan/Build/compile_commands.json --define sonar.testExecutionReportPaths=Build/Output/Ninja-Mac-MTL-Scan/Install/Tests/Results/MethaneDataTypesTest.xml,Build/Output/Ninja-Mac-MTL-Scan/Install/Tests/Results/MethaneDataEventsTest.xml,Build/Output/Ninja-Mac-MTL-Scan/Install/Tests/Results/MethaneDataRangeSetTest.xml,Build/Output/Ninja-Mac-MTL-Scan/Install/Tests/Results/MethanePlatformInputTest.xml,Build/Output/Ninja-Mac-MTL-Scan/Install/Tests/Results/MethaneGraphicsTypesTest.xml,Build/Output/Ninja-Mac-MTL-Scan/Install/Tests/Results/MethaneGraphicsCameraTest.xml,Build/Output/Ninja-Mac-MTL-Scan/Install/Tests/Results/MethaneUserInterfaceTypesTest.xml --define sonar.coverageReportPaths=Build/Output/Ninja-Mac-MTL-Scan/Install/Tests/Coverage/Report/SonarQube.xml --define sonar.scm.revision=628ec12a83ca28241aa60c6f693e06a56c1218fd

sonar-project.properties

# Sonar Cloud projects common scanner configuration properties
# https://sonarcloud.io/organizations/methane-powered/projects

sonar.cloudName='Methane Powered Graphics'
sonar.organization=methane-powered
#sonar.projectKey=methane-powered-kit-(windows|linux|macos)

sonar.sources=Apps,Modules
sonar.tests=Tests
sonar.sourceEncoding=UTF-8
sonar.verbose=false

sonar.cfamily.cache.enabled=true
sonar.cfamily.cache.path=~/.sonar/cache

compile_commands.json (2.6 MB)

SonarScan.log (1.1 MB) with error

17:51:21.313 INFO: 95/644 files marked as unchanged
17:51:21.313 INFO: 13/22 test files marked as unchanged
17:51:21.314 INFO: Cache: 0/0 hits, 125 bytes
17:51:21.314 INFO: 0 compilation units analyzed
17:51:21.366 INFO: ------------------------------------------------------------------------
17:51:21.367 INFO: EXECUTION FAILURE
17:51:21.367 INFO: ------------------------------------------------------------------------
17:51:21.367 INFO: Total time: 37.849s
17:51:21.458 INFO: Final Memory: 39M/134M
17:51:21.458 INFO: ------------------------------------------------------------------------
17:51:21.458 ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: The Compilation Database JSON file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
  * you are correctly invoking the scanner with correct configuration
  * your compiler is supported
  * you are providing the path to the correct Compilation Database JSON
  * 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:62)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:51)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:468)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:464)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:420)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:130)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
	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)

Build.log (143.6 KB) proves that code builds successfully.

Other details can be found in GitHub Actions run output and zipped build artifacts.

Hi @egorodet ,

thank you for the detailed report, very useful!

The reason why 0 files are analyzed is that objective-c++ is not supported and files are skipped. All the files in the compile_commands.json have -x objective-c++ and you set OBJCXX language only on macOS. Are you really using Objective-C++?

Yes, you’re right. I root-caused this issue myself yesterday and set objective-c++ flag only for *.mm source files which are actually using it. As the result, other C++ files were normally analyzed. I’m using Obj-C++ for C++ class wrappers implementation around Obj-C Metal API. Do I correctly understand that Objective-C language is supported, but Objective-C++ is not?

@mpaladin Byt the way, is there any chance Objective-C++ would be supported by Sonar Cloud for static analysis? It looks to me like a combination of C++ and Objective-C code checks that need to be run for Objective-C++ source files. Or is it more complex than that?

Hi @egorodet,

Yes, you are right.

Even if it is mostly a combination of C++ and Objective-C, it would still require some work to support it, and we have not had a lot of requests for that.

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