1

Are certain variables that were available to run scripts in Xcode 3 no longer available to pre-build script actions in Xcode 4?

The script

PLIST_FILE="$SRCROOT/$INFOPLIST_FILE"
echo "${PLIST_FILE}"

produces just "/" as output: neither SRCROOT nor INFOPLIST_FILE appear to be defined. Do these have new names in Xcode 4; is this a bug?

orome
  • 45,163
  • 57
  • 202
  • 418

4 Answers4

13

Update: Xcode 4.1 finally addresses this issue. A new popup in the script editor lets you choose the target on which Xcode bases the environment variables it makes available to your script (you can still choose "none" ... an option of questionable usefulness).

Old Post About 4.0 Follows

That's because, for whatever reason, Xcode environment variables are unavailable in pre- and post-action scripts in the current version.

Nobody has any idea why (or how they're useful without envvars).

Quick test - Add this in a script:

printenv ~/Desktop/EnvVars.txt

... then open up the text file and witness the disappointment. :-)

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • 2
    (REALLY hoping people don't down-vote me this time as well because they don't like this fact. Please don't shoot the messenger. He really is a nice guy once you get to know him. :-)) – Joshua Nozzi Jun 06 '11 at 15:19
  • Wow, that's messed up! A bug? – orome Jun 06 '11 at 19:21
  • I don't think it's a bug, no. I think it's an undercooked slab of Xcode 4. Almost certainly Apple will flesh this out later - the pre- and post-action script feature is practically useless in its current state. You can imagine my surprise when researching the matter for my book. I was SURE I was missing something. :-D – Joshua Nozzi Jun 06 '11 at 19:55
  • Hint: Keep an eye on >4.0 release notes. :-) – Joshua Nozzi Jul 03 '11 at 16:11
  • @chown - Not sure why you changed the command to "env > ~/path...", citing no arguments allowed with "env". That's exactly why my original answer specified *printenv*, which works perfectly fine exactly the way it is. Please only correct what is incorrect. – Joshua Nozzi May 20 '12 at 15:55
1

Try this:
cd ${SRCROOT}
open .

it works for me.

Ramiro
  • 375
  • 5
  • 8
0

In Edit Schema -> Build -> Pre-actions, make sure one of the target is selected for "Provide build settings from" (not none) option.

cp SOME_PATH/build.gradle "${SRCROOT}/build.gradle"
Suryavel TR
  • 3,576
  • 1
  • 22
  • 25
0

"$SRCROOT/$INFOPLIST_FILE" work fine for me in Xcode 4.1 Build 4B110 on Mac OSX Lion.

Imran
  • 967
  • 1
  • 8
  • 12