方案脚本的 Xcode 4 构建设置变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5319989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 4 build setting variables for scheme scripts
提问by beinstein
I'm still getting used to Xcode 4, so forgive me if this is an asinine question:
我仍然习惯于 Xcode 4,所以如果这是一个愚蠢的问题,请原谅我:
In previous versions of Xcode, one could use any of the build setting variables (such as SRCROOT or PRODUCT_NAME, etc in any shell scripts associated with a build. This was easily accomplished by adding a 'Run Script' build phase to any target.
在以前版本的 Xcode 中,可以在与构建关联的任何 shell 脚本中使用任何构建设置变量(例如 SRCROOT 或 PRODUCT_NAME 等。这可以通过向任何目标添加“运行脚本”构建阶段来轻松实现。
In Xcode 4, however, the addition of schemes (really great, by the way) seems to disallow the usage of any of these variables. Is it possible this is by design? Is there a workaround?
然而,在 Xcode 4 中,方案的添加(顺便说一句,真的很棒)似乎不允许使用任何这些变量。这可能是设计使然吗?有解决方法吗?
回答by Martijn Thé
In the "Run Script" scheme action in Xcode 4.2 there is a "Provide build settings from..." drop down menu where you can select a target from which you would like to have the environment variables from. See screenshot below:
在 Xcode 4.2 中的“运行脚本”方案操作中,有一个“提供构建设置来自...”下拉菜单,您可以在其中选择您希望从中获得环境变量的目标。请看下面的截图:
Apart from that, if you select "None", there will be a bunch of environment variables set by Xcode. You can discover all of them by doing something like printenv > ~/Desktop/printenv.txt
to have them dumped to a text file.
除此之外,如果您选择“无”,Xcode 会设置一堆环境变量。您可以通过执行诸如printenv > ~/Desktop/printenv.txt
将它们转储到文本文件之类的操作来发现所有这些。
Some of the more useful environment variables include ARCHIVE_PATH
, SCHEME_NAME
, USER
, ARCHIVE_DSYMS_PATH
, ARCHIVE_PRODUCTS_PATH
.
一些更有用的环境变量包括ARCHIVE_PATH
、SCHEME_NAME
、USER
、ARCHIVE_DSYMS_PATH
、ARCHIVE_PRODUCTS_PATH
。
回答by kharrison
You can still add a Run Script to a target in Xcode 4 in much the same way you could with Xcode 3. First select the project in the left hand project navigator pane and then with the target selected look in the Build Phases tab for the Run Script section. The scripts can use the usual set of variables as with Xcode 3.
您仍然可以在 Xcode 4 中以与使用 Xcode 3 几乎相同的方式向目标添加运行脚本。首先在左侧项目导航器窗格中选择项目,然后在“构建阶段”选项卡中选择“运行”选项卡中的目标脚本部分。脚本可以使用与 Xcode 3 一样的常用变量集。
Reading some of the posts on this topic in the Apple developer forums it seems that Apple has at least acknowledged the limitations of the pre and post actions so we might see it fixed in a future update (open a bug report with Apple if you have not already done so).
阅读 Apple 开发者论坛中有关此主题的一些帖子,Apple 似乎至少承认了 pre 和 post 操作的局限性,因此我们可能会在未来的更新中看到它得到修复(如果您还没有,请打开与 Apple 的错误报告)已经这样做了)。