Package osx dependencies separately from the main download; Game is now run from inside app bundle; Support dir used to cache downloads only

This commit is contained in:
Paul Chote
2010-07-07 21:45:46 +12:00
parent 12a350b89f
commit 9d70bb24a6
3 changed files with 69 additions and 79 deletions

View File

@@ -16,17 +16,21 @@
# along with OpenRA. If not, see <http://www.gnu.org/licenses/>. # along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
# #
# Tweakable options # Tweakable options
#export MONO_LOG_LEVEL=debug #export MONO_LOG_LEVEL=debug
GAME_PATH=~/Library/"Application Support"/OpenRA SUPPORT_PATH=~/Library/"Application Support"/OpenRA
RA_MIXEN="http://open-ra.org/packages/ra-packages.zip" DEPS_PACKAGE="osx-deps-v1.zip"
CNC_MIXEN="http://open-ra.org/packages/cnc-packages.zip" DEPS_URL="http://localhost/~paul/osx-deps-v1.zip"
#RA_URL="http://open-ra.org/packages/ra-packages.zip"
#CNC_URL="http://open-ra.org/packages/cnc-packages.zip"
RA_URL="http://localhost/~paul/ra-packages.zip"
CNC_URL="http://localhost/~paul/cnc-packages.zip"
# Internal options # Internal options
APP_PATH=`echo $0 | awk '{split($0,patharr,"/"); idx=1; while(patharr[idx+3] != "") { if (patharr[idx] != "/") {printf("%s/", patharr[idx]); idx++ }} }'` APP_PATH=`echo $0 | awk '{split($0,patharr,"/"); idx=1; while(patharr[idx+3] != "") { if (patharr[idx] != "/") {printf("%s/", patharr[idx]); idx++ }} }'`
EXE_PATH=$APP_PATH/Contents/MacOS/ EXE_PATH=$APP_PATH/Contents/MacOS/
RESOURCES_PATH=$APP_PATH/Contents/Resources RESOURCES_PATH=$APP_PATH/Contents/Resources
GAME_PATH=$RESOURCES_PATH
PAYLOAD=$RESOURCES_PATH/payload.zip PAYLOAD=$RESOURCES_PATH/payload.zip
VERSION=`cat "$APP_PATH/Contents/Resources/VERSION"` VERSION=`cat "$APP_PATH/Contents/Resources/VERSION"`
export LD_LIBRARY_PATH="$EXE_PATH/lib":$LD_LIBRARY_PATH export LD_LIBRARY_PATH="$EXE_PATH/lib":$LD_LIBRARY_PATH
@@ -61,11 +65,18 @@ EOT`
# $5: download url # $5: download url
function download_package function download_package
{ {
PWD=`pwd`
if [ ! -d "$SUPPORT_PATH" ]; then
mkdir -p "$SUPPORT_PATH"
fi
cd "$SUPPORT_PATH"
if [ -e "downloads/${1}" ]; then if [ -e "downloads/${1}" ]; then
mkdir -p "${2}" mkdir -p "${2}"
unzip -o "downloads/${1}" -d "${2}" unzip -o "downloads/${1}" -d "${2}"
else else
pwd
CONTINUE=`/usr/bin/osascript << EOT CONTINUE=`/usr/bin/osascript << EOT
tell application "Finder" tell application "Finder"
display dialog "OpenRA needs to download the ${4} game data.\nDownload size: ${3}" \ display dialog "OpenRA needs to download the ${4} game data.\nDownload size: ${3}" \
@@ -78,14 +89,16 @@ EOT`
if [ "$CONTINUE" != "Download" ]; then if [ "$CONTINUE" != "Download" ]; then
exit 1 exit 1
fi fi
mkdir -p "${2}" mkdir -p "${2}"
/usr/bin/osascript << EOT /usr/bin/osascript << EOT
tell application "Terminal" tell application "Terminal"
activate activate
do script "cd \"${GAME_PATH}\"; curl --create-dirs -o \"./downloads/${1}\" \"${5}\"; touch \"downloads/done\"; exit;" do script "cd \"${SUPPORT_PATH}\"; curl --create-dirs -o \"./downloads/${1}\" \"${5}\"; touch \"downloads/done\"; exit;"
end tell end tell
EOT EOT
# Hack around osascript returning before the download finishes # Hack around osascript returning before the download finishes
while [ ! -e "downloads/done" ]; do while [ ! -e "downloads/done" ]; do
sleep 1 sleep 1
@@ -97,23 +110,12 @@ EOT
fi fi
unzip -o "downloads/${1}" -d "${2}" unzip -o "downloads/${1}" -d "${2}"
fi fi
cd "$PWD"
} }
# Install the game in the users Application Support directory if it doesn't exist # Download and install game dependencies if needed
if [ ! -e "$GAME_PATH/OpenRA.Game.exe" ]; then if [[ ! -e "$EXE_PATH/mono" ]]; then
mkdir -p ~/Library/Application\ Support/OpenRA download_package "$DEPS_PACKAGE" "$EXE_PATH" "17.2 Mb" "Game Dependencies" $DEPS_URL
unzip "$PAYLOAD" -d "$GAME_PATH"
if [ ! -e "$GAME_PATH/OpenRA.Game.exe" ]; then
display_error "Installation error" "Game setup failed"
fi
fi
# Is the installed version older than the current version?
INSTVER=`cat "$GAME_PATH/VERSION"`
if [ $INSTVER -lt $VERSION ]; then
echo "Updating installed version $INSTVER to $VERSION"
unzip -o "$PAYLOAD" -d "$GAME_PATH"
fi fi
# Prompt for the mod to run # Prompt for the mod to run
@@ -134,19 +136,20 @@ MOD="ra"
if [ "$MODBUTTON" == "C&C" ]; then if [ "$MODBUTTON" == "C&C" ]; then
MOD="cnc" MOD="cnc"
fi fi
cd "$GAME_PATH"
# Check that the game data is installed # Check that the game data is installed
if [[ $MOD == "ra" && ! -e "mods/ra/packages/redalert.mix" ]]; then if [[ $MOD == "ra" && ! -e "$GAME_PATH/mods/ra/packages/redalert.mix" ]]; then
download_package "ra-packages.zip" "mods/ra/packages/" "10 Mb" "Red Alert" $RA_MIXEN download_package "ra-packages.zip" "$GAME_PATH/mods/ra/packages/" "10 Mb" "Red Alert" $RA_URL
fi fi
if [[ $MOD == "cnc" && ! -e "mods/cnc/packages/conquer.mix" ]]; then if [[ $MOD == "cnc" && ! -e "$GAME_PATH/mods/cnc/packages/conquer.mix" ]]; then
download_package "cnc-packages.zip" "mods/cnc/packages/" "5.9 Mb" "C&C" $CNC_MIXEN download_package "cnc-packages.zip" "$GAME_PATH/mods/cnc/packages/" "5.9 Mb" "C&C" $CNC_URL
fi fi
# Run the game # Run the game
${EXE_PATH}mono OpenRA.Game.exe InitialMods=$MOD cd "${GAME_PATH}"
${EXE_PATH}mono "OpenRA.Game.exe" InitialMods=$MOD
# Did we crash? # Did we crash?
STATUS=$? STATUS=$?

View File

@@ -1,30 +1,26 @@
#!/bin/sh #!/bin/sh
# OpenRA Packaging script for osx # OpenRA Packaging script for osx
# Creates a self contained app bundle that contains # Packages all the dependencies required to run the game.
# all the dependencies required to run the game.
# This script assumes that it is being run on osx >= 10.5 # This script assumes that it is being run on osx >= 10.5
# and that all the required dependencies are installed # and that all the required dependencies are installed
# and the dependant dlls exist in the system GAC. # and the dependant dlls exist in the system GAC.
# $GAME_PATH in OpenRA.app/Contents/MacOS/OpenRA
# specifies the game directory to load. This can point
# anywhere on the filesystem.
# A list of the binaries that we want to be able to run # A list of the binaries that we want to be able to run
DEPS_LOCAL="OpenRA.Game.exe OpenRA.Gl.dll OpenRA.FileFormats.dll" DEPS_LOCAL="OpenRA.Game.exe OpenRA.Gl.dll OpenRA.FileFormats.dll"
PACKAGING_DIR="osxbuild/launcher" PWD=`pwd`
PACKAGING_PATH="$PWD/osxbuild"
BINARY_PATH="$PACKAGING_PATH/deps"
LIB_PATH="$BINARY_PATH/lib"
SYSTEM_MONO="/Library/Frameworks/Mono.framework/Versions/2.6.3" SYSTEM_MONO="/Library/Frameworks/Mono.framework/Versions/2.6.3"
# dylibs referred to by dlls in the gac; won't show up to otool # dylibs referred to by dlls in the gac; won't show up to otool
GAC_DYLIBS="$SYSTEM_MONO/lib/libMonoPosixHelper.dylib $SYSTEM_MONO/lib/libgdiplus.dylib " GAC_DYLIBS="$SYSTEM_MONO/lib/libMonoPosixHelper.dylib $SYSTEM_MONO/lib/libgdiplus.dylib "
#################################################################################### ####################################################################################
EXE_DIR="$PACKAGING_DIR/OpenRA.app/Contents/MacOS"
LIB_DIR="$EXE_DIR/lib"
function patch_mono { function patch_mono {
echo "Patching binary: "$1 echo "Patching binary: "$1
LIBS=$( otool -L $1 | grep /Library/Frameworks/Mono.framework/ | awk {'print $1'} ) LIBS=$( otool -L $1 | grep /Library/Frameworks/Mono.framework/ | awk {'print $1'} )
# Todo: fix the -id?
for i in $LIBS; do for i in $LIBS; do
install_name_tool -change $i @executable_path/lib/`basename $i` $1 install_name_tool -change $i @executable_path/lib/`basename $i` $1
done done
@@ -37,9 +33,9 @@ function patch_mono {
for i in $LIBS; do for i in $LIBS; do
FILE=`basename $i` FILE=`basename $i`
if [ ! -e $LIB_DIR/$FILE ]; then if [ ! -e $LIB_PATH/$FILE ]; then
cp $i $LIB_DIR cp $i $LIB_PATH
patch_mono $LIB_DIR/$FILE patch_mono $LIB_PATH/$FILE
fi fi
done done
} }
@@ -51,36 +47,29 @@ export CC="gcc -arch i386 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/Ma
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig/ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig/
export PATH=/sw/bin:/sw/sbin:$PATH export PATH=/sw/bin:/sw/sbin:$PATH
# Copy and patch mono
echo "Creating app bundle..."
# Create the directory tree and copy in our existing files # Create the directory tree and copy in our existing files
mkdir -p $PACKAGING_DIR/OpenRA.app mkdir -p "$LIB_PATH"
cp -r ./packaging/osx/OpenRA.app/* $PACKAGING_DIR/OpenRA.app/ cp "$SYSTEM_MONO/bin/mono" "$BINARY_PATH"
mkdir -p $LIB_DIR patch_mono "$BINARY_PATH/mono"
# Copy the gac dylibs=
cp "$SYSTEM_MONO/bin/mono" $EXE_DIR
patch_mono "$EXE_DIR/mono"
# Copy the gac dylibs into the app bundle
for i in $GAC_DYLIBS; do for i in $GAC_DYLIBS; do
cp $i $LIB_DIR cp $i $LIB_PATH
patch_mono $LIB_DIR/`basename $i` patch_mono $LIB_PATH/`basename $i`
done done
# Find the dlls that are used by the game; copy them into the app bundle and patch/package any dependencies # Find the dlls that are used by the game; copy them into the app bundle and patch/package any dependencies
echo "Searching for dlls..." echo "Searching for dlls... (this will take a while)"
# This is a huge hack, but it works # This is a huge hack, but it works
DLLS=`mkbundle --deps --static -z -c -o OpenRA $DEPS_LOCAL | grep "embedding: "` DLLS=`mkbundle --deps -c -o "$PACKAGING_PATH/bogus" $DEPS_LOCAL | grep "embedding: "`
rm "$PACKAGING_PATH/bogus"
for i in $DLLS; do for i in $DLLS; do
if [ "$i" != "embedding:" ]; then if [ "$i" != "embedding:" ]; then
cp $i $LIB_DIR cp $i $LIB_PATH
if [ -e "$i.config" ]; then if [ -e "$i.config" ]; then
CONFIG=$LIB_DIR/"`basename $i`.config" CONFIG=$LIB_PATH/"`basename $i`.config"
echo "Patching config: $CONFIG" echo "Patching config: $CONFIG"
# Remove any references to the hardcoded mono framework; the game will look in the right location anyway # Remove any references to the hardcoded mono framework; the game will look in the right location anyway
@@ -94,18 +83,22 @@ done
# Remove the files that we want to run that we accidentally copied over # Remove the files that we want to run that we accidentally copied over
for i in $DEPS_LOCAL; do for i in $DEPS_LOCAL; do
rm "$LIB_DIR/$i" rm "$LIB_PATH/$i"
done done
# Copy external frameworks # Copy external frameworks
echo "Copying Cg..." echo "Copying Cg..."
cp /Library/Frameworks/Cg.framework/Cg $LIB_DIR cp -X /Library/Frameworks/Cg.framework/Cg $LIB_PATH
chmod 755 $LIB_DIR/Cg chmod 755 $LIB_PATH/Cg
echo "Copying SDL..." echo "Copying SDL..."
cp /Library/Frameworks/SDL.framework/SDL $LIB_DIR cp -X /Library/Frameworks/SDL.framework/SDL $LIB_PATH
xattr -d com.apple.quarantine $LIB_DIR/SDL chmod 755 $LIB_PATH/SDL
chmod 755 $LIB_DIR/SDL
cd "$BINARY_PATH"
zip osx-deps-v1 -r -9 *
mv osx-deps-v1.zip "$PACKAGING_PATH"
rm -rf "$BINARY_PATH"
echo "All Done!" echo "All Done!"

View File

@@ -5,35 +5,29 @@
PWD=`pwd` PWD=`pwd`
PACKAGING_PATH="$PWD/osxbuild" PACKAGING_PATH="$PWD/osxbuild"
LAUNCHER_PATH="$PACKAGING_PATH/launcher/OpenRA.app"
SOURCE_PATH="$PWD/." SOURCE_PATH="$PWD/."
BUNDLE_PATH="$SOURCE_PATH/packaging/osx/OpenRA.app"
TARGET_PATH="$PACKAGING_PATH/OpenRA.app/Contents/Resources"
FILES="OpenRA.Game.exe OpenRA.Gl.dll OpenRA.FileFormats.dll FreeSans.ttf FreeSansBold.ttf titles.ttf shaders maps mods/ra mods/cnc" FILES="OpenRA.Game.exe OpenRA.Gl.dll OpenRA.FileFormats.dll FreeSans.ttf FreeSansBold.ttf titles.ttf shaders maps mods/ra mods/cnc"
EXCLUDE="*.mdb ./mods/cnc/packages/*.mix ./mods/ra/packages/*.mix ./mods/cnc/packages/*.MIX ./mods/ra/packages/*.MIX" EXCLUDE="*.mdb ./mods/cnc/packages/*.mix ./mods/ra/packages/*.mix ./mods/cnc/packages/*.MIX ./mods/ra/packages/*.MIX"
# Copy source files into packaging dir # Copy source files into packaging dir
PAYLOAD="$PACKAGING_PATH/payload" mkdir -p $PACKAGING_PATH
mkdir -p $PAYLOAD cp -r "$BUNDLE_PATH" "$PACKAGING_PATH/OpenRA.app"
mkdir -p "$PAYLOAD/mods" mkdir -p "$TARGET_PATH/mods"
for i in $FILES; do for i in $FILES; do
cp -RX "$i" "$PAYLOAD/$i" cp -R "$i" "$TARGET_PATH/$i"
done done
# Delete unwanted files # Delete unwanted files
cd $PAYLOAD cd $TARGET_PATH
for i in $EXCLUDE; do for i in $EXCLUDE; do
find . -path "$i" -delete find . -path "$i" -delete
done done
date "+%Y%m%d%H%M" > "VERSION"
zip payload -r -9 * git describe --tags > "VERSION"
cd $PACKAGING_PATH cd $PACKAGING_PATH
#zip OpenRA -r -9 OpenRA.app
# Move everything into the app bundle
cp -r "$LAUNCHER_PATH" .
cp "$PAYLOAD/payload.zip" "OpenRA.app/Contents/Resources/"
cp "$PAYLOAD/VERSION" "OpenRA.app/Contents/Resources/"
rm -rf $PAYLOAD
zip OpenRA -r -9 OpenRA.app
echo "Done!" echo "Done!"