Apollo-ios: Building project in XCode10 returns error `Build input file cannot be found: .../API.swift

Created on 20 Sep 2018  路  7Comments  路  Source: apollographql/apollo-ios

  • [x] has-reproduction

Problem reproduction

When trying to compile the project having the schema downloaded, but without having the API.swift generated, the compiler returns the error:
Build input file cannot be found: '/Users/victormihaita/GitHub/ios/Sources/API.swift

After this error, theAPI.swift is generated, so if we build the project again, everything is fine. The problem in my case, is that the build has to compile the first time in order to pass the CI.

Build Phase:

APOLLO_FRAMEWORK_PATH="$(eval find $FRAMEWORK_SEARCH_PATHS -name "Apollo.framework" -maxdepth 1)"

if [ -z "$APOLLO_FRAMEWORK_PATH" ]; then echo "error: Couldn't find Apollo.framework in FRAMEWORK_SEARCH_PATHS; make sure to add the framework to your project." exit 1 fi

cd "${SRCROOT}" $APOLLO_FRAMEWORK_PATH/check-and-run-apollo-cli.sh codegen:generate Sources/API.swift --queries="$(find . -name '*.graphql')" --passthroughCustomScalars --schema=Sources/schema.json

Fastlane for downloading schema

lane :download_schema do
sh("npm install -g apollo")
Dir.chdir("..") do
sh("apollo schema:download ./Sources/schema.json --endpoint our_private_url")
end
end

build-issue has-reproduction

Most helpful comment

I believe it's not something connected with apollo, it's the xcode 10 new building tool, WWDC'18 Session #408

If an output file which is generated by a shell script is used as an input elsewhere in the build, then that output must be declared as an explicit output by the script that generates it; otherwise the build system may attempt to search for the file before it has been generated, causing the build to fail.

To solve the problem, under Generate Apollo GraphQL script you have an output files click on the + and add API.swift file in there 馃帀. This solution will work local without any issue and in the CI.

screen shot 2018-10-01 at 18 05 13

The reason of having the output files is that Xcode can better determine the dependency graph between targets.

All 7 comments

Workaround for this issue

The compiler needs to have the reference to the API.swift file. A solution for this is to remove all the code that is inside the file. In this way, the CI will recognise the reference to the file and will compile the code.

My workaround was to add a script step in CI to touch API.swift so the compiler will see something. More of a problem with how CI and source control are set up than anything this project can fix?

we ended up with the same solution as you did @ashiemke. But is still an issue because this behavior can be observed also when you build locally. If the API.swift doesn鈥檛 exist, the build crashes also locally first time.

+1 on this

Would be lovely to know if this workaround is something we have to live with for quite some time or if there is a plan to fix this? This may influence the solution / workaround we implement and how much time we dedicate to it.

I believe it's not something connected with apollo, it's the xcode 10 new building tool, WWDC'18 Session #408

If an output file which is generated by a shell script is used as an input elsewhere in the build, then that output must be declared as an explicit output by the script that generates it; otherwise the build system may attempt to search for the file before it has been generated, causing the build to fail.

To solve the problem, under Generate Apollo GraphQL script you have an output files click on the + and add API.swift file in there 馃帀. This solution will work local without any issue and in the CI.

screen shot 2018-10-01 at 18 05 13

The reason of having the output files is that Xcode can better determine the dependency graph between targets.

It would be nice if Apollo generated a .xcfilelist file, which could be used to declare all the .swift files it generates. (This is in cases where you鈥檙e generating a folder of files, rather than just a single API.swift file.)

Hey all - the build scripts have been updated in the docs - I'm going to close this one out but @ZevEisenberg thank you for the suggestion, I'm going to open that as a separate enhancement.

Was this page helpful?
0 / 5 - 0 ratings