当我在Build Phases的Run Script部分的Shell文本字段中输入设置的内部版本号脚本时,它可以完美运行。当我将脚本放入文件中并尝试运行它时,出现“没有这样的目录或文件”错误。
脚本:
#!/bin/bash
git=`sh /etc/profile; which git`
appBuild=`"$git" rev-list HEAD --count`
if [ $CONFIGURATION = "Debug" ]; then
branchName=`"$git" rev-parse --abbrev-ref HEAD`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild-$branchName" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild-$branchName" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}.dSYM/Contents/Info.plist"
else
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}.dSYM/Contents/Info.plist"
fi
echo "Incremented the build number ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
done
我将该脚本放在./scripts/set-build-number.sh中(在文件夹和文件上执行chmod 755
),并将$(SRCROOT)/scripts/set-build-number
放入外壳文本字段。那是我得到构建错误的时候。如果我将该路径放在Shell文本字段下方的“输入文件”部分中,则不会发生任何事情。怎么了?
构建消息
正常
Set: Entry, ":CFBundleVersion", Does Not Exist
File Doesn't Exist, Will Create: /Users/XXXX/Library/Developer/Xcode/DerivedData/YYYY-czbuuppxwtizikbcswqcwzqtvnri/Build/Products/Debug-iphonesimulator/YYYY.app.dSYM/Contents/Info.plist
Incremented the build number /Users/XXXX/Library/Developer/Xcode/DerivedData/YYYY-czbuuppxwtizikbcswqcwzqtvnri/Build/Products/Debug-iphonesimulator/YYYY.app/Info.plist
在脚本文本字段中使用$(SRCROOT)/scripts/set-build-number
。
/Users/XXXX/Library/Developer/Xcode/DerivedData/YYYY-czbuuppxwtizikbcswqcwzqtvnri/Build/Intermediates.noindex/YYYY.build/Debug-iphonesimulator/YYYY.build/Script-652071B32183E6C100A92117.sh: line 25: SRCROOT: command not found
/Users/XXXX/Library/Developer/Xcode/DerivedData/YYYY-czbuuppxwtizikbcswqcwzqtvnri/Build/Intermediates.noindex/YYYY.build/Debug-iphonesimulator/YYYY.build/Script-652071B32183E6C100A92117.sh: line 25: /scripts/set-build-number: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
在输入文件中带有$(SRCROOT)/scripts/set-build-number
。
Run custom shell script 'Run Script' 0.1 second
答案 0 :(得分:0)
#!/bin/bash # Set the build number to the current git commit count. # If we're using the Dev scheme then we'll suffix the build number with the # current branch name to make collisions far less likely across feature branches. git=$(sh /etc/profile; which git) appBuild=$("$git" rev-list HEAD --count) branchName=$("$git" rev-parse --abbrev-ref HEAD) dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist" target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH" for plist in "$target_plist" "$dsym_plist"; do if [ -f "$plist" ]; then if [ $CONFIGURATION = "Debug" ]; then /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild-$branchName" "$plist" echo "Build number set to $appBuild-$branchName in ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" else /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild" "$plist" echo "Build number set to $appBuild in ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" fi fi done
$SRCROOT/BuildScripts/set-build-number.sh
放入外壳文本框中。