Skip to content

Instantly share code, notes, and snippets.

@ModestGoblin
Last active November 30, 2015 22:27
Show Gist options
  • Save ModestGoblin/d67fce3e14df2f399985 to your computer and use it in GitHub Desktop.
Save ModestGoblin/d67fce3e14df2f399985 to your computer and use it in GitHub Desktop.
SCAS is a small XCode shell script which efficiently packages a Mac OS X Application's source code into the application itself. The resulting embedded project directory is fully funcitonal, allowing the code and resources to be examined, modified and re-built.
#!/bin/bash
# Source Code Access Script
set -eux
# Only bundle the source for Release/Deployment builds.
if [ "$CONFIGURATION" != 'Release' -a "$CONFIGURATION" != 'Deployment' ] ; then exit ; fi
INSIDE_SOURCE="$TARGET_BUILD_DIR"/"$CONTENTS_FOLDER_PATH"/Source
PROJECT_NAME=`basename "$PROJECT_FILE_PATH"`
rm -rf "$INSIDE_SOURCE"
mkdir -p "$INSIDE_SOURCE"
# Copy the source tree, minus resources, into Content/Source.
rsync -a --cvs-exclude --extended-attributes \
--exclude 'build' --exclude '*.pbxuser' --exclude '*.mode1' \
--exclude '*.lproj' --exclude '*.tiff' --exclude '*.png' --exclude '*.icns' --exclude '*.scriptSuite' \
$@ \
"$SRCROOT"/ "$INSIDE_SOURCE"
# Check if the project has already been modified for embedding.
if ! grep 'path = ../Resources;' "$PROJECT_FILE_PATH"/project.pbxproj
then
# No, so modify the project to find resources in the Package's Resources directory.
# Change the location of Info.plist, since it isn't like other resources. Add _Mod to
# Current Project Version to identify derivitive apps.
sed \
-e '/name = Resources;/a\
path = ../Resources;\
' \
-e 's/path = Info.plist; sourceTree = "<group>";/path = Info.plist; sourceTree = SOURCE_ROOT;/' \
-e 's/CURRENT_PROJECT_VERSION = \(.*\);/CURRENT_PROJECT_VERSION = \1_Mutant;/g' \
"$PROJECT_FILE_PATH"/project.pbxproj > "$INSIDE_SOURCE"/"$PROJECT_NAME"/project.pbxproj
# Check if the project is embedded.
elif [ -d "$SRCROOT"/../../../"$WRAPPER_NAME" ]
then
# Project embedded, so syncrhonize the build result to the enclosing application.
rsync -a --extended-attributes --exclude 'Source' "$TARGET_BUILD_DIR"/"$WRAPPER_NAME"/ "$SRCROOT"/../../../"$WRAPPER_NAME"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment