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.
我有一个用于c++的跨平台单元测试框架。为了在XCode 6.1中构建和运行测试,我需要作为预构建脚本的一部分运行python脚本。
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.
由于我在多个项目中使用了相同的单元测试框架,所以我认为在我的~/中使用环境变量是很好的。bash_profile指向python脚本所需的资源。但是看起来XCode 6.1在构建过程中运行脚本之前并没有加载bash_profile。有使用bash_profile的替代方案吗?也许我可以将环境变量添加到XCode环境变量列表中?但随着OSX的每一次更新,这种情况似乎都在发生变化。我似乎不知道在哪里可以为XCode 6.1添加环境变量。
1 个解决方案
#1
5
You can run a shell script by adding a build phase to your target. The instructions are also here.
您可以通过向目标添加构建阶段来运行shell脚本。说明也在这里。
- Select the project file
- 选择项目文件
- Select "Build Phases" at the top
- 在顶部选择“构建阶段”
- Select Editor > Add Build Phase > Add Run Script Build Phase
- 选择编辑>添加构建阶段>添加运行脚本构建阶段。
- Add your script in the box provided
- 在提供的框中添加脚本
in your case you can do:
在你的情况下,你可以这样做:
source ~/.bash_profile
源~ / . bash_profile
python [your_script]
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:
注意:在~/中定义的环境变量。当您运行程序时,bash_profile将不存在(至少在我的经验中是这样)。向run命令添加环境变量:
- Select Product > Scheme > Edit Scheme...
- 选择产品>方案>编辑方案…
- Select Run on the side bar
- 选择在侧边栏上运行
- Select the Arguments tab
- 选择Arguments选项卡
- Put any Environment variables needed by your program in the proper section
- 将程序所需的任何环境变量放在适当的部分中
#1
5
You can run a shell script by adding a build phase to your target. The instructions are also here.
您可以通过向目标添加构建阶段来运行shell脚本。说明也在这里。
- Select the project file
- 选择项目文件
- Select "Build Phases" at the top
- 在顶部选择“构建阶段”
- Select Editor > Add Build Phase > Add Run Script Build Phase
- 选择编辑>添加构建阶段>添加运行脚本构建阶段。
- Add your script in the box provided
- 在提供的框中添加脚本
in your case you can do:
在你的情况下,你可以这样做:
source ~/.bash_profile
源~ / . bash_profile
python [your_script]
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:
注意:在~/中定义的环境变量。当您运行程序时,bash_profile将不存在(至少在我的经验中是这样)。向run命令添加环境变量:
- Select Product > Scheme > Edit Scheme...
- 选择产品>方案>编辑方案…
- Select Run on the side bar
- 选择在侧边栏上运行
- Select the Arguments tab
- 选择Arguments选项卡
- Put any Environment variables needed by your program in the proper section
- 将程序所需的任何环境变量放在适当的部分中