Xcode 10:运行“设置内部版本号”脚本失败,并显示“没有此类文件或目录”

时间:2018-10-30 00:25:46

标签: xcode10

当我在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

1 个答案:

答案 0 :(得分:0)

  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. $SRCROOT/BuildScripts/set-build-number.sh放入外壳文本框中。