The Compilation Database JSON file was found empty

I run Sonar Cloud scanner manually and try to build the project, Project is build sucessfully using below command :-

build-wrapper-macosx-x86 --out-dir bw-output xcodebuild clean build -workspace Project.xcworkspace -scheme ProjectName
**** BUILD SUCCEEDED ****

But when i tried to run the scanner command it will gave me error :-

sonar-scanner
-Dsonar.organization=xyzdigital
-Dsonar.projectKey=xyzdigital_ios-app
-Dsonar.sources=.
-Dsonar.cfamily.compile-commands=bw-output/compile_commands.json
-Dsonar.host.url=https://sonarcloud.io

16:32:36.658 ERROR Error during SonarScanner Engine execution
java.lang.IllegalStateException: The Compilation Database JSON file was found empty. Please make sure to provide a non-empty file:
/Users/ABC/Documents/xyzdigital_ios-app/bw-output/compile_commands.json

at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:303)
at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:183)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:63)
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:192)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:188)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:159)
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.ScannerContainer.doAfterStart(ScannerContainer.java:416)
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:128)
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.ScannerMain.runScannerEngine(ScannerMain.java:135)
at org.sonar.scanner.bootstrap.ScannerMain.run(ScannerMain.java:52)
at org.sonar.scanner.bootstrap.ScannerMain.main(ScannerMain.java:38)

16:32:37.142 INFO EXECUTION FAILURE
16:32:37.148 INFO Total time: 2:43.685s

MACOS Version :- 14.4 (23E214)

Xcode Version :- 15.1 (15C65)

Based on [CPP-4941] - Jira

Hey there!

It seems you’ve already found the ticket describing the issue and the workaround. Were you able to follow the steps inside?

Hi There,

I tried the same steps but i got some error related to pods files.

Command which we tried :-

xcodebuild clean build -workspace projectName.xcworkspace -scheme ProjectName OTHER_CFLAGS=“$(inherited) -gen-cdb-fragment-path $(/Users/XYZ/Documents/projectName)/CompilationDatabase”

pushd ~/CompilationDatabase

sed -e ‘1s/^/['$’\n’‘/’ -e ‘$s/,$/'$’\n’‘]/’ *.json > …/compile_commands.json

popd

Error we got :-

PhaseScriptExecution [CP]\ Copy\ XCFrameworks /Users/xyz/Library/Developer/Xcode/DerivedData/xyz-gzdhdfrodipelobkclgbsiutvqvh/Build/Intermediates.noindex/Pods.build/Dev-iphoneos/ABCPOD.build/Script-BAD188F2B3A0595A7525F4143A5D921D.sh (in target ‘ABCPOD’ from project ‘Pods’)
ExtractAppIntentsMetadata (in target ‘ABCPOD2’ from project ‘Pods’)

and we can’t try to disable SIP beacuse we are using our organisation assets.

So do we have any other solution for this?

Which step gave you the error?

We got the Error when we run below command :-

xcodebuild clean build -workspace projectName.xcworkspace -scheme ProjectName OTHER_CFLAGS=“$(inherited) -gen-cdb-fragment-path $(/Users/XYZ/Documents/projectName)/CompilationDatabase”

pushd ~/CompilationDatabase

sed -e ‘1s/^/[‘$’\n’‘/’ -e ‘$s/,$/’$’\n’‘]/’ *.json > …/compile_commands.json

popd

Those are 4 seperate commands. Have you tried running them one at a time?

We tried all the comands one by one.

first we hit
xcodebuild clean build -workspace projectName.xcworkspace -scheme ProjectName OTHER_CFLAGS=“$(inherited) -gen-cdb-fragment-path $(/Users/XYZ/Documents/projectName)/CompilationDatabase”

then
pushd ~/CompilationDatabase

So pushd gave the error, not xcodebuild? xcodeBuild completed successfully?

No Its failing in first command itself :-

xcodebuild clean build -workspace projectName.xcworkspace -scheme ProjectName OTHER_CFLAGS=“$(inherited) -gen-cdb-fragment-path $(/Users/XYZ/Documents/projectName)/CompilationDatabase”