annotate repoint @ 393:b081441c7970

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