是否可以将用户定义的XCode构建设置导出到环境变量 [英] Is it possible to export user defined XCode build settings to environment variables
问题描述
我已经针对各种配置进行了一些构建设置,例如
I have made a few build settings for various configurations, e.g.
例如
我可以像这样在各种文件(例如info.plist)中访问它们:
I can access them in various files (e.g. the info.plist) like so:
${MYTESTSETTING}
但是可以在命令行环境中获取值吗?例如在詹金斯(Jenkins)的xcodebuild之后
However is it possible to get the value in the command line enviroment? e.g. after a xcodebuild from Jenkins
我尝试过
echo ${MYTESTSETTING}
还有
echo $MYTESTSETTING
推荐答案
xcodebuild -showBuildSettings
显示所有构建设置,包括用户定义的设置.示例:
shows all build settings, including the user-defined settings. Example:
$ xcodebuild -configuration Debug -showBuildSettings | grep MYTESTSETTING
MYTESTSETTING = DebugValue
$ xcodebuild -configuration Release -showBuildSettings | grep MYTESTSETTING
MYTESTSETTING = ReleaseValue
要将这些变量放入当前shell的环境中,必须分析此输出.例如,可以使用Perl脚本(或许多其他脚本语言)来完成此操作.
To get these variables into the environment of your current shell, you have to parse this output. This can for example be done with a Perl script (or many other scripting languages).
创建具有以下内容的Perl脚本"exportsettings.pl":
Create a Perl script "exportsettings.pl" with the following contents:
#!/usr/bin/perl
open(FH, "xcodebuild -configuration Release -showBuildSettings|");
while(<FH>) {
if (/\s*(\w+)\s*=\s*(.*)$/) { # Search for <key> = <value>
$key = $1; $value = $2;
print "export $key='$value'\n";
}
}
close(FH);
现在您可以运行命令
$ eval `perl exportsettings.pl`
从命令行
,并且(几乎)所有构建设置都在环境中. (将会出现一些错误消息,例如"UID:只读变量".)
from the command line, and (almost) all build settings are in the environment. (There will be some error messages, e.g. "UID: readonly variable").
如果在环境中仅需要使用定义的设置,则可以使用唯一的前缀(例如"MY")并更改行
If you need only your used-defined settings in the environment, you could use a unique prefix (e.g. "MY") and change the line
if (/\s*(\w+)\s*=\s*(.*)$/) { # Search for <key> = <value>
到
if (/\s*(MY\w+)\s*=\s*(.*)$/) { # Search for MY<key> = <value>
这篇关于是否可以将用户定义的XCode构建设置导出到环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!