sorin
sorin

Reputation: 170548

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

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?

Upvotes: 23

Views: 4025

Answers (3)

ishahak
ishahak

Reputation: 6795

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.

Upvotes: 1

Farcaller
Farcaller

Reputation: 3070

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

Upvotes: 5

Joshua Nozzi
Joshua Nozzi

Reputation: 61228

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.

Upvotes: 29

Related Questions