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

筅森魡賤 提交于 2019-12-21 09:17:04

问题


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.


回答1:


$ myversion=1.0.3
$ perl -O777 -i.bak -pe 's|<key>CFBundleVersion</key>\\s*<string>[\d.]*</string>|<key>CFBundleVersion</key></key>'"$myversion"'<string>|' bundle

Moves the file bundle to bundle.bak, and replaces 1.0.6.9 with 1.0.3 in the new bundle file.




回答2:


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



回答3:


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


来源:https://stackoverflow.com/questions/5299734/bash-script-to-edit-cfbundleversion-field-of-project-info-plist-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!