Daij-Djan
Daij-Djan

Reputation: 50089

Xcode doesn't seem to execute my scheme's post-action

I'm using Xcode (4.6.2) and my target is an external build tool. The auto generated scheme calls that just fine during build.

On RUNNING, I wanted the scheme to execute another shell script. It wasn't intuitive, but I managed it by setting /bin/bash as executable and passing my script as parameter.

The only step left is that I want to execute yet another script AFTER run. And here I thought it'd be easy and just tried to set it as a post-action.

BUT no matter what, I can't get xcode to execute my post-action script. No matter what it is. I tried echo hi > /tmp/testfile even...

I need that post-action to do a bit of cleanup.


Again in short:

  1. I have a script build_me that is my external build tool
  2. I have a script run_me that I set my scheme to run
  3. I have a script cleanup that I want to have as run post-action

Can't get Xcode to run my post-action script or any.

Upvotes: 21

Views: 13292

Answers (6)

Jonny
Jonny

Reputation: 2084

For me, the "not working" effect was caused by a directory path lookup failure in my script.

If you run your script at your target's Build Phases, A relative directory path like this will work:

INFO="MyApp/Info.plist"

However in Pre-Actions it fails silently. Instead, you must use an absolute directory path like this:

INFO="${PROJECT_DIR}/MyApp/Info.plist"

Upvotes: 1

Dannie
Dannie

Reputation: 2480

This works on Xcode 5.0, tested, I figure it should work the same in 4.6.2.

Post-actions only works when you quit the program from within the program

It will not run when you click on Stop in Xcode, or terminate the program otherwise. For my case, it works when I press CMD-Q while the program is in focus.

Using a bash script file for Post-actions

These settings work: enter image description here

Upvotes: 12

Ondrej Rafaj
Ondrej Rafaj

Reputation: 4417

I suggest you enable logging to a file by adding exec > /tmp/xcode_build.log 2>&1 to the beginning of your run script phase.

You can than see the log by running cat /tmp/xcode_build.log in terminal

This will allow you to print out paths, etc and verify functionality of your scripts.

To print location of the script, you can put following in your post-action:

exec > /tmp/my_log_file.txt 2>&1
pwd

Upvotes: 21

Moose
Moose

Reputation: 2737

It's a bit odd, but Archive executes pre and post scripts when called from command line.

So I've made an archive.sh script in my project folder, I pass the name of project ( same as main target - but you can configure that as you like ) as a parameter:

xcodebuild clean -project $1.xcodeproj -configuration Release -target $1
xcodebuild archive -project $1.xcodeproj -scheme $1

Then I create an "External Build" target name "Archive", with ./archive.sh as script.

When I build this target, Project is cleaned, build and archived. and post script defined in the scheme is executed

Just a remark, since I'm building from a shell script, I've removed my post script in the archive scheme, and instead call it after my build commands in my archive.sh script.

This way gives me a better control on working directories, variables and all… It's much more convenient

Upvotes: 2

Maria
Maria

Reputation: 4601

If anyone else comes across this, I was using a script file in my project directory and the file did not have the right permissions for the build process to run the script. I did the following in the pre/post action/Run Script area

chmod 755 ${PROJECT_DIR}/BuildScripts/IncrementBuildNumber.sh
${PROJECT_DIR}/BuildScripts/IncrementBuildNumber.sh

Upvotes: 5

enedil
enedil

Reputation: 1645

Depending on programming language you use you can do (it's pseudocode):

system( <command> 2>&1 | tee run.log && exit $PIPESTATUS )

Upvotes: 0

Related Questions