|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +q(){ echo "Error at: $*" >&2 ; exit 5 ; } # exit function |
| 4 | + |
| 5 | +alttarbase="$2" |
| 6 | +alttardir="$3" |
| 7 | + |
| 8 | +cleaner(){ |
| 9 | + step="Remove build directory" |
| 10 | + echo "$step" ; rm -Rf build || q "$step" |
| 11 | +} |
| 12 | + |
| 13 | +basedir="$(dirname $(realpath $0))" |
| 14 | +[ -d "$basedir" ] || q "Insane basedir '$basedir'" |
| 15 | +cd "$basedir" || q "Can't cd to $basedir" |
| 16 | + |
| 17 | +builddirname=build |
| 18 | +builddir="$basedir/$builddirname" # this can be deleted to retry a build |
| 19 | +basename=OoliteDebugConsole2 # gets used a lot |
| 20 | +inscript=DebugConsole.py # the name of the script we'll be 'compiling' |
| 21 | +venv="$builddir/pyinstaller" |
| 22 | +relpath="../../../" |
| 23 | + |
| 24 | +prep(){ |
| 25 | + mkdir -p "$builddir" || q "Can't create $builddir." |
| 26 | + cd "$builddir" || q "Can't cd to builddir $builddir" |
| 27 | + step="setting up venv and building tools" |
| 28 | + python3 -m venv "$venv" && |
| 29 | + source "$venv"/bin/activate && |
| 30 | + pip install click && |
| 31 | + pip install twisted && |
| 32 | + pip install pyinstaller || q "$step" |
| 33 | +} |
| 34 | + |
| 35 | + |
| 36 | +setupvars(){ |
| 37 | + #cd to base directory and set up base variables |
| 38 | + cd "$basedir" |
| 39 | + cd ../.. && ver=$(echo " |
| 40 | +from _version import __version__ |
| 41 | +print(__version__) |
| 42 | +" | python3 ) && cd - || q "error ascertaining version" |
| 43 | + [ "x$ver" = "x" ] && q "version not found. version file empty or absent" |
| 44 | + [ "x$alttarbase" != "x" ] && tarbase="$alttarbase" || tarbase="${basename}-$ver-macos_$(arch)" |
| 45 | + [ "x$alttardir" != "x" ] && tardir="$alttardir" || tardir="$basedir" |
| 46 | + mkdir -p "$tardir" || q "could not create dir '$tardir' to house tarballs" |
| 47 | +} |
| 48 | + |
| 49 | +onefile(){ |
| 50 | +step="making executable" |
| 51 | +echo "$step" |
| 52 | +pyinstaller --name "$basename" --onefile "${relpath}$inscript" \ |
| 53 | + --add-binary "${relpath}oojsc.xbm:." --add-binary "${relpath}OoJSC.ico:." \ |
| 54 | + --add-binary "${relpath}OoJSC256x256.png:." && |
| 55 | +tarname="$tarbase-onefile.tgz" |
| 56 | +tar -C "$builddir/dist" --numeric-owner --dereference \ |
| 57 | + -cpzf "$tardir/$tarname" . || q "$failed $step" |
| 58 | +mv dist/$basename $basedir && |
| 59 | +echo " |
| 60 | +Finished $step. |
| 61 | +
|
| 62 | +To test the executable run: |
| 63 | +
|
| 64 | +./$basename |
| 65 | +
|
| 66 | +A tarball is at '$tardir/$tarname'. |
| 67 | +
|
| 68 | +" || q "$step" |
| 69 | +} |
| 70 | + |
| 71 | +#Arg 1 chooses action. clean or dist. |
| 72 | +case "$1" in |
| 73 | + clean) cleaner ;; # remove entire build directory |
| 74 | + dist) cleaner && setupvars && prep && onefile ;; |
| 75 | + *) q "Setup: Invalid arg 1: [clean|dist]" ;; |
| 76 | +esac |
| 77 | + |
| 78 | +#end |
0 commit comments