With the newest releases of iOS and iTunesConnect, Apple is more and more restrictive about what´s happening in your CFBundleVersion of your Extensions.
I tried to fiddle around with Run Script Build Phases, such as this:
#!/bin/sh
INFOPLIST_EXT="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
echo "Extension writing to $INFOPLIST_EXT"
PLISTCMD="Set :CFBundleVersion $(git rev-list --all|wc -l)"
echo -n "$INFOPLIST_EXT" \
| xargs -0 /usr/libexec/PlistBuddy -c "$PLISTCMD"
However, this seems to work for some types of Extensions (WatchKit), but for some others it doesn´t (Today Widget). In my cases, I seem to access the $TARGET_BUILD_DIR before there´s content in it. Using $BUILT_PRODUCTS_DIR delivers the same error.
Extension writing to /Users/marc/Library/Developer/Xcode/DerivedData/MyApp-focpnqzzpnqsfyaqwwocwpujmhmh/Build/Intermediates/ArchiveIntermediates/MyApp/IntermediateBuildFilesPath/UninstalledProducts/TopNewsWidget.appex/Info.plist
Set: Entry, ":CFBundleVersion", Does Not Exist
File Doesn't Exist, Will Create: /Users/marc/Library/Developer/Xcode/DerivedData/MyApp-focpnqzzpnqsfyaqwwocwpujmhmh/Build/Intermediates/ArchiveIntermediates/MyApp/IntermediateBuildFilesPath/UninstalledProducts/TopNewsWidget.appex/Info.plist
Command /bin/sh failed with exit code 1
So now I´m asking: what is the best practice for setting the CFBundleVersion automatically across all my Extensions? If Apple forces this for all developers, there should be an official way to do this across all extensions!
I don´t want to use agvtool, as this requires a separate step in the build process, modifes the Info.plists (which then are marked as modified by the SCM) etc.
What is the lifecycle of a build, when are which directories filled with build products?
Cheers,
Marc