Xcode scheme pre-action script not running

Pre-action takes place before the build, so output doesn't go to the build log, it goes to stdErr. You can copy the output to a file:

exec > ${PROJECT_DIR}/prebuild.log 2>&1
echo "hello world"

To get the environment variables to work, you also need to set "Provide build settings from" to the appropriate target.

enter image description here

That should write hello world to a file named "prebuild.log" in your project folder.

If you want these activities to end up in the build log, consider adding a run script to your target's build phase instead.


To add to the answer, https://stackoverflow.com/a/42497746/1058199, it's important to not clutter up the project.pbxproj (where build scripts go) or your scheme file (where these scripts go) as much as possible.

With this in mind, I create a Build-Scripts folder in the project root where I put the app build scripts and pre-action scripts. This folder is dragged into the root of the project as a folder so that any script I add to it is automatically added to project.

Assuming that your pre-action script is called That_pre-action_script.sh, this is what I put in Pre-actions script based on the approved answer.

say "Pre build scripts running."
exec > "${PROJECT_DIR}/prebuild.log" 2>&1
echo "Starting build scheme Pre-actions"
"${PROJECT_DIR}/Build-Phases/That_pre-action_script.sh"

As a test, make sure to echo some message from your script so you can see it in the prebuild.log file.

Hope this helps.

And don't forget to chmod u+x your script in the terminal so that it will run.

The important part is if you can't make sure if your build script is running or not. This is where the say command us useful so that you know it's actually being issued before a build.

It's a good idea to put quotes around the path to the script in case there are any space characters (or otherwise) in the path to your project.

Tags:

Bash

Xcode