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?
You need to return a non-zero exit code from the script:
exit 1
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
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