Xcode4: empty environment variables in custom build pre-action / post-action
I need to run a custom build script in xcode 4. The script is added as pre-action and executed properly. My problem is, that there are no environment variables available that could help me to access my project files.
I.e. I开发者_JAVA百科'm interested in ${PROJECT_DIR}
, ${BUILT_PRODUCTS_DIR}
and ${INFOPLIST_PATH}
. Unfortunately the variables are not set. The whole environment looks like that:
Apple_PubSub_Socket_Render=/tmp/launch-pc2V6P/Render
BASH=/bin/sh
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=([0]="0")
BASH_SOURCE=([0]="/Users/melle/Projects/rc-control/RC/Scripts/preBuild.sh")
BASH_VERSINFO=([0]="3" [1]="2" [2]="48" [3]="1" [4]="release" [5]="x86_64-apple-darwin10.0")
BASH_VERSION='3.2.48(1)-release'
COMMAND_MODE=unix2003
DIRSTACK=()
DISPLAY=/tmp/launch-VH6onm/org.x:0
EUID=502
GROUPS=()
HOME=/Users/melle
HOSTNAME=zack.fritz.box
HOSTTYPE=x86_64
IFS=' '
LOGNAME=melle
MACHTYPE=x86_64-apple-darwin10.0
OPTERR=1
OPTIND=1
OSTYPE=darwin10.0
PATH=/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
PIPESTATUS=([0]="0")
POSIXLY_CORRECT=y
PPID=43073
PS4='+ '
PWD=/private/var/folders/h2/h2tdJ2dPF943jRjJXqjNX++++TM/-Tmp-
SCHEME_ACTION_NAME='Run Script'
SHELL=/bin/bash
SHELLOPTS=braceexpand:hashall:interactive-comments:posix
SHLVL=3
SSH_AUTH_SOCK=/tmp/launch-LXX6Lp/Listeners
TERM=dumb
TMPDIR=/var/folders/h2/h2tdJ2dPF943jRjJXqjNX++++TM/-Tmp-/
UID=502
USER=melle
_=PWD
__CF_USER_TEXT_ENCODING=0x1F6:0:0
Is this a bug in xcode4 or is it me, doing it totally wrong?
My current workaround is to abuse ${BASH_SOURCE}
to find the way back to my project directory...
Update: It looks like this is a bug in xcode 4.0.1. If you enter the script directly into the Xcode window, at least the variable ${WORKSPACE_PATH}
is available.
I found that adding the script to the target's build phase rather than as a pre-action was a better solution in my case:
- Select the Project in the project navigator.
- Select your target.
- Go to the Build Phases tab.
- Add a new build phase (script).
- Drag it above the compile sources phase.
- Add whatever script you need there. You can access environment variables such as
${PROJECT_DIR}
.
You can even have it output all the environment variables in the Log Navigator for you.
Additionally, the working directory for any scripts you call will be set to the project's directory automatically.
精彩评论