Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ~/.bash_profile environment variables when using "Run Script" in "Build Phases" for XCode 6.1?

I have a cross platform unit testing framework that I use for C++. In order to build and run the tests in XCode 6.1 I need to run a python script as part of a prebuild script.

Since I use the same unit testing framework for multiple projects I figured it'd be great to use environment variables in my ~/.bash_profile to point to the resources necessary for the python script. But it seems that XCode 6.1 doesn't load the bash_profile before running the script in the build process. Are there alternatives to using the bash_profile? Maybe I could add my environment variables to the XCode environment variables list? But this seems to be changing with each update to OSX. I can't seem to figure out where I can add environment variables for XCode 6.1.

like image 425
David Avatar asked Jan 26 '15 22:01

David


1 Answers

You can run a shell script by adding a build phase to your target. The instructions are also here.

  1. Select the project file
  2. Select "Build Phases" at the top
  3. Select Editor > Add Build Phase > Add Run Script Build Phase
  4. Add your script in the box provided

in your case you can do:

source ~/.bash_profile

python [your_script]

You can rearrange the order of your build phases by dragging them into the order you want.

NOTE: The environment variables defined in ~/.bash_profile will not be there when you run your program (at least in my experience). To add environment variables to the run command:

  1. Select Product > Scheme > Edit Scheme...
  2. Select Run on the side bar
  3. Select the Arguments tab
  4. Put any Environment variables needed by your program in the proper section
like image 173
pdodd Avatar answered Sep 28 '22 05:09

pdodd