Write a build phase script

In the Build Phases pane of the project editor, you can configure a project to run a shell script as part of building a target. In the shell script, you can use build phase-specific variables in addition to environment variables. You can also write to the build log and trigger a build failure.

Use additional variables

You can use these additional variables in a build phase shell script:

Variable

Description

SCRIPT_INPUT_FILE_COUNT

The total number of script files described as inputs.

SCRIPT_INPUT_FILE_[#]

Each input file listed is exported as an environment variable, starting with SCRIPT_INPUT_FILE_0.

SCRIPT_INPUT_FILE_LIST_COUNT

The total number of file lists described as input file lists.

SCRIPT_INPUT_FILE_LIST_[#]

A path to the file with each of the values within the given input list resolved with their expanded values, starting with SCRIPT_INPUT_FILE_LIST_0.

SCRIPT_OUTPUT_FILE_COUNT

The total number of script files described as outputs.

SCRIPT_OUTPUT_FILE_[#]

Each output file listed is exported as an environment variable, starting with SCRIPT_OUTPUT_FILE_0.

SCRIPT_OUTPUT_FILE_LIST_COUNT

The total number of file lists described as output file lists.

SCRIPT_OUTPUT_FILE_LIST_[#]

A path to the file with each of the values within the given output list resolved with their expanded values, starting with SCRIPT_OUTPUT_FILE_LIST_0.

Log errors and warnings

To add errors and warnings to the build log, write the message to standard out and prefix it with either error: or warning:. These messages will appear in the build log.

Trigger a build failure

To trigger a build failure, return a non-zero exit code from the script.

For example:

echo "error: This is an error message that will show up in the build log."echo "warning: This is a warning message that will show up in the build log."# This will cause a build failureexit 1
See alsoRun a shell script