annotate repoint @ 266:d04675d44928 tip master

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