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?
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'.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With