XCodeでビルド番号を自動更新
バージョン番号にビルド番号を付けるのが
はやっています。
開発者が手動でビルド番号を更新するのは
あまりにも馬鹿らしいです。
自動で更新してくれるとうれしい。
しかも、Bundle Versionに書き込んでくれると
最高です。
http://www.gravitini.com/iPhone/2008/12/incrementing-your-build-number-in-xcode.html
↑こちらに使えそうなスクリプトがあったのですが、
そのままでは動かなかったので、調整しました。
version=$(sed -n ' /^[[:blank:]]*<key>CFBundleShortVersionString<\/key>$/ { N s/^[[:blank:]]*<key>CFBundleShortVersionString<\/key>\n[[:blank:]]*<string>\(.*\)<\/string>/\1/ p }' info.plist) build=$(sed -n ' /^[[:blank:]]*<key>CFBundleVersion<\/key>$/ { N s/^[[:blank:]]*<key>CFBundleVersion<\/key>\n[[:blank:]]*<string>.*\.\(.*\)<\/string>/\1/ p }' info.plist) build=$(($build +1)) cp info.plist 'Backup of Info.plist' sed ' /^[[:blank:]]*<key>CFBundleVersion<\/key>$/ { N s/\(.*\)<string>.*\(<\/string>\)/\1'"<string>$version\.$build"'\2/ P D }' 'Backup of info.plist' > info.plist
なお、スクリプトの追加は、ターゲットを選択し、
追加 → 新規ビルドフェーズ → 新規スクリプトを実行
でできます。
「スクリプトを実行」をダブルクリックすれば、
スクリプトを編集する画面になります。
複数ターゲット対応
複数のターゲットがあり、
info.plistがターゲットごとに存在し、
バージョン番号は共通にしたい場合、
以下のようにするとよいでしょう。
version=$(sed -n ' /^[[:blank:]]*<key>CFBundleShortVersionString<\/key>$/ { N s/^[[:blank:]]*<key>CFBundleShortVersionString<\/key>\n[[:blank:]]*<string>\(.*\)<\/string>/\1/ p }' info.plist) build=$(sed -n ' /^[[:blank:]]*<key>CFBundleVersion<\/key>$/ { N s/^[[:blank:]]*<key>CFBundleVersion<\/key>\n[[:blank:]]*<string>.*\.\(.*\)<\/string>/\1/ p }' info.plist) build=$(($build +1)) cp info.plist 'Backup of Info.plist' sed ' /^[[:blank:]]*<key>CFBundleVersion<\/key>$/ { N s/\(.*\)<string>.*\(<\/string>\)/\1'"<string>$version\.$build"'\2/ P D }' 'Backup of info.plist' > info.plist cp App1-Info.plist 'Backup2 of Info.plist' sed ' /^[[:blank:]]*<key>CFBundleVersion<\/key>$/ { N s/\(.*\)<string>.*\(<\/string>\)/\1'"<string>$version\.$build"'\2/ P D }' 'Backup2 of info.plist' > 'Backup3 of info.plist' sed ' /^[[:blank:]]*<key>CFBundleShortVersionString<\/key>$/ { N s/\(.*\)<string>.*\(<\/string>\)/\1'"<string>$version"'\2/ P D }' 'Backup3 of info.plist' > App1-Info.plist
これだと、info.plistのBundle Versionを
変更するだけで、App1-Info.plistに、
書き込まれます。
また、App2というターゲットを新しく作ったら、
スクリプト中のApp1-Info.plistをApp2-Info.plistに
変更すればよいだけです。
タグ:
XCode iPhone Cocoa Build Number Version Number バージョン 自動更新