在Xcode中构建之前运行shell脚本 [英] Run a shell script before build in Xcode

查看:449
本文介绍了在Xcode中构建之前运行shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在构建/存档之前调整我的项目的构建和版本号。

我尝试了多种方法,但到目前为止无济于事。

I need to adjust my build and version number for my project before build/archiving.
I tried multiple things, but so far to no avail.

我添加了一个带脚本的目标来更新数字,并将其添加为我的主目标的第一个依赖项。但是因为我有多个依赖项,因为我在我的应用程序中有扩展并且所有依赖项都是由Xcode并行执行的(或者至少是随机顺序),这不起作用。

I added a target with the script to update the numbers and added that as first dependency to my main target. But because I have multiple dependencies as I have extensions in my app and all dependencies are executed by Xcode in parallel (or at least in random order) this does not work.

我为我的方案添加了一个预先行动,结果相同。在继续构建之前,Xcode没有等待我的预操作完成(我添加了一个睡眠100来测试)。

I added a pre-action to my scheme with the same result. Xcode is not waiting for my pre-action to complete before continuing with the build (I added a sleep 100 to test).

因为我正在改变构建号码,所以至关重要的是脚本可以在其他任何开始之前完成,但还有一个副作用:由于plist文件在构建相关目标时已被更改,因此构建甚至停止。

As I'm altering build numbers it is crucial that the script can complete before anything else is started, but there is also one more side-effect: The build even stops due to the fact that the plist files have been altered while building the related target.

让我更难的是,我想使用 agvtools 设置我的版本&编号。这显然会启动我无法控制以更改plists的后台进程。

What makes it more difficult is, that I would like to use agvtools to set my version & build number. This obviously starts background processes that are out of my control to alter the plists.

免责声明:我搜索了其他答案,没有帮助。

Disclaimer: I have searched for other answers, didn't help.

推荐答案

agvtools在Xcode构建中不起作用。它将始终停止构建。
什么工作正常是PlistBuddy,虽然设置不是那么好又整洁。

agvtools just does not work in an Xcode build. It will always stop the build. What works fine is PlistBuddy, although the setup is not as nice and neat.

我在我的主要方案中为构建添加了一个Pre-Action来调用我项目中的新目标:

I added a Pre-Action to the build in my main scheme to call a new target in my project:

xcodebuild -project "${SRCROOT}/MAIN_APP.xcodeproj" -scheme BuildNumberPreProcess

在目标 BuildNumberPreProcess 中,我有运行脚本

VERSION=$(head -n 1 version.txt)
BUILD=`git rev-list $(git rev-parse --abbrev-ref HEAD) | wc -l | awk '{ print $1 }'`

echo "${VERSION} (${BUILD})"

SCRIPT="${SRCROOT}/CLIENT/Supporting Files/set-version-in-plist.sh"

"${SCRIPT}" "${SRCROOT}/MAIN_APP/Supporting Files/Info.plist" ${VERSION} ${BUILD}
"${SCRIPT}" "${SRCROOT}/EXTENSION/Info.plist" ${VERSION} ${BUILD}
...

set-version-in-plist.h:

set-version-in-plist.h:

#!/bin/sh

#  set-version-in-plist.sh
#
# usage:
# set-version-in-plist LIST VERSION BUILD
# LIST:      Info.plist path & name
# VERSION:   version number xxx.xxx.xxx
# BUILD:     build number xxxxx
#

# Location of PlistBuddy
PLISTBUDDY="/usr/libexec/PlistBuddy"

echo "$1: $2 ($3)"

${PLISTBUDDY} -c "Set :CFBundleShortVersionString $2" "$1";
${PLISTBUDDY} -c "Set :CFBundleVersion $3" "$1";

这篇关于在Xcode中构建之前运行shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆