3

I'm running the build-wrapper like so:

build-wrapper-macosx-x86 --out-dir build_wrapper_output xcodebuild -project MyProject.xcodeproj -scheme All -configuration Release clean build

However, when I look at the result output the json file is empty:

# (C) SonarSource SA, 2014-2022, info@sonarsource.com
# All SONARSOURCE programs and content are copyright protected.
# SONARSOURCE and SONARQUBE are trademarks of SonarSource SA. All rights are expressly reserved.
#
# This file is designed exclusively for use with the SONARSOURCE C / C++ / Objective-C Plugin.
# It may not be used in connection with any other software.
# Any other use is prohibited by law and may be grounds for immediate termination of your License.
{
"version":"6.35",
"captures":[
]}

When I run xcodebuild normally the build works. Is there something I'm missing here? I tried reading the following and followed the instructions:

https://docs.sonarqube.org/latest/analysis/languages/cfamily/

KVISH
  • 12,923
  • 17
  • 86
  • 162

3 Answers3

2

Starting from macOS 13, wrapper is no longer working, I found below 2 steps to fix the issue

  1. First generate compile commands using xcpretty as suggested by sonar xcodebuild clean build | xcpretty --report json-compilation-database --output compile_commands.json

  2. Then use below sonar setting instead of sonar.cfamily.build-wrapper-output sonar.cfamily.compile-commands=compile_commands.json

If someone is interested what the heck is build wrapper and compilation database, read this page from Sonar https://www.sonarsource.com/blog/alternative-way-to-configure-c-and-cpp-analysis/

Trident
  • 810
  • 9
  • 20
1

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

balazs630
  • 3,421
  • 29
  • 46
0

Finally I found the solution. build wrapper doesnot support Mac os Ventura 13.x

SonarCommunity, Build wrapper is not working as expected, Objective C, XCode

logs

Initially, I had used this command: xcodebuild clean build -workspace PagaloTodo.xcworkspace -Scheme PagaloTodo and the build is successful.

I had tried passing others configuration options as arch, sdk, BUILD_LIBRARIES_FOR_DISTRIBUTION where also the build is successful but the build wrapper generated file is uncomplete.

There is a jira ticket created for same.

Dorian Turba
  • 3,260
  • 3
  • 23
  • 67
nethra
  • 16
  • 1
  • The alternative i found for now is to use the `compilation database`: https://docs.sonarqube.org/latest/analyzing-source-code/languages/c-family/#using-compilation-database – KVISH Feb 10 '23 at 08:01