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