swift-package-manager: Could not generate PIF

Description

After updating to Xcode 14 xcodebuild failing on my SPM fixture with:

❌  error: Build service could not create build operation: internal error: could not generate PIF because the workspace has not finished loading or is still waiting for package resolution

Expected behavior

xcodebuild works without internal errors 😃

Actual behavior

❌  error: Build service could not create build operation: internal error: could not generate PIF because the workspace has not finished loading or is still waiting for package resolution

Steps to reproduce

  1. Clone repo
  2. Run Scripts/test-SPM-integration.sh

Swift Package Manager version/commit hash

Swift Package Manager - Swift 5.7.0

Swift & OS version (output of swift --version && uname -a)

swift-driver version: 1.62.8 Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50) Target: x86_64-apple-macosx12.0 Darwin testings-MacBook-Pro.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 x86_64

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 15
  • Comments: 19 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Bug still present with Xcode 14.3 and Swift 5.8

Hey @mikelrob

Thanks 😃 In our case we are generating test fixture for our library from scratch, so there is no .swiftpm to begin with…

I was able to work this problem around by running

swift package dump-pif > /dev/null
xcodebuild clean -scheme TempProject -destination 'generic/platform=iOS' > /dev/null

swift package dump-pif is undocumented, but it causes PIF generation. After running it next command usually fails with internal error, but by “silently” running xcodebuild clean I am sort of stabilising it… #ifitworksitisnotstupid

UPD

CI is still flaky 😦

resolving the packages first seems to work:

$ xcodebuild -resolvePackageDependencies
$ xcodebuild -scheme ... -destination ... test

@amadeu01 there’s nothing special about my script, the only thing I changed was the path being passed as the -clonedSourcePackagesDirPath argument, which instead of being set as foo (i.e. path inside the checkout folder), was set to a path outside the checkout folder, e.g. /tmp/foo, $HOME/foo, …

Hope this makes sense 🙏🏼

We started to experience this issue once we migrated our build tools from Mint to SPM Plugins. Specifically, the problem is caused by SwiftGenPlugin which is using prebuild command internally. Same issue is already mentioned above by @amadeu01

First run of xcodebuild always fails with Could not generate PIF error, subsequent runs are ok. This cause us issues on cloud-based CI instances like GitHub Actions etc. So for now we are sticking with Mint until this issue is resolved.

Committing .swiftpm folders doesn’t resolve our issue.

@0xpablo, I .gitignore the .swiftpm folder entirely. Any schemes that are persisted get exported to dependencies down stream. In CI, I generate any custom schemes as needed for xcodebuild to run tests. In general, it seems that packages behave better when the schemes are auto-generated each time.

We have worked around the issues by making sure schemes inside .swiftpm/xcode/xcshareddata/xcschemes were committed. Sometimes they don’t show up, or they don’t reflect the latest status of the package, as sometimes you start adding things “on the go” to the package and it does not get updated.

What has worked for us when the package is ready is:

  • Open the package with Xcode
  • Open the scheme editor
  • Delete the scheme and re-create it
  • Sometimes, for some reason, this wasn’t enough and we needed to unshare and share the scheme (by unchecking and checking the Shared checkbox).

After doing this, we haven’t had more issues on CI. The .gitignore that swift package init generates is good to go by the way.