Xcode Swift scan intermittently fails after 10.2 upgrade - wrapper issue

  • which versions are you using (
    • SonarQube: 10.2.0,
    • build-wrapper-macosx-x86 downloaded from instance
      • sonar.scanner.app=ScannerCLI
      • sonar.scanner.appVersion=4.8.0.2856
      • SonarQubePrepare (5.15.0)
      • SonarQubeAnalyze (5.15.0) )
    • macOS 12.6.9 (Microsoft Hosted Agent on Azure Pipelines )
    • Xcode 13.4.1
  • how is SonarQube deployed: zip
  • what are you trying to achieve: Scan Xcode Swift, Objective-C code

After upgrading from Sonarqube developer 10.0 to 10.2.0 we are seeing this error where the build failes, after rerunning the same build it succeeds as expected

I have looked at other releated issue in the community but nothing has helped

I do see the below env var set:
export DYLD_INSERT_LIBRARIES=/Users/runner/work/1/s/build-wrapper-macosx-x86/libinterceptor.dylib

Nothing in the pipeline has changed prior to and after the SonarQube, the only change is the SonarQube version used

Note:

We normally have aroud 20 builds during the day, 2 of which will fail with this issue. When we retry the failed job if succeeds (just retry, no other changes)

The build-wrapper-dump.json is empty on failed builds and nothing of note in the build-wrapper.log

strange how the wrapper works after a retry

build command:

./build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir ‘SonarData’ xcodebuild -configuration Debug -workspace /Users/runner/work/1/s/App/Project.xcworkspace -scheme MyScheme build CODE_SIGN_IDENTITY=‘Apple Development: Me (XYZ123)’

Error:

Resolve Package Graph

Resolved source packages:
  PhoneFormatterKit: /Users/runner/work/1/s/App/PhoneFormatterKit

xcodebuild: error: Could not resolve package dependencies:
  invalidManifestFormat("build-wrapper: connect to /tmp/build-wrapper-socket.x9i04M: Operation not 
    permitted", diagnosticFile: 
       Optional(<AbsolutePath:"/Users/runner/Library/Developer/Xcode/DerivedData/project- 
                 clfcozuapkrwfjftureqrckkkjeb/SourcePackages/ManifestLoading/phoneformatterkit.dia">))

      BUILD FAILED....

Hi @Darren13579 ,

if you are trying to scan Swift code, what is the reason to use the build-wrapper? Do you also have C, C++, or Objective-C files?

Are you able to reproduce the same issue locally?

Hi Massimo,

Yes looking to analize Swift, Objective-C iOS project

Tried locally with no issue

The issue started after upgrading SQ from 10.0 to 10.2.0

I noticed the build wrapper version is different between SonarQube 10.2.0 and 10.2.1

SonarQube 10.2.0:
build-wrapper, version 6.48.1 (macosx-x86)

SonarQube 10.2.1
build-wrapper, version 6.49 (macosx-x86)

what changes were made in these two version and would this relate to the issue I am having

Thanks

Hi @Darren13579 ,

There is no relevant change between those two versions.

I can observe some random failures on Azure DevOps with some internal jobs that sometimes fail and relaunch usually succeeds. It is not clear what could be the cause. Have you ever experienced the same issue outside of Azure DevOps?

As a note, I noticed in the logs that the failed ones have a different image version:

Operating System
macOS
12.6.9
21G726
Runner Image
Image: macos-12
Version: 20230921.1
Included Software: https://github.com/actions/runner-images/blob/macOS-12/20230921.1/images/macos/macos-12-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/macOS-12%2F20230921.1

the succeeding jobs seem to have:

Operating System
macOS
12.7
21G816
Runner Image
Image: macos-12
Version: 20230921.4
Included Software: https://github.com/actions/runner-images/blob/macOS-12/20230921.4/images/macos/macos-12-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/macOS-12%2F20230921.4

Also, it seems that 20230921.1 has been deleted from GitHub - actions/runner-images: GitHub Actions runner images. Could you check if you are seeing the same on your side?

Hi Massimo,

I did observe the same thing with the failures across different images

Not sure if this was isolated or just a conciende after ther10.2 upgrade.

We are now on SonarQube 10.2.1 with the same issue.

We have decided to remove the wrapper from our CI pipelines now in favor of xcpretty for the compilation database

  xcodebuild 
    -configuration Debug 
    -workspace /Users/runner/work/1/s/App/Project.xcworkspace 
    -scheme Project
     build | xcpretty --report json-compilation-database --output compile_commands.json

and sonar prepare property:
sonar.cfamily.compile-commands=compile_commands.json

Would you be able to check the logs and see if it was the same image?

I do not recommend to use xcpretty as it is buggy. Clang compiler has a built-in feature (-gen-cdb-fragment-path ) to create the compilation database:

xcodebuild 
    -configuration Debug \
    -workspace /Users/runner/work/1/s/App/Project.xcworkspace \
    -scheme Project \
     build \
     OTHER_CFLAGS="\$(inherited) -gen-cdb-fragment-path \$(PROJECT_DIR)/CompilationDatabase"
pushd CompilationDatabase
sed -e '1s/^/[\'$'\n''/' -e '$s/,$/\'$'\n'']/' *.json > ../compile_commands.json
popd

and sonar property:
sonar.cfamily.compile-commands=compile_commands.json