Running Bash Script on XCode Compile — Where To Ge

2019-07-14 07:42发布

问题:

When using XCode to compile a Cocoa application, I'm running a custom Bash script in the build phase. Unfortunately, I'm having to spell out full paths. Instead, I'm almost certain there are variables I can use in the Bash and one of those might cover it. Here's what I'm running:

/Users/mike/Projects/objectivec/proj1/proj1/shellscript.sh  /Users/mike/Projects/objectivec/proj1/proj1/proj1/lang/en/html/

See how having a $VAR would help here, rather than specifying physical paths? It would also help members on my team be able to compile this project without modification.

I tried looking in the XCode7 docs, but couldn't find any listing anywhere of what these variables might be that I can use.

Note that the path /Users/mike/Projects/objectivec/proj1/proj1/ folder contains my AppDelegate.mm file in this case, if that helps you.

Can you tell me where I can find the documentation on this list of available variables so that I don't have to specify full physical paths?

回答1:

The fix was that I made it run this Bash script as a test:

#!/bin/bash

set > /tmp/vars.txt

Then, I compiled a build. After that, I looked in /tmp/vars.txt to see what was available to use. From there, I could use these directly both in my custom Bash script and in the black script field inside XCode, such as $SOURCE_ROOT.