Unable to access SRCROOT in Xcode 4 scheme pre-build action scripts
Are certain variables that were available to run scripts in Xco开发者_如何学Pythonde 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?
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. :-)
Try this:
cd ${SRCROOT}
open .
it works for me.
"$SRCROOT/$INFOPLIST_FILE" work fine for me in Xcode 4.1 Build 4B110 on Mac OSX Lion.
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"
精彩评论