SwiftPM package build via xcodebuild with specified derived data path

The answer was found over on the Apple Developer forums in a thread titled Xcodebuild error Swift Package with -derivedDataPath. That thread links back to this forum and got me to this post: Xcode and Swift Package manager - #6 by simonpierreroy.

It seems that -derivedDataPath cannot be in the current working directory or if it is then the SwiftPM cache should not be. I am using -clonedSourcePackagesDirPath to move the SwiftPM cache outside the current working directory.

Solution

xcodebuild \
    -disableAutomaticPackageResolution \
    -usePackageSupportBuiltinSCM \
    -derivedDataPath "$PWD/derivedData" \
    -clonedSourcePackagesDirPath "$HOME/Library/Developer/Xcode/DerivedData/$XCODE_SCHEME"
    -enableCodeCoverage YES \
    -scheme "$XCODE_SCHEME" \
    -destination "$DESTINATION" \
    build-for-testing
1 Like