Search code examples
xcode10

Xcode 10 Build Phase Shell Script


In our project we derive our release version from git tag etc then write it to the built folder's Info.plist with a shell script like:

GIT_RELEASE_VERSION=$(some git command) defaults write "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH%.*}" "CFBundleShortVersionString" "${GIT_RELEASE_VERSION#*v}"

This has worked well for all past Xcode versions, but in Xcode 10's New Build System this failed to actually update the CFBundleShortVersionString in the info.list file. The value is correctly updated with Xcode 10's Legacy Build System though.

I added some echos to the script and compared the build log on New and Legacy systems and cannot see any difference:

echo "git release version:" ${GIT_RELEASE_VERSION} echo "info path:" ${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH%.*} echo "grv:" "${GIT_RELEASE_VERSION#*v}"

Not sure if anyone out there encountered similar issues with the New Build System?


Solution

  • It seems like the problem is that sometimes your Run Script Phase will execute before Xcode creates the Info.plist. If you’d like to ensure that your script phase runs after a specific step, you need use the inputs to mark your dependencies.

    For instance, adding:

    $(TARGET_BUILD_DIR)/$(INFOPLIST_PATH)

    As an input to your script phase should enforce the ordering you are looking for: Xcode will create the Info.plist and sometime after, your script will execute and modify the Info.plist.

    Edit for Xcode 14 - J Nozzi

    Per comment below, the above did not completely work for me, as it kept claiming it would run with every build. Adding $(DERIVED_FILE_DIR)/$(INFOPLIST_PATH) to the Output Files list worked.