Search code examples
swiftxcodeapolloswift-package-manager

Error when adding a code generation build script of Apollo in swift package manager


The error that xcode gives me is:

./../SourcePackages/checkouts/apollo-ios/scripts: No such file or directory

I've seen this line of code in the official script on the official website , I have xcode11,I'm using Apollo iOS 0.16.0 with Swift package manager


Solution

  • I had the same problem few weeks ago. In fact this is a mistake with the Apollo iOS Website Documentation. I realized that when building in Release Configuration the script doesn't locate the scripts in the right folder. However, when building in Debug Configuration the path works fine. I refer to this line ../../SourcePackages/checkouts/apollo-ios/scripts

    So in order to solve this problem we have to detect the build configuration type like following:

        # Go to the build root and go back up to where SPM keeps the Apollo iOS repo checked out.
    cd "${BUILD_ROOT}"
    
    if [ "${CONFIGURATION}" == "Release" ]; then
        cd "../../../../../SourcePackages/checkouts/apollo-ios/scripts"
    fi
    
    if [ "${CONFIGURATION}" == "Debug" ]; then
        cd "../../SourcePackages/checkouts/apollo-ios/scripts"
    fi
    
    APOLLO_SCRIPT_PATH="$(pwd)"
    
    if [ -z "${APOLLO_SCRIPT_PATH}" ]; then
        echo "error: Couldn't find the CLI script in your checked out SPM packages; make sure to add the framework to your project."
        exit 1
    fi
    
    cd "${SRCROOT}/${TARGET_NAME}"
    "${APOLLO_SCRIPT_PATH}"/run-bundled-codegen.sh codegen:generate --target=swift --includes=./**/*.graphql --localSchemaFile="schema.json" API.swift