I have a script that I run using osascript from a Run Script Build Phase in Xcode 4. This script does some checks to try and catch any human-error in plists and suchlike.
However, I only really want to run this script when a developer chooses 'Archive' as opposed to running it every time they build.
Is there any way of testing for this situation? Either in Shell Script or Apple Script?
Go to the Build Phases section of your project. (Click on the project, then on the main target, then on the “Build Phases” tab along the top.) Click the + at the top left to create a new build phase; choose “New Run Script Phase.” Xcode creates the script at the end of the list, naming it “Run Script.”
On the Xcode menu, select Product -> Edit Scheme... In the Build section, add the new target, then uncheck all the boxes except the one in the Archive column. This ensures the script will only be run on Archive. (See this question for an explanation and a nice screenshot.)
you can run as many bash scrips as you like at any point in the build phase. select your target, then either: from the menu: Editor -> Add Build Phase -> Add run script build phase.
In Xcode 4+, you could run this script as a pre- or post-action script on the "Archive" action. However, pre- and post-action scripts are not considered part of the build itself; their output is not part of the build log, and a failing script will not cause the build to fail.
If you want to include this script as a first-class part of the build, such that its failure will cause the build to fail, then you'll want to do something else. Make a new "External Build System" target, and configure it to run your script. The path to your script can be a relative path, relative to the project root.
Finally, open your main project scheme, and in the "Build" tag add the new checker target, and set it to only be included in the "Archive" action. This should cause your checker script to be run as part of the build only when "Archive" is selected, and if the script returns a non-zero value the build will fail.
Here's a step-by-step visual guide to configure a bash script to run only when archiving a target:
File > New > Target > Other > External Build System
Name the product accordingly and set /bin/bash
as the Build tool
Provide the path to the script under Info > Arguments of the newly created target
Product > Scheme > Edit Scheme…, and edit the scheme of the target where you want this script to run before archiving. Under Build, add the External Build System target you added in step 1. Reorder if needed. Then uncheck everything except Archive.
If you don't do 3. the script will run all the time, but if you check that box, it will only run when archiving.
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