我有一个用于C ++的跨平台单元测试框架。 为了在XCode 6.1中构建并运行测试,我需要运行一个python脚本作为预构建脚本的一部分。
由于我对多个项目使用相同的单元测试框架,我认为在我的~/.bash_profile使用环境变量来指向python脚本所需的资源会很好。 但是,在构建过程中运行脚本之前,似乎XCode 6.1不加载bash_profile 。 有没有其他方法可以使用bash_profile ? 也许我可以将我的环境变量添加到XCode环境变量列表中? 但是这似乎随着OSX的每次更新而改变。 我似乎无法弄清楚我可以在哪里添加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.
最满意答案
您可以通过向目标添加构建阶段来运行shell脚本。 说明也在这里 。
选择项目文件 在顶部选择“Build Phases” 选择编辑器>添加构建阶段>添加运行脚本构建阶段 在提供的框中添加您的脚本在你的情况下,你可以这样做:
源〜/ .bash_profile
python [your_script]
您可以通过将您的构建阶段拖动到所需的顺序来重新排列构建阶段的顺序。
注意:在运行程序时,〜/ .bash_profile中定义的环境变量将不存在(至少在我的经验中)。 要将环境变量添加到运行命令:
选择产品>计划>编辑计划... 在侧栏上选择运行 选择参数选项卡 将程序所需的任何环境变量放在适当的部分You can run a shell script by adding a build phase to your target. The instructions are also here.
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 providedin 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:
Select Product > Scheme > Edit Scheme... Select Run on the side bar Select the Arguments tab Put any Environment variables needed by your program in the proper section更多推荐
发布评论