Reputation: 971
I am trying to do the following:
Can I write a shell script for this?
It will be great if someone can guide me to achieve this.
Upvotes: 25
Views: 23767
Reputation: 6660
Probably the simplest way is to use PlistBuddy. I have a Run Script phase that looks like this:
BUILD_NUMBER=`git rev-list HEAD --count`
INFO_PLIST="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
if [ -f "$INFO_PLIST" ] ; then
oldversion=`/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$INFO_PLIST"`
fi
if [ "$BUILD_NUMBER" != "$oldversion" ] ; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "$INFO_PLIST"
fi
(Note that starting with Xcode 6, you have to run this after the Copy Bundle Resources phase, because Info.plist
isn't copied to the target location until then and PlistBuddy would fail.)
Edit 01/17: Updated to avoid unnecessary copying or signing of targets. You don’t want to touch Info.plist unless something really changes, otherwise Xcode will treat it (and thus the target) as modified. Checking previous value CFBundleVersion
can significantly speed up builds — it saved me several seconds on noop build.
Upvotes: 25
Reputation: 36752
Yes you can. I would do it in three steps:
${MY_COOL_SETTING}
.Upvotes: 13
Reputation: 1355
I have a script file that puts a build number into a field in my info.plist. I put some place holder text in the info.plist in project and then the script just replaces it. It only increments the build number on release builds. On development builds it just says they are a development build.
if [ "$BUILD_STYLE" = "Release" ]
then
if [ ! -f build-number ]; then
echo 0 > build-number
else
expr `cat build-number` + 1 > build-number.new
mv build-number.new build-number
fi
perl -pi -e s/BUILD_NUMBER_PLACEHOLDER/`cat build-number`/ $BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Contents/Info.plist
else
perl -pi -e s/BUILD_NUMBER_PLACEHOLDER/`echo Development`/ $BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Contents/Info.plist
fi
Upvotes: 4
Reputation: 299345
@PeyloW offers one way to do it. The other way to do it is to add a Run Script build step. In that step you can rewrite your Info.plist anyway you like. I do this all the time to set the svnversion.
I recommend putting your script in a file, and then putting . myscript.sh
in the Run Script phase. This is easier to understand and maintain than putting the entire script directly in Xcode.
Upvotes: 8