Created
July 31, 2013 22:05
-
-
Save tapi/6126601 to your computer and use it in GitHub Desktop.
An Xcode build phase script to automatically run mogenerator on your xcdatamodel if it has changed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Xcode sets up its own PATH variable so we want to ensure that it includes /usr/local/bin | |
PATH=$PATH:/usr/local/bin | |
# Check that mogenerator is available | |
command -v mogenerator >/dev/null 2>&1 || { echo >&2 "You need mogenerator but it's not installed. To install using homebrew use 'brew install mogenerator'. Aborting."; exit 1; } | |
# Change the working dir to where our models are | |
cd "${SRCROOT}"/Models | |
# Only run mogenerator if the access time for ResultsCache.xcdatamodeld is newer than our lock file | |
MODEL_ACCESS=$[ $(stat -f '%m' ResultsCache.xcdatamodeld) ] | |
LOCK_ACCESS=$[ $(stat -f '%m' mogenerator.lock) ] | |
if [ $MODEL_ACCESS -gt $LOCK_ACCESS ]; then | |
# Run mogenerator | |
mogenerator -m ResultsCache.xcdatamodeld --includeh PXModels.h -M generated/ \ | |
--template-path Templates \ | |
--template-var arc=true \ | |
--template-var frc=true \ | |
--template-var project="${PROJECT}" \ | |
--template-var user="${USER}" \ | |
--template-var year=`date "+%Y"` \ | |
--template-var date=`date "+%d-%m-%Y"` \ | |
--template-var year=`date "+%Y"` | |
# Update the access times of our lockfile using our xcdatamodeld as a reference | |
touch -r ResultsCache.xcdatamodeld mogenerator.lock | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment