Xcode 10:运行 设置内部版本号脚本失败 "No such file or directory"

Xcode 10: Running Set Build Number script fails with "No such file or directory"

当我在构建阶段的 运行 脚本部分的 Shell 文本字段中输入我的设置构建号脚本时,它运行良好。当我将脚本放入文件并尝试 运行 它时,我收到 "no such directory or file" 错误。

脚本:

#!/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 文本字段。那是我收到构建错误的时候。如果我将该路径放在 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
  1. $(SRCROOT) 不能很好地处理空格。我删除了项目文件夹名称中的所有空格。
  2. 我重写了脚本。

    #!/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

  1. 在shell文本框中输入$SRCROOT/BuildScripts/set-build-number.sh