xcode 如果运行脚本阶段出现错误,如何中止构建
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3869984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to abort build if run script phase gives an error
提问by GorillaPatch
I would like to use a run scripts target to tag my revision in mercurial and upload it to a server. I created a new run scripts target that depends on the other target building my app, then I added two run script phases directly one after another.
我想使用运行脚本目标在 mercurial 中标记我的修订并将其上传到服务器。我创建了一个新的运行脚本目标,它依赖于构建我的应用程序的另一个目标,然后我一个接一个地直接添加了两个运行脚本阶段。
Now my question: how can I prevent executing run script phase #2 if run script phase #1 gives an error (return code of script is unequal 0)?
现在我的问题是:如果运行脚本阶段 #1 出现错误(脚本的返回代码不等于 0),我该如何阻止执行运行脚本阶段 #2?
The second script would upload the files to a server, so I only want to execute this phase if everything went right until then.
第二个脚本将文件上传到服务器,所以我只想在一切顺利的情况下执行这个阶段。
采纳答案by w-m
A solution would be to generally stop building when errors occur:
解决方案通常是在发生错误时停止构建:
XCode -> Preferences -> Building -> Build options "Continue building after errors".
XCode -> 首选项 -> 构建 -> 构建选项“错误后继续构建”。
If you uncheck that, the build will stop if your script returns something unequal 0 and the second script will not be executed. If you use xcodebuild, the name for the setting is "PBXBuildsContinueAfterErrors".
如果取消选中,如果您的脚本返回不等于 0 的值,则构建将停止,并且不会执行第二个脚本。如果您使用 xcodebuild,则该设置的名称为“PBXBuildsContinueAfterErrors”。
回答by Farhad Malekpour
Your first script can abort the build with "exit 1", like this:
您的第一个脚本可以使用“exit 1”中止构建,如下所示:
if [ error ] then
echo "There are some errors, etc..."
exit 1
fi