Get current Scheme Name from Run Script Phase

后端 未结 3 2002
渐次进展
渐次进展 2021-02-05 04:41

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

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

3条回答
  •  心在旅途
    2021-02-05 05:13

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

提交回复
热议问题