In Xcode, how to not run certain Run Script Build Phases when running Tests?
Asked Answered
K

2

7

My project is currently setup so that the MyApp target includes a few Run Script Build Phases. These scripts depend on the sequence of Build Phases. For example, there's a script that runs before Copy Bundle Resources and another one that runs afterwards.

My test target depends on MyApp, so when I run the tests (Product Menu, Test), I'd like to not include some of these scripts because it slows the testing down.

I thought to create an Aggregate Target which includes MyApp target. Then move the scripts I don't want to run when testing out of MyApp and into the Aggregate. However, I don't see how I can configure the same sequence of when these scripts will run by doing this.

Is there a way to do this? Or perhaps a better solution all together?

Kalamazoo answered 9/6, 2015 at 21:4 Comment(2)
I believe run scripts have a Run script only when installing option. Will that help you?Taking
@PetahChristian That won't completely help as at least one script needs to run each build, not just when installing.Kalamazoo
R
2

It depends on what your scripts doing:

  • You can create a Pre-Action (go to "edit-scheme") - there you can add a run script and it will be only executed when your running selected scheme. What you have to know is: Pre-Actions are on another thread, so if you want to stop the building process it won't work

  • If its possible: You can check your script if "debuging" or "releasing" you can use this if its enough to check just this two options like:

    wantedConfig="Debug"; currentConfig="$CONFIGURATION"    
    if [ $currentConfig=$wantedConfig ]; then
      echo "Now Im on a debug mode and will do all you want here";
    fi
    
  • You also can create your own environments variables like:

TEST_MODE=YES

..and use it like example above:

currentConfig="$TEST_MODE"

Retinite answered 1/6, 2016 at 9:4 Comment(1)
I tried adding env vars to both the host and the test schemes, for both "run" and "test" configurations, but in all 4 cases I got the empty echo output, like: echo "HOST_TEST_VAR = $HOST_TEST_VAR" outputs HOST_TEST_VAR =.Levis
P
0

It depends on what your scripts doing:

You can create a Pre-Action (go to "edit-scheme") - there you can add a run script and it will be only executed when your running selected scheme. What you have to know is: Pre-Actions are on another thread, so if you want to stop the building process it won't work

If its possible: You can check your script if "debuging" or "releasing" you can use this if its enough to check just this two options like:

wantedConfig="Debug"; currentConfig="$CONFIGURATION" if [ $currentConfig=$wantedConfig ]; then echo "Now Im on a debug mode and will do all you want here"; fi You also can create your own environments variables like:

TEST_MODE=YES

..and use it like example above:

currentConfig="$TEST_MODE"

The logic is there, but it keeps coming inside the if even thoug the configuration is different. After some debugging and searching this is the working snippet :

wantedConfig="PROD"
currentConfig="${CONFIGURATION}"  
echo "currentConfig = $CONFIGURATION"
if [ "$currentConfig" = "$wantedConfig" ]; then
    echo "begin action"
fi
Postobit answered 17/2, 2021 at 3:30 Comment(2)
What's the point of quoting the other answer in its entirely? You can just link to it if this answer is meant to correct it.Salts
As i said, when i tried to just copy and paste the snippet given, it keeps coming inside the if even though the actual value is different. I don't know why it doesn't work , i am not that familiar with scripting syntax and stuff. But after some debugging (i added space between the = inside the if), now it works. I attach the snippet to help people that have no extra time wondering what's wrong with it.Postobit

© 2022 - 2024 — McMap. All rights reserved.