Description
I'm unable to use Xcode Cloud build due to IDEPackageOnlyUseVersionsFromResolvedFile
being enabled by default, which seems to cause Swift Package Manager not to resolve local packages.
There are two problems at play.
Problem #1
If there are no remote packages in the Xcode project (only local ones), then no Packages.resolved
gets generated, resulting in the following output:
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -resolvePackageDependencies -project LocalPackagesFailOnCloudBuild.xcodeproj -scheme LocalPackagesFailOnCloudBuild -disableAutomaticPackageResolution -onlyUsePackageVersionsFromResolvedFile
User defaults from command line:
IDEPackageOnlyUseVersionsFromResolvedFile = YES
IDEPackageSupportUseBuiltinSCM = YES
Resolve Package Graph
a resolved file is required when automatic dependency resolution is disabled and should be placed at /Users/featherless/workbench/localpackages/LocalPackagesFailOnCloudBuild.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved. Running resolver because the following dependencies were added: 'mypackage' (/Users/featherless/workbench/localpackages/MyPackage)fatalError
2023-09-17 15:02:07.817 xcodebuild[53959:2851120] Writing error result bundle to /var/folders/8g/h8fxkf_90mj2zxdf78r0tmbh0000gn/T/ResultBundle_2023-17-09_15-02-0007.xcresult
xcodebuild: error: Could not resolve package dependencies:
a resolved file is required when automatic dependency resolution is disabled and should be placed at /Users/featherless/workbench/localpackages/LocalPackagesFailOnCloudBuild.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved. Running resolver because the following dependencies were added: 'mypackage' (/Users/featherless/workbench/localpackages/MyPackage)
fatalError
Problem #2
If the Xcode project has remote packages and was able to generate a Package.swift, then the following line ends up still being hit:
https://github.com/apple/swift-package-manager/blob/de8e6e8e416f0ddf66ded9bf9c9abafe9517f3c3/Sources/Workspace/Workspace.swift#L2727
with an error message like this:
an out-of-date resolved file was detected at /Volumes/workspace/repository/MyProject.xcworkspace/xcshareddata/swiftpm/Package.resolved, which is not allowed when automatic dependency resolution is disabled; please make sure to update the file to reflect the changes in dependencies. Running resolver because the following dependencies were added: 'mylibrary' (/Volumes/workspace/repository/packages/MyLibrary)fatalError
Full repro repository: https://github.com/jverkoey/LocalSwiftPackagesFailure
There doesn't appear to be a way to remove the use of IDEPackageOnlyUseVersionsFromResolvedFile from Xcode Cloud. The problem here seems to be to do with the fact that local packages aren't added to Packages.resolved
?