Running pre-/post-build Python scripts from XCode


For anyone interested in running Python scripts during the pre- or post-build phase in XCode, this is what we’re doing:

We’ve set this in the “Post-build-shell script” entry within the Projucer:


We’re calling a sh-file first, instead of the Python script directly, as this ensures that the build is interrupted on error. This is the script:

#!/usr/bin/env bash

function callPythonScript()
    # them in <sys.argv> in the Python script.

    # Exit on error.
    if [ $return_code -ne 0 ]; then
        exit 1;

# Note that we're currently in /project/xcode/<product_folder>
callPythonScript "../../../installer/mac/";

exit 0;

Out Python script, with some condition to only run on Release, and only on the aggregate target (note that this currently only works on JUCE’s current develop branch, not on master):

#!/usr/bin/env python

import os

is_release = os.environ['CONFIGURATION'] == 'Release'
is_aggregate = os.environ['TARGET_NAME'].endswith('(All)')

# Only run on release, and only run at the end
# (when the aggregate target is built).
if is_release and is_aggregate:
    product_name = os.environ['PRODUCT_NAME']
    #.. build installer, do stuff etc

Hope this is of some help for some.

Post-build script