OSX / Bash - 检测构建失败

时间:2013-01-23 16:38:21

标签: bash xcodebuild

直接从bash使用Xcodebuild,如何检测失败?无论如何,退出代码始终为0。我意识到有一个“FAILED”或“SUCCEEDED”纹理输出,但是没有更优雅的方式吗?

另外,我有时会使用“make”(尤其是我的基于Qt的版本)。有没有办法从构建脚本中检测make失败?

3 个答案:

答案 0 :(得分:6)

即使构建失败,xcodebuild也始终返回0。要检测错误,您可以使用如下脚本:

build_errors_file=build_errors.log

# Pipe errors to file
xcodebuild 2>$build_errors_file

errors=`grep -wc "The following build commands failed" $build_errors_file`
if [ "$errors" != "0" ]
then
    echo "BUILD FAILED. Error Log:"
    cat $build_errors_file
    rm $build_errors_file
    exit 1
fi
rm $build_errors_file

# ... continue

我确认在使用存档选项运行xcodebuild时不会打印** BUILD FAILED **,所以看起来要查找的字符串是'以下构建命令失败'。

答案 1 :(得分:1)

可能取决于Xcode的版本或可能的失败方式。这是我检查$时得到的结果?一些包含文件后找不到:

davidb@DavidBs-Mobile-Macintosh:~/Source/icanvas/iCanvas-project (release/icanvas-1.9 %) $ xcodebuild
...
/Users/davidb/Source/icanvas/iCanvas-project/iCanvas-target/iPhone/ConversationViewController.m:21:9: fatal error: 'CanvasKit/CKActionSheetWithBlocks.h' file not found
#import "CanvasKit/CKActionSheetWithBlocks.h"
        ^
1 error generated.
...
** BUILD FAILED **
...
(5 failures)
davidb@DavidBs-Mobile-Macintosh:~/Source/icanvas/iCanvas-project (release/icanvas-1.9 %) $ echo $?
65

答案 2 :(得分:0)

退出代码并不总是0.

我假设你是从shell脚本运行xcodebuild。

您可以尝试在脚本文件之前添加#!/ bin / bash -e

https://stackoverflow.com/a/40808843/2705627