Previously we used build wrapper to collect information in a JSON file about Objective-C build configuration during build time.
Analysis steps using build wrapper
Unfortunately, build-wrapper currently doesn’t support macOS 13 Ventura and Apple Silicon.
[CPP-3987] - Jira
Sonar have clearly no plans to keep alive the build wrapper, see:
build-wrapper macOS: explicitly do not support macOS Ventura 13.x
and they closed this support ticket with only a workaround:
https://sonarsource.atlassian.net/browse/CPP-3987
“Use the JSON Compilation Database. To generate a Compilation Database:
if you are using Xcode, use xcpretty”
sudo gem install xcpretty
Sonar only mentions xcpretty
in the documentation for Xcode projects so I tried to generate the json dump with xcpretty
using this command:
xcodebuild clean build \
-workspace TestApp.xcworkspace \
-scheme TestApp \
-destination 'generic/platform=iOS' \
CODE_SIGN_IDENTITY='""' CODE_SIGN_ENTITLEMENTS='""' \
CODE_SIGNING_REQUIRED='NO' CODE_SIGNING_ALLOWED='NO' \
| xcpretty --report json-compilation-database --output xcpretty-compilation-database.json
xcpretty
doesn’t have any other flag which is relevant other than —report json-compilation-database
and —output
so there is no room to generate the compilation database in a different way.
Unfortunately Sonar analysis failed to process the resulting json produced by xcpretty:
INFO Reached stage: parsing
DEBUG [ParsingError] /Users/balazs630/development/TestApp/Common/Account.m:10
'Account.h' file not found
... and so on. Couldn't find the headers in the project.
Later it turned out that the problem is not with Sonar scanner, but with xcpretty which is buggy.
Luckily I found a poorly documented Xcode compile flag -gen-cdb-fragment-path
which generates a compilation database json fragment for each Objective-C file.
Then we needed to merge the ~150 fragment that was generated during the clean build into a single .json file to be able to pass it to sonar scanner.
The GitHub Gist page which led to the solution:
https://gist.github.com/T1T4N/f4d63a44476eb5c7046cc561cb8c7f77
from this post:
https://stackoverflow.com/a/73120984/7343596