Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSX/Bash - detecting build failure

Using Xcodebuild directly from bash, how would one detect a failure? the exit code is always 0 regardless. I realize there's an "FAILED" or "SUCCEEDED" textural output, but isn't there a more elegant way?

Also, I sometimes use "make" (especially with my Qt based builds). Is there a way to detect make has failed from the build script?

like image 466
JasonGenX Avatar asked Jan 23 '13 16:01

JasonGenX


2 Answers

xcodebuild always returns 0 even when the build fails. To detect errors, you could use a script like this:

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

I verified that ** BUILD FAILED ** will not be printed when running xcodebuild with the archive option, so it seems that the string to look for is 'The following build commands failed'.

like image 95
bizz84 Avatar answered Nov 03 '22 07:11

bizz84


Maybe it depends on the version of Xcode or possibly how it fails. This is what I get when I check $? after some include files can't be found:

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
like image 29
devguydavid Avatar answered Nov 03 '22 07:11

devguydavid