Xcodebuild in buildwrapper fails using Swift Packages on CI

xcodebuild in buildwrapper using Swift Packages on Virtual Machine

I had sonar scan working on my Obj-c/Swift project on Bitrise CI build. When we added a Swift package the build wrapper step started failing when trying to resolve the dependencies. The build works fine on Bitrise without the build wrapper but also the build wrapper build works fine on my machine. I opened a ticket with Bitrise and after some back and forth they said they need more info about the build wrapper.

The command being run is:

build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir build_wrapper_output_directory xcodebuild -workspace XXXXX.xcworkspace -scheme XXXXX clean build -destination id=XXXXX

The error I’m getting is:

Resolve Package Graph

build-wrapper: connect to /tmp/build-wrapper-socket.I4n37v: Operation not permitted

Resolved source packages:

SwiftUISegues: https://github.com/globulus/swiftui-segues @ main

xcodebuild: error: Could not resolve package dependencies:

build-wrapper: connect to /tmp/build-wrapper-socket.I4n37v: Operation not permitted

In the case above the swift package has already been fetched. If it has not already it throws a similar error while fetching.

Resolve Package Graph

Fetching from https://github.com/globulus/swiftui-segues

invalidManifestFormat("build-wrapper: connect to /tmp/build-wrapper-socket.JdQQ13: Operation not permitted", diagnosticFile: Optional(<AbsolutePath:"/Users/vagrant/Library/Developer/Xcode/DerivedData/GlookoFDA-asnxvgetmqqsfvhdvphsncnwpqdy/SourcePackages/ManifestLoading/swiftui-segues.dia">)) in https://github.com/globulus/swiftui-seguesxcodebuild: error: Could not resolve package dependencies:

invalidManifestFormat("build-wrapper: connect to /tmp/build-wrapper-socket.JdQQ13: Operation not permitted", diagnosticFile: Optional(<AbsolutePath:"/Users/vagrant/Library/Developer/Xcode/DerivedData/GlookoFDA-asnxvgetmqqsfvhdvphsncnwpqdy/SourcePackages/ManifestLoading/swiftui-segues.dia">)) in https://github.com/globulus/swiftui-segues

Bitrise support has said:

"Without any information on how build-wrapper works and what this socket is that it is trying to connect to is, I’m not sure we will be able to figure this out. Have you considered raising an issue/asking in sonar forum? If we could get more info on what it is doing, we might be able to determine what is going wrong. It seems like it is trying to connect to network socket. Given that the build is on a VM, I’m not exactly sure how or if that will even work.”

I found this related issue using CircleCI, but it was closed without a conclusion. https://community.sonarsource.com/t/xcodebuild-can-not-resolve-package-dependencies-using-build-wrapper-macosx-x86/32959

I was wondering you could help us out by letting us know how and why this socket is being used? Is there anyway to avoid the use of the socket? Are there any permissions the virtual device would need to be able to use it?

Hello @kathleen-glooko and welcome to our community!

Without going too much into the details, the build wrapper will observe what processes are run by xcodebuild in order to record the compilation options (e.g., include search paths, to name only one). The socket is created and used by the build wrapper for that purpose. Any configuration required to make it work in the virtual device is specific to that device. Therefore, it’s really hard to provide meaningful advice there.

However, if you cannot solve this configuration issue, you can rely on a compilation database instead of the build wrapper. See this link for more information: Analysis Steps Using Compilation Database. There should be a few tools out there to generate the compilation database automatically, for example from xcodebuild's output using xcpretty.

I hope this helps.

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