Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current Scheme Name from Run Script Phase

Tags:

xcode

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

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

like image 601
James Campbell Avatar asked Sep 05 '25 03:09

James Campbell


2 Answers

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.

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}

Build Pre-action

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}`

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).

like image 137
David Avatar answered Sep 07 '25 21:09

David


Simplest one is set 'User Defined' variable as per scheme and use it.

like image 20
Amit Avatar answered Sep 07 '25 21:09

Amit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!