如何在XCode 6.1的“Build Phases”中使用“Run Script”时使用〜/ .bash

系统教程 行业动态 更新时间:2024-06-14 16:57:18
如何在XCode 6.1的“Build Phases”中使用“Run Script”时使用〜/ .bash_profile环境变量?(How to use ~/.bash_profile environment variables when using “Run Script” in “Build Phases” for XCode 6.1?)

我有一个用于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 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:

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

更多推荐

本文发布于:2023-04-12 20:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/2b941e0d928bbda0d576ed752115b830.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   XCode   Build   bash   Script

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!