ObjectiveCesar
ObjectiveCesar

Reputation: 61

Swift Package Manager relying on outdated source

I have a SwiftPM issue which is driving me nuts.

Let’s say I have swift package project (no Xcode project involved). And let’s call it SDK from here. The SDK is laying in its own git repository. So I want to build a Showcase App for that SDK by adding the SDK as a dependency, managing swift packages via Xcode not via a Package.swift file. The showcase is deployed to our QA team and they should be able to always test the latest development version of the SDK with that showcase.

So naturally I would configure the package dependency in Xcode by defining the branch develop. Adding a package dependency via Xcode

So now, when I change something inside the SDK, push it onto the develop branch, and want to have that change available inside the showcase, I simply need to right click on the package inside the showcase and click Update Package and this works great.

Here comes the catch: This approach does not work on our Jenkins CI. I don’t know what I’m doing wrong here, but the xcodebuild command line tool won’t notice something changed on the develop branch of the SDK and would checkout the older revision.

What I tried so far:

The generated xcodebuild command by Fastlane looks like this: $ xcodebuild -resolvePackageDependencies -scheme ScannerShowcase -project ScannerShowcase.xcodeproj -configuration Release -clonedSourcePackagesDirPath SourcePackage

The Fastlane gym summary looks like this: The gym summary

I'd expect that if I delete all that cached packages and not having any Package.resolved file present xcodebuild would resolve the swift package to the latest revision available. Instead it seems there still is something cached somewhere and xcodebuild is using that cache.

Nothing worked so far. Does anybody have experienced this same issue and is able to provide any suggestions and/or help?

Upvotes: 0

Views: 1002

Answers (1)

ObjectiveCesar
ObjectiveCesar

Reputation: 61

As it turns out there seems to be now way to achieve the same results with xcodebuild command line tool as with Xcode's Update Package or Update to Latest Versions.

The command line tools rely on data stored inside derived data while updating packages. Thanks to Gregory Higley's answer here I was able to solve the issue by deleting the derived data for that specific build job by

  • Keeping Showcase.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved out of git index,
  • adding Package.resolved to .gitignoreto keep it that way,
  • and adding the following stage to the declarative pipeline inside the Jenkins file:
stage('Clean up') {
    steps {
        script { env.DERIVED_DATA_PATH=sh(returnStdout: true, script: "xcodebuild -showBuildSettings | grep -m 1 BUILD_DIR | grep -oE \"/.*\" | sed 's|/Build/Products||'") }
        echo "Derived data path is: ${env.DERIVED_DATA_PATH}"
        // The above will return a folder with a name like /Users/you/Library/Developer/Xcode/DerivedData/MyProject-ehdkocavaenextdcrsaszjdmyssx
        sh script: "rm -rf ${env.DERIVED_DATA_PATH}", label: "Removing derived project data ..."
    }
}

Any other step I mentioned when asking the question wasn't necessary to achieve my goal:

  • No need to remove ~/Library/Cache/org.swift.swiftpm nor ~/Library/org.swift.swiftpm
  • No need to delete any prior created workspace on the build node
  • No need to to explicitly specify the SPM cloned source packages path via Fastlane with. cloned_source_packages_path: "SourcePackages"

Again big shout out to Gregory Higley for their approach.

Upvotes: 0

Related Questions