Script to get errors and logs out of xCode prebuild action

In response to an issue that came up on stack overflow – http://stackoverflow.com/a/18477820/285694

log_prebuild.sh

Run your script in your prebuild action using this script.

[shell]
#!/bin/sh

# log_prebuild.sh
#
# Created by Kevin Lohman on 8/27/13.
#

#### Default Setup
scriptName=${BASH_SOURCE[0]##*/}
echoerr() { echo “Error – $scriptName – $@” 1>&2; exit 1; }
if [ -z $SOURCE_ROOT ]; then
outputFolder=”$( cd “$( dirname “${SOURCE_ROOT}” )”/build && pwd )”
else
outputFolder=”${SOURCE_ROOT}/build”
fi
stopOnError=””
unset scriptPath

##### Parse Parameters
while true ; do
case “$1” in
-v) echo “### Verbose mode enabled -v”; set -x; shift;;
–output) outputFolder=`python -c ‘import os,sys;print os.path.realpath(sys.argv[1])’ $2`; shift 2;;
“”) break;;
*) if [ -z scriptPath ]; then
echo “Unknown flag: $1”; echoerr “usage: $scriptName [-v] [–output destinationFolder] scriptPath”
else
scriptPath=`python -c ‘import os,sys;print os.path.realpath(sys.argv[1])’ $1`
fi; shift;;
esac
done

if [ -z scriptPath ]; then
echoerr “Script path parameter needs to be set” > “$outputFolder/prebuild_error.log”
fi

if [ -f “$outputFolder”/prebuild_error.log ]; then
rm “$outputFolder”/prebuild_error.log
fi

echo “### Prebuild Logging Script Launching – $scriptPath” > “$outputFolder”/prebuild.log

$scriptPath >> “$outputFolder”/prebuild.log 2> “$outputFolder”/prebuild_error.log
[/shell]

enforcePrebuildFailures.sh

This script should be placed in a Run Script build phase for your target (ideally before compile)

[shell]
#!/bin/sh

# enforcePrebuildFailures.sh
#
#
# Created by Kevin Lohman on 8/27/13.
#

prebuildLog=”$SOURCE_ROOT”/build/prebuild.log
errorLog=”$SOURCE_ROOT”/build/prebuild_error.log

if [ -s $prebuildLog ]; then echo “#### PRE-BUILD Output”; cat $prebuildLog; rm $prebuildLog; fi
if [ -s $errorLog ]; then echo “#### PRE-BUILD Error” 1>&2; cat $errorLog; rm $errorLog exit 1; fi
[/shell]

Leave a Reply

Your email address will not be published. Required fields are marked *