Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script to edit CFBundleVersion field of PROJECT-Info.plist file

In order to put in place a continuous integration system, Hudson, I wrote a bash script to build Xcode project automatically. Moreover, in Debug configuration, It was asked to me, to insert the svn revision number of the project in the CFBundleRevision field of the PROJECT-Info.plist file as ${BUNDLE_VERSION}.r${SVN_REVISION}.

You'll find the source code of PROJECT-Info.plist file below :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
[...]
    <key>CFBundleVersion</key>
    <string>1.0</string>
[...]
</dict>
</plist>

I tried this bash script below :

sed 'N;s_^.*<key>CFBundleVersion</key>.*<string>[0-9][0-9]*\.[0-9][0-9]*</string>$_<key>CFBundleVersion</key>\
<string>'"$BUNDLE_VERSION"'\.r'"$SVN_REVISION"'</string>_' $PROJECT-Info.plist

This script should replace the "1.0" string with ${BUNDLE_VERSION}.r${SVN_REVISION} (just in standard output currently). However, the replacement works without the 'N' option which includes the next line in the sed process and for one line at a time. But there is many line with "<string>[...]</string>" string in the PROJECT-Info.plist file...

I think it's my way of processing the unknown characters between the two lines ('N' option and ".*" for any characters) is wrong.

Any idea ?

Thanks in advance and sorry for my bad level in English.

like image 425
Doc_1faux Avatar asked Mar 14 '11 14:03

Doc_1faux


2 Answers

Use PlistBuddy:

# cf. http://davedelong.com/blog/2009/04/15/incrementing-build-numbers-xcode
/usr/libexec/PlistBuddy -h
/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" test.plist
myversion=1.0.5
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion '${myversion}'" test.plist
like image 120
tognum Avatar answered Nov 07 '22 00:11

tognum


In this specific case you can also use Xcode's agvtool. You do not even need to provide the path to the PROJECT-Info.plist file. Inside your project dir run:

agvtool new-version -all "$BUILD_NUMBER" # sets CFBundleVersion
agvtool new-marketing-version "$BUNDLE_VERSION" # sets CFBundleShortVersionString
like image 43
tfischbach Avatar answered Nov 07 '22 02:11

tfischbach