Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop Xcode build from shell script

Tags:

bash

shell

xcode

I am currently working on an app in Xcode where I've added a Build Phase that runs a shell script.

The script looks for resources from the Desktop and copies them to the app . If the files/folders don't exist, the script should cancel the build of the app.

I have tried various things to stop the build such as xcodebuild clean but I can't quite figure it out. Here is what I have:

if [ -d ~/Desktop/MyFolder ]; then
    cp -r ~/Desktop/MyFolder ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/MyFolder
else
    #Stop the build
fi

Is there a way to have the script tell Xcode to stop the build? If so, how can I do it?

like image 565
Dominic Mortlock Avatar asked Oct 22 '12 12:10

Dominic Mortlock


2 Answers

You need to return a non-zero exit code from the script:

exit 1
like image 99
Mike Weller Avatar answered Oct 21 '22 12:10

Mike Weller


Another useful technique is for the script to produce an output with an "error: " prefix. This will cause Xcode to show the error within the build logs, and if you Xcode settings stop building on failure - it will stop right there.

In addition to this, you could also trigger a warning by printing out "warning: " prefix.

Example:

if [ -d ~/Desktop/MyFolder ]; then
    cp -r ~/Desktop/MyFolder ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/MyFolder
else
    echo "error: Copy failed!"
fi
like image 22
jmkk Avatar answered Oct 21 '22 11:10

jmkk