Search code examples
swiftxcodeswift-package-manager

Xcode environment variable to project directory with SPM


I have an Xcode project and would like to add a Build Phase Run Script to run a script that's inside a package i'm using. With CocoaPods i could do something like this - bash "$SOURCE_ROOT/Pods/myFramework/script.sh. I changed the dependency to use Swift Package Manager, so now i need to change the path to be something like this - /Users/username/Library/Developer/Xcode/DerivedData/project-name/SourcePackages/checkouts/myFramework/script.sh. what would be the equivalent of SOURCE_ROOT to get to the project inside DerivedData? I don't want to set a local environment variable as this should be a out of the box ready for other developers on every mac


Solution

  • You can set your path like this

    ${BUILD_DIR%Build/*}SourcePackages/checkouts/myFramework/script.sh
    

    here is the source of the answere.