从运行脚本阶段获取当前方案名称 [英] Get current Scheme Name from Run Script Phase

查看:26
本文介绍了从运行脚本阶段获取当前方案名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从运行脚本阶段获取当前方案?

Is there a way of grabbing the current scheme from a run script phase?

我试过 $(SCHEME_NAME) 但它不存在.

I've tried $(SCHEME_NAME) but it doesn't exist.

推荐答案

我找不到要使用的环境变量,所以我不得不开发一个变通方法:在 Build Pre 中将方案名称写入磁盘-action,然后在运行脚本阶段将其读回.

I couldn't find an environment variable to use, so I had to develop a work around: write a scheme name to disk in the Build Pre-action and then read it back out in the Run Script phase.

对于您感兴趣的每个方案,转到 Edit Scheme 并添加具有以下代码的脚本:

For each scheme you're interested in go to Edit Scheme and add a script with the following code:

rm -rf ${INTERMEDIATES_OUTPUT_DIR}
mkdir -p ${INTERMEDIATES_OUTPUT_DIR}
echo MY_SCHEME_NAME > ${SCHEME_FILE}

接下来,转到构建目标的构建设置"并添加两个用户定义的设置":

Next, go to your build target's "Build Settings" and add two "User-Defined Settings":

INTERMEDIATES_OUTPUT_DIR=${PROJECT_DIR}/build/intermediates/${CONFIGURATION}/
SCHEME_FILE=${INTERMEDIATES_OUTPUT_DIR}current_scheme.txt

打开您的运行脚本"并添加:

Open up your "Run script" and add this:

SCHEME_NAME=`cat ${SCHEME_FILE}`

确保将中间体构建目录添加到您的 .gitignore 文件中.

Be sure to add the intermediates build directory to your .gitignore file.

显然,您可以通过对文件名进行硬编码来稍微简化一下,但这会更健壮一些(而且我们还有其他东西最终会出现在中间目录中).

Obviously you could simplify this a bit by hardcoding a file name but this is a bit more robust (and we have other stuff that ends up in the intermediates directory, too).

这篇关于从运行脚本阶段获取当前方案名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆