2

I have the following script saved as a Run Script in my project's target:

git_output=$(git status | grep "nothing to commit, working directory clean")
if [[ -z "$git_output" ]]; then
    xcrun agvtool next-version -all
fi

Which checks the git repo to see if there are any pending changes, and if so increments the project's build number. That all works fine.

The problem is that when running KIF tests, the changing of the build number messes with the running of the KIF tests so that it never ends up launching the simulator and running. I have verified that if no such build number increment occurs, the KIF test will run just fine.

The easiest way to go about this would to specify within Xcode to not run a given script when running a certain scheme. Additionally, if I could query which scheme is being run from within the script itself, that would accomplish the same thing. But I am unaware how to do either of those.

Stunner
  • 12,025
  • 12
  • 86
  • 145

1 Answers1

1

You could add your own "Test" build configuration which you select in your scheme. For this build configuration you can define your own GCC_PREPROCESSOR_DEFINITIONS.

From your script you can then access these with {GCC_PREPROCESSOR_DEFINITIONS}.

needle="NO_BUILD=1"
haystack="${GCC_PREPROCESSOR_DEFINITIONS}"
if [[ "$haystack" =~ "$needle" ]]; then
  echo "Test Build. Do not increase build number." >> ~/Desktop/Test.txt
else
  echo "Not a test build" >> ~/Desktop/Test.txt
fi

For this build setting to be set only on a specific scheme follow these steps.

  1. Create a configuration.

Create a Configuration

  1. Set the build settings for this configuration.

Set the build settings for this configuration

  1. Edit your scheme and choose the configuration.

Choose the configuration for the scheme

Onato
  • 9,916
  • 5
  • 46
  • 54
  • Cool, but how would I go about querying for, say, `NO_BUILD` within `{GCC_PREPROCESSOR_DEFINITIONS}`? Knowing how to view output from these run scripts would be immensely helpful... ;) – Stunner Nov 12 '14 at 01:41
  • 1
    Found out how to view output from run scripts by the way... http://stackoverflow.com/a/18219518/347339 – Stunner Nov 12 '14 at 01:48
  • 1
    I updated my answer with an example of how to access a preprocessor definition. – Onato Nov 13 '14 at 10:03
  • Unfortunately no. I got what you were saying, but there was no way for me to read environment variables tied to a specific scheme. Your solution works for things that are in the project's build settings, not an individual scheme's options. – Stunner Dec 03 '14 at 20:26
  • There is a way. I described it briefly in my answer. I have added screenshots to clarify. Don't give up, it works. – Onato Dec 03 '14 at 20:43