Xcodebuild 无法从项目文件中获取环境值?
我正在使用 Xcode 3.2.6、MacOSX。
我有一个全局可见的环境设置:
ICU_SRC=~/Documents/icu/source
这确实是一个环境设置,它是在登录时设置的。当我打开终端时,它就在那里。
在我的项目中,在 Header Search Paths
下,我添加了以下内容:
$(ICU_SRC)/i18n
$(ICU_SRC)/common
当我在 IDE 中编译时,这些路径会正确展开。当我查看构建结果时,我看到了这一点:
-I/Users/eric.grunin/Documents/icu/source/i18n
-I/Users/eric.grunin/Documents/icu/source/common
但是,当我从命令行构建时,它失败了。我看到的是这样的:
-I/i18n
-I/common
这是我用来编译的命令:
/usr/bin/env -i xcodebuild -project my_project.xcodeproj -target “my_program”-配置发布-sdk macosx10.6构建
我做错了什么?
编辑添加:
Apple 解释设置环境变量对于用户进程
I'm using Xcode 3.2.6, MacOSX.
I have a globally visible environment setting:
ICU_SRC=~/Documents/icu/source
This really is an environment setting, it's set at login time. When I open up Terminal, it's there.
In my project, under Header Search Paths
I've added this:
$(ICU_SRC)/i18n
$(ICU_SRC)/common
These expand correctly when I compile inside the IDE. When I look at the build results, I see this:
-I/Users/eric.grunin/Documents/icu/source/i18n
-I/Users/eric.grunin/Documents/icu/source/common
When I build from the command line, however, it fails. What I see is this:
-I/i18n
-I/common
Here's the command I'm using to compile:
/usr/bin/env -i xcodebuild -project my_project.xcodeproj -target
"my_program" -configuration Release -sdk macosx10.6 build
What am I doing wrong?
Edited to add:
Apple explains Setting environment variables for user processes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有时,如果您在
xcodebuild
命令之前指定环境变量,效果会更好,如使用 cocoapods 时,这对于
PRODUCT_NAME
尤其有效。Sometimes it works better if you specify the env vars before the
xcodebuild
command, as inThis works especially well for
PRODUCT_NAME
when working with cocoapods.您需要使用您的方案将 xcode 构建“连接”到 Xcode。
从 xcodebuild 方面:
xcodebuild ... 选项 ... yourVAR=yourValue
来自 Xcode ->产品->方案->编辑方案...->参数 ->环境变量
(name) someKey (Value) $yourVAR
关键是 xcodebuild 中 yourVAR 的名称将通过使用“$”从 Xcode 参数引用。
为了稍后从代码中访问环境变量,您需要使用
You need to "connect" xcode build to Xcode using your scheme.
From xcodebuild side :
xcodebuild ... options ... yourVAR=yourValue
From Xcode -> Product -> Scheme -> Edit Scheme... -> Arguments -> Environment Variables
(name) someKey (Value) $yourVAR
The key is that the name of yourVAR in xcodebuild will be referred from Xcode arguments, by using '$'.
In order to access the environment variable later from code, you need to use
我知道这个问题已经有两年了,但仍然具有现实意义。我刚刚花了一天时间追踪 xcodebuild 查看 CC 环境变量(如果已设置)并且可能会做错误的事情。我正在使用 xcodebuild 版本 6.1.1(构建版本 6A2008a)。
如果设置了 CC,我得到的错误是:
PBXTargetBuildContext.mm:1690
详细信息:commandPath 应该是一个字符串,位为零
提示:无
我希望这对其他人有帮助。
I know this question is 2 years old but it is still relevant. I just spent a day tracking down the fact that xcodebuild looks at the CC environmental variable (if it is set) and will probably do the wrong thing. I am using xcodebuild version 6.1.1 (build version 6A2008a).
The error I get if CC is set is:
PBXTargetBuildContext.mm:1690
Details: commandPath should be a string, bit it is nil
Hints: none
I hope this helps somebody else.
根据我的实验,xcodebuild 并没有真正从 Shell 获取环境变量。为了使 xcode 尊重环境变量,我们必须显式地传递它们:
上面的命令将系统环境变量传递给 xcodebuild 环境变量。您可以在 xcodeproj 中通过 $(ICU_SRC) 符号引用它。顺便说一句,我使用了不同的名称,这样我们就可以区分两个变量,但您也可以使用相同的变量名称。
~/.MacOSX/environment.plist 确实与我的示例中的导出行等效。只适用于壳牌。
希望有帮助。
As per my experiments, xcodebuild does not really pick up environment variable from Shell. To make xcode honor environment variables, we have to pass them explicitly:
The command above passes system environment variable to xcodebuild environment variable. You may reference it in your xcodeproj by $(ICU_SRC) notation. BTW, I used different names so we can distinguish two variables, but you can also use the same variable name.
The ~/.MacOSX/environment.plist is indeed equivalant with the export line in my example. It's for Shell only.
Hope that helps.
使用 Xcode 设置的“环境”设置实际上并不是环境变量;而是环境变量。只有 Xcode 知道它们。如果您希望它们成为真正的环境变量,可以从命令行看到,则必须使用以下 shell 命令:
The "environment" settings set using Xcode are not really environment variables; they're only known to Xcode. If you want them to be really environment variables, visible from the command line, you have to use the following shell command: