Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it normal for Xcode not to detect if a pre-action failed?

Tags:

xcode

xcode4

I am using Xcode 4 and I added an preaction to the run scheme, a bash script, but it seems that Xcode is ignoring the exit status of the script and always run, even if the exit code is not zero.

Is this normal? What alternatives do I have for adding a custom step, one that can fail?

Update: I also tried exit 1 for post-action for build but with the same results, always executing without any feedback.

How can I make a custom step that can mark the build as failed?

like image 991
sorin Avatar asked Mar 24 '11 13:03

sorin


3 Answers

Not only does it not seem to care about pre-/post-action script exit status, but it doesn't seem to place the output into the build/run logs either. There are I think two separate threads about this buried in Apple's Xcode 4 dev forums. No word on whether this is a bug or a feature.

like image 186
Joshua Nozzi Avatar answered Jan 17 '23 14:01

Joshua Nozzi


You can add something like kill $PPID in the run script phase to terminate the xcodebuild (with exit code 70).

like image 41
Farcaller Avatar answered Jan 17 '23 14:01

Farcaller


When using Xcode, kill $PPID is not a solution, as I was commenting to Farcaller.

My solution is to have the pre-action script generate a header file (e.g. SchemePreActions.h) and make it empty for normal situation, and include it into your code (e.g. into AppDelegate.m).

This way, if you want the pre-actions script to report an error, put there a #error line, like in this real-world example:

if [ $CONFIGURATION == Debug ]; then
    echo "#error AppStore builds must not be in debug configuration" >> SchemePreActions.h
fi

Xcode will report this error very nicely.

It is recommended to have the generated file ignored by git.


As a tip I will add that my pre-actions script always starts with these lines:
echo "//auto-generated. no need to commit"      > SchemePreActions.h
echo "#define SCHEME_${SCHEME_NAME}"            >> SchemePreActions.h
echo "#define SCHEME_NAME @\"${SCHEME_NAME}\""  >> SchemePreActions.h
if [[ ${SCHEME_NAME} =~ "_PROD" ]]; then
    echo "#define PRODUCTION"                   >> SchemePreActions.h
fi

This way, by including SchemePreActions.h, my code can test to see if running under a specific scheme.

like image 38
ishahak Avatar answered Jan 17 '23 16:01

ishahak