Packaging up a Project
One of the great things about computers is the way that they let us automate tasks that we repeat often, right? A task that I find I repeat often is packaging up an application and it's source code to be distributed. So, I wrote myself a little script to do the job automatically:
#!/bin/bash
#automatic packaging script by Niemand. 5/10/2008
#move to the directory the command file was run from
cd "$(dirname "$0")"
#check if expected directory structure exists
if [ ! -d "build" ]
then
echo "'./build' does not exist, aborting"
exit
fi
if [ ! -d "build/Release" ]
then
echo "'./build/Release' does not exist, aborting"
exit
fi
#move to the built product
cd ./build/Release/
#get the product name
if [ `ls *.app | wc -l` = 0 ]
then
echo "No built product found, aborting"
exit
fi
APPNAME=`ls | sed -n 's/\([^.]*\).app/\1/p'`
echo "Product name is: $APPNAME"
#create the output directory if necessary
cd ..
if [ ! -d "Current" ]
then
mkdir "Current"
echo "Created './build/Current' to contain output."
fi
#move to the output directory
cd Current/
#erase old output if present
if [ -f "$APPNAME.tgz" ]
then
rm "$APPNAME.tgz"
echo "Erased old $APPNAME.tgz"
fi
if [ -f "$APPNAME Source Code.tgz" ]
then
rm "$APPNAME Source Code.tgz"
echo "Erased old $APPNAME Source Code.tgz"
fi
#back to the product directory
cd ../Release/
#make a compressed copy of the product
echo "Compressing product..."
tar -czf "../Current/$APPNAME.tgz" "./$APPNAME.app"
#make a copy of the source code
#move mack up to the original directory
cd ../..
#make a clean copy of the project
echo "Exporting source code..."
svn export ./ "./build/Current/$APPNAME Source Code"
#test to see whether we got anything
if [ ! -d "./build/Current/$APPNAME Source Code" ]
then
echo "export failed, aborting"
exit
fi
#go to the output directory
cd ./build/Current/
#make a compressed copy of the copy
echo "Compressing source code..."
tar -czf "./$APPNAME Source Code.tgz" "./$APPNAME Source Code"
#delete the uncompressed copy
echo "Deleting temporary source code copy..."
rm -r "./$APPNAME Source Code"
echo "Finished"
To use this script save it as a '.command' file in the main directory of an XCode Project, which is then run by double clicking form the FInder. There are a couple of things that it requires to work correctly:
- The project directory must be a subversion working copy, checked out from some repository. The script could easily enough be modified to do the copying itself, instead of using
svn exportso that it would work with non-subversion controlled projects instead. - The built product must be an application bundle in the
Releasesubdirectory of thebuilddirectory. This too could be changed.
The script creates separate gzipped tarballs of the application and the project directory and places them in ./build/Current/