annotate repoint @ 64:0c94d3065ecd

Fix app signing; remove plugin signing from project files, as we now need to separate out the plugin build, plugin signing, and installer build phases on every platform
author Chris Cannam
date Tue, 11 Feb 2020 10:16:49 +0000
parents eaa4410df4cd
children
rev   line source
Chris@0 1 #!/bin/bash
Chris@0 2
Chris@0 3 # Disable shellcheck warnings for useless-use-of-cat. UUOC is good
Chris@0 4 # practice, not bad: clearer, safer, less error-prone.
Chris@0 5 # shellcheck disable=SC2002
Chris@0 6
Chris@0 7 sml="$REPOINT_SML"
Chris@0 8
Chris@0 9 set -eu
Chris@0 10
Chris@0 11 # avoid gussying up output
Chris@0 12 export HGPLAIN=true
Chris@0 13
Chris@0 14 mydir=$(dirname "$0")
Chris@0 15 program="$mydir/repoint.sml"
Chris@0 16
Chris@0 17 hasher=
Chris@0 18 local_install=
Chris@0 19 if [ -w "$mydir" ]; then
Chris@0 20 if echo | sha256sum >/dev/null 2>&1 ; then
Chris@0 21 hasher=sha256sum
Chris@0 22 local_install=true
Chris@0 23 elif echo | shasum >/dev/null 2>&1 ; then
Chris@0 24 hasher=shasum
Chris@0 25 local_install=true
Chris@0 26 else
Chris@0 27 echo "WARNING: sha256sum or shasum program not found" 1>&2
Chris@0 28 fi
Chris@0 29 fi
Chris@0 30
Chris@0 31 if [ -n "$local_install" ]; then
Chris@0 32 hash=$(echo "$sml" | cat "$program" - | $hasher | cut -c1-16)
Chris@0 33 gen_sml=$mydir/.repoint-$hash.sml
Chris@0 34 gen_out=$mydir/.repoint-$hash.bin
Chris@0 35 trap 'rm -f $gen_sml' 0
Chris@0 36 else
Chris@0 37 gen_sml=$(mktemp /tmp/repoint-XXXXXXXX.sml)
Chris@0 38 gen_out=$(mktemp /tmp/repoint-XXXXXXXX.bin)
Chris@0 39 trap 'rm -f $gen_sml $gen_out' 0
Chris@0 40 fi
Chris@0 41
Chris@0 42 if [ -x "$gen_out" ]; then
Chris@0 43 exec "$gen_out" "$@"
Chris@0 44 fi
Chris@0 45
Chris@0 46 # We need one of Poly/ML, SML/NJ, MLton, or MLKit. Since we're running
Chris@0 47 # a single-file SML program as if it were a script, our order of
Chris@0 48 # preference is usually based on startup speed. An exception is the
Chris@0 49 # local_install case, where we retain a persistent binary
Chris@0 50
Chris@0 51 if [ -z "$sml" ]; then
Chris@0 52 if [ -n "$local_install" ] && mlton 2>&1 | grep -q 'MLton'; then
Chris@0 53 sml="mlton"
Chris@0 54 elif sml -h 2>&1 | grep -q 'Standard ML of New Jersey'; then
Chris@0 55 sml="smlnj"
Chris@0 56 # We would prefer Poly/ML to SML/NJ, except that Poly v5.7 has a
Chris@0 57 # nasty bug that occasionally causes it to deadlock on startup.
Chris@0 58 # That is fixed in v5.7.1, so we could promote it up the order
Chris@0 59 # again at some point in future
Chris@0 60 elif echo | poly -v 2>/dev/null | grep -q 'Poly/ML'; then
Chris@0 61 sml="polyml"
Chris@0 62 elif mlton 2>&1 | grep -q 'MLton'; then
Chris@0 63 sml="mlton"
Chris@0 64 # MLKit is at the bottom because it leaves compiled files around
Chris@0 65 # in an MLB subdir in the current directory
Chris@0 66 elif mlkit 2>&1 | grep -q 'MLKit'; then
Chris@0 67 sml="mlkit"
Chris@0 68 else cat 1>&2 <<EOF
Chris@0 69
Chris@0 70 ERROR: No supported SML compiler or interpreter found
Chris@0 71 EOF
Chris@0 72 cat 1>&2 <<EOF
Chris@0 73
Chris@0 74 The Repoint external source code manager needs a Standard ML (SML)
Chris@0 75 compiler or interpreter to run.
Chris@0 76
Chris@0 77 Please ensure you have one of the following SML implementations
Chris@0 78 installed and present in your PATH, and try again.
Chris@0 79
Chris@0 80 1. Standard ML of New Jersey
Chris@0 81 - may be found in a distribution package called: smlnj
Chris@0 82 - executable name: sml
Chris@0 83
Chris@0 84 2. Poly/ML
Chris@0 85 - may be found in a distribution package called: polyml
Chris@0 86 - executable name: poly
Chris@0 87
Chris@0 88 3. MLton
Chris@0 89 - may be found in a distribution package called: mlton
Chris@0 90 - executable name: mlton
Chris@0 91
Chris@0 92 4. MLKit
Chris@0 93 - may be found in a distribution package called: mlkit
Chris@0 94 - executable name: mlkit
Chris@0 95
Chris@0 96 EOF
Chris@0 97 exit 2
Chris@0 98 fi
Chris@0 99 fi
Chris@0 100
Chris@0 101 arglist=""
Chris@0 102 for arg in "$@"; do
Chris@0 103 if [ -n "$arglist" ]; then arglist="$arglist,"; fi
Chris@0 104 if echo "$arg" | grep -q '["'"'"']' ; then
Chris@0 105 arglist="$arglist\"usage\""
Chris@0 106 else
Chris@0 107 arglist="$arglist\"$arg\""
Chris@0 108 fi
Chris@0 109 done
Chris@0 110
Chris@0 111 case "$sml" in
Chris@0 112 polyml)
Chris@0 113 if [ -n "$local_install" ] && polyc --help >/dev/null 2>&1 ; then
Chris@0 114 if [ ! -x "$gen_out" ]; then
Chris@0 115 polyc -o "$gen_out" "$program"
Chris@0 116 fi
Chris@0 117 "$gen_out" "$@"
Chris@0 118 else
Chris@0 119 echo 'use "'"$program"'"; repoint ['"$arglist"'];' |
Chris@0 120 poly -q --error-exit
Chris@0 121 fi ;;
Chris@0 122 mlton)
Chris@0 123 if [ ! -x "$gen_out" ]; then
Chris@0 124 echo "[Precompiling Repoint binary...]" 1>&2
Chris@0 125 echo "val _ = main ()" | cat "$program" - > "$gen_sml"
Chris@0 126 mlton -output "$gen_out" "$gen_sml"
Chris@0 127 fi
Chris@0 128 "$gen_out" "$@" ;;
Chris@0 129 mlkit)
Chris@0 130 if [ ! -x "$gen_out" ]; then
Chris@0 131 echo "[Precompiling Repoint binary...]" 1>&2
Chris@0 132 echo "val _ = main ()" | cat "$program" - > "$gen_sml"
Chris@0 133 mlkit -output "$gen_out" "$gen_sml"
Chris@0 134 fi
Chris@0 135 "$gen_out" "$@" ;;
Chris@0 136 smlnj)
Chris@0 137 cat "$program" | (
Chris@0 138 cat <<EOF
Chris@0 139 val smlrun__cp =
Chris@0 140 let val x = !Control.Print.out in
Chris@0 141 Control.Print.out := { say = fn _ => (), flush = fn () => () };
Chris@0 142 x
Chris@0 143 end;
Chris@0 144 val smlrun__prev = ref "";
Chris@0 145 Control.Print.out := {
Chris@0 146 say = fn s =>
Chris@0 147 (if String.isSubstring " Error" s
Chris@0 148 then (Control.Print.out := smlrun__cp;
Chris@0 149 (#say smlrun__cp) (!smlrun__prev);
Chris@0 150 (#say smlrun__cp) s)
Chris@0 151 else (smlrun__prev := s; ())),
Chris@0 152 flush = fn s => ()
Chris@0 153 };
Chris@0 154 EOF
Chris@0 155 cat -
Chris@0 156 cat <<EOF
Chris@0 157 val _ = repoint [$arglist];
Chris@0 158 val _ = OS.Process.exit (OS.Process.success);
Chris@0 159 EOF
Chris@0 160 ) > "$gen_sml"
Chris@0 161 CM_VERBOSE=false sml "$gen_sml" ;;
Chris@0 162 *)
Chris@0 163 echo "ERROR: Unknown SML implementation name: $sml" 1>&2;
Chris@0 164 exit 2 ;;
Chris@0 165 esac
Chris@0 166