學科:IOS/Xcode/build script

來自維基學院

把TODO,FIXME等註釋轉化為編譯結果中的警告[編輯 | 編輯原始碼]

#!/bin/sh
# 把TODO,FIXME等註釋轉化為編譯結果中的警告
# by Kellen Styler
# via: http://d3signerd.com/turn-fixme-todo-and-comments-into-compiler-warnings/
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"


編譯時自增構建數[編輯 | 編輯原始碼]

參考:

下面是使用Plistbuddy的增強版,增加了只在文件修改時自增

#!/bin/sh
# 自增構建數
# via: http://stackoverflow.com/q/9258344

plist=${PROJECT_DIR}/${INFOPLIST_FILE}
dir="$(dirname "$plist")"

# 僅當文件有修改時自增
if [ -n "$(find "$dir" \! -path "*xcuserdata*" \! -path "*.git" -newer "$plist")" ]; then
    buildnum=$(/usr/libexec/Plistbuddy -c "Print CFBundleVersion" "$plist")
    if [ -z "$buildnum" ]; then
        echo "No build number in $plist"
        exit 2
    fi
    buildnum=$(expr $buildnum + 1)
    # 或使用日期(形如:121204):
    # buildnum=$(date "+%y%m%d")
    /usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "$plist"
    echo "Incremented build number to $buildnum"
else
    echo "Not incrementing build number as source files have not changed"
fi

APP to IPA[編輯 | 編輯原始碼]

把現有App包轉換為IPA可以創建一個服務,這樣可以在finder中直接選擇一個app,然後使用服務直接完成轉換。

你需要創建一個Automator服務,設置該服務可以接受文件,下面的腳本就是用來處理接受文件的。

#!/bin/sh
# App转IPA包,Automator shell脚本
source=$*
dateID=$( date +%j )
target=${source%.*}-${dateID}.ipa
#echo $source
#echo $target
xcrun -sdk iphoneos PackageApplication -v "$source" -o "$target"

參考: Generating ipa from xcode command-line - Stack Overflow

正常在Xcode中生成IPA的話,Archive後選擇Ad Hoc或In House方式的Distribute即可。

將項目目錄中的所有文件按字母順序排序[編輯 | 編輯原始碼]

使用xUnique腳本:https://github.com/truebit/xUnique

假設腳本文件在 $(SRCROOT)/Scripts/xUnique.py

# 项目按字母排序
cd Scripts
python2 xUnique.py $PROJECT_FILE_PATH

在應用Icon上加入版本信息[編輯 | 編輯原始碼]

見: Overlaying Application Version on Top of Your Icon http://www.merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/


參考[編輯 | 編輯原始碼]