annotate repoint @ 33:b21704074c9c spect tip

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