9

I'm still getting used to Xcode 4, so forgive me if this is an asinine question:

In previous versions of Xcode, one could use any of the build setting variables (such as SRCROOT or PRODUCT_NAME, etc in any shell scripts associated with a build. This was easily accomplished by adding a 'Run Script' build phase to any target.

In Xcode 4, however, the addition of schemes (really great, by the way) seems to disallow the usage of any of these variables. Is it possible this is by design? Is there a workaround?

2 Answers 2

12

In the "Run Script" scheme action in Xcode 4.2 there is a "Provide build settings from..." drop down menu where you can select a target from which you would like to have the environment variables from. See screenshot below:

"Provide build settings from" drop down menu

Apart from that, if you select "None", there will be a bunch of environment variables set by Xcode. You can discover all of them by doing something like printenv > ~/Desktop/printenv.txt to have them dumped to a text file.

Some of the more useful environment variables include ARCHIVE_PATH, SCHEME_NAME, USER, ARCHIVE_DSYMS_PATH, ARCHIVE_PRODUCTS_PATH.

Sign up to request clarification or add additional context in comments.

1 Comment

This is a really handy tip, apart from being a bit unclear as to how to get to these settings. Start in the scheme editor and open up the appropriate action in the left-hand column (e.g. Build). Click on e.g. Pre-actions, then the add (+) button at the bottom of the main pane, and choose "New Run Script Action". Then you get what you see above and can add the script. Thanks, @Martijn!
0

You can still add a Run Script to a target in Xcode 4 in much the same way you could with Xcode 3. First select the project in the left hand project navigator pane and then with the target selected look in the Build Phases tab for the Run Script section. The scripts can use the usual set of variables as with Xcode 3.

Reading some of the posts on this topic in the Apple developer forums it seems that Apple has at least acknowledged the limitations of the pre and post actions so we might see it fixed in a future update (open a bug report with Apple if you have not already done so).

3 Comments

Sure, I'm aware of this. I'm just very surprised that the schemes scripts (pre and post) don't allow usage of these variables. It's quite useless without them.
below the "Arguments" tab it states that "build settings like $(BUILT_PRODUCTS_DIR) will be expanded". Sure enough, it is. However, other settings that worked previously, e.g. $(PROJECT_DIR) seem to be ignored.
Definitely worth creating a bug report with Apple (bugreporter.apple.com). The more reports they get on this the better.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.