From a8d0dfdacceb6ece787273a3db04b6acce2b9b4c Mon Sep 17 00:00:00 2001 From: walker0643 <> Date: Wed, 14 Feb 2018 14:41:59 -0500 Subject: [PATCH] recursive re-referencing of binaries, and add cocoa qt platform plugin --- build_mac_installer.sh | 42 +++++++++++++++++++++++++++++------------- mac_reref_dylibs.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 13 deletions(-) create mode 100755 mac_reref_dylibs.sh diff --git a/build_mac_installer.sh b/build_mac_installer.sh index 8a815047..b2d98ad9 100755 --- a/build_mac_installer.sh +++ b/build_mac_installer.sh @@ -10,6 +10,12 @@ read cd $(dirname $0) +B_REREF_SCRIPT=$(pwd)/mac_reref_dylibs.sh +if [ ! -x $B_REREF_SCRIPT ]; then + echo Missing script: $B_REREF_SCRIPT + exit 1 +fi + # remove any old copies so there's no confusion about whever this # process completes successfully or not rm -rf build/bundle/{bundle.dmg,$B_DMG} @@ -31,18 +37,28 @@ cd MacOS || exit 1 # copy all executables cp ${B_BINARY_PATH}/* . || exit 1 -# only one executable (barrier) needs non-system libraries. -# get a list of them and make local copies -B_LIBS=$(otool -XL barrier | awk '{ print $1 }' | grep -Ev '^(/usr/lib|/System)') -[ $? -ne 0 ] && exit 1 -for B_SRC in $B_LIBS; do - cp $B_SRC . || exit 1 - B_DST=@executable_path/$(basename $B_SRC) - # adjust the executable's metadata to point to the local copy - # rather than the system-wide copy which would only exist on - # a development machine - install_name_tool -change $B_SRC $B_DST barrier || exit 1 -done +# copy the qt platform plugin +# TODO: this is hacky and will probably break if there is more than one qt +# version installed. need a better way to find this library +B_COCOA=$(find /usr/local/Cellar/qt -type f -name libqcocoa.dylib | head -1) +if [ $? -ne 0 ] || [ "x$B_COCOA" = "x" ]; then + echo "Could not find cocoa platform plugin" + exit 1 +fi +mkdir platforms +cp $B_COCOA platforms/ || exit 1 + +# make sure we can r/w all these binaries +chmod -R u+rw * || exit 1 + +# only one executable (barrier) needs non-system libraries although it's +# libraries can call each other. use a recursive script to handle the +# re-referencing +$B_REREF_SCRIPT barrier || exit 1 +# the cocoa platform plugin also needs to know where to find the qt libraries. +# because it exists in a subdirectory we append ../ to the relative path of the +# libraries in its metadata +$B_REREF_SCRIPT platforms/libqcocoa.dylib ../ || exit 1 # create a startup script that will change to the binary directory # before starting barrier @@ -51,7 +67,7 @@ chmod +x barrier.sh # create the DMG to be distributed in build/bundle cd ../../.. -hdiutil create -size 32m -fs HFS+ -volname "Barrier" bundle.dmg || exit 1 +hdiutil create -size 64m -fs HFS+ -volname "Barrier" bundle.dmg || exit 1 hdiutil attach bundle.dmg -mountpoint mnt || exit 1 cp -r Barrier.app mnt/ || exit 1 hdiutil detach mnt || exit 1 diff --git a/mac_reref_dylibs.sh b/mac_reref_dylibs.sh new file mode 100755 index 00000000..15191bd2 --- /dev/null +++ b/mac_reref_dylibs.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# $1 = binary (program or dylib) +B_TARGET=$1 +if [ "x$B_TARGET" = "x" ]; then + echo Which binary needs to be re-referenced? + exit 1 +fi + +cd $(dirname $B_TARGET) || exit 1 + +# where to find non-system libraries relative to target's directory. +# the vast majority of the time this should be empty +B_REL_PATH=$2 + +# we're in target's directory now. trim off the path +B_TARGET=$(basename $B_TARGET) + +# get a list of non-system libraries and make local copies +B_LIBS=$(otool -XL $B_TARGET | awk '{ print $1 }' | grep -Ev '^(/usr/lib|/System)') +[ $? -ne 0 ] && exit 1 +for B_LIB in $B_LIBS; do + B_LIB_NAME=$(basename $B_LIB) + + # ignore self-references + [ "$B_TARGET" = "$B_LIB_NAME" ] && continue + + B_DST=${B_REL_PATH}${B_LIB_NAME} + if [ ! -e $B_DST ]; then + cp $B_LIB $B_DST || exit 1 + chmod u+rw $B_DST || exit 1 + # recursively call this script on libraries purposefully not passing + # $B_REL_PATH so that it is only used explicitly + $0 $B_DST + fi + + # adjust the target's metadata to point to the local copy + # rather than the system-wide copy which would only exist on + # a development machine + install_name_tool -change $B_LIB @loader_path/$B_DST $B_TARGET || exit 1 +done