Mercurial > hg > sonic-visualiser
comparison repoint.ps1 @ 1808:adc8a48f4e4c repoint
Vext -> Repoint. Let's see how this goes.
author | Chris Cannam |
---|---|
date | Wed, 09 May 2018 13:28:55 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1807:dc4e6eb475ed | 1808:adc8a48f4e4c |
---|---|
1 <# | |
2 | |
3 .SYNOPSIS | |
4 A simple manager for third-party source code dependencies. | |
5 Run "repoint help" for more documentation. | |
6 | |
7 #> | |
8 | |
9 Set-StrictMode -Version 2.0 | |
10 $ErrorActionPreference = "Stop" | |
11 $env:HGPLAIN = "true" | |
12 | |
13 $sml = $env:REPOINT_SML | |
14 | |
15 $mydir = Split-Path $MyInvocation.MyCommand.Path -Parent | |
16 $program = "$mydir/repoint.sml" | |
17 | |
18 # We need either Poly/ML or SML/NJ. No great preference as to which. | |
19 | |
20 # Typical locations | |
21 $env:PATH = "$env:PATH;C:\Program Files (x86)\SMLNJ\bin;C:\Program Files\Poly ML;C:\Program Files (x86)\Poly ML" | |
22 | |
23 if (!$sml) { | |
24 if (Get-Command "sml" -ErrorAction SilentlyContinue) { | |
25 $sml = "smlnj" | |
26 } elseif (Get-Command "polyml" -ErrorAction SilentlyContinue) { | |
27 $sml = "poly" | |
28 } else { | |
29 echo @" | |
30 | |
31 ERROR: No supported SML compiler or interpreter found | |
32 | |
33 The Repoint external source code manager needs a Standard ML (SML) | |
34 compiler or interpreter to run. | |
35 | |
36 Please ensure you have one of the following SML implementations | |
37 installed and present in your PATH, and try again. | |
38 | |
39 1. Standard ML of New Jersey | |
40 - executable name: sml | |
41 | |
42 2. Poly/ML | |
43 - executable name: polyml | |
44 | |
45 "@ | |
46 exit 1 | |
47 } | |
48 } | |
49 | |
50 if ($args -match "'""") { | |
51 $arglist = '["usage"]' | |
52 } else { | |
53 $arglist = '["' + ($args -join '","') + '"]' | |
54 } | |
55 | |
56 if ($sml -eq "poly") { | |
57 | |
58 $program = $program -replace "\\","\\\\" | |
59 echo "use ""$program""; repoint $arglist" | polyml -q --error-exit | Out-Host | |
60 | |
61 if (-not $?) { | |
62 exit $LastExitCode | |
63 } | |
64 | |
65 } elseif ($sml -eq "smlnj") { | |
66 | |
67 $lines = @(Get-Content $program) | |
68 $lines = $lines -notmatch "val _ = main ()" | |
69 | |
70 $intro = @" | |
71 val smlrun__cp = | |
72 let val x = !Control.Print.out in | |
73 Control.Print.out := { say = fn _ => (), flush = fn () => () }; | |
74 x | |
75 end; | |
76 val smlrun__prev = ref ""; | |
77 Control.Print.out := { | |
78 say = fn s => | |
79 (if String.isSubstring "Error" s orelse String.isSubstring "Fail" s | |
80 then (Control.Print.out := smlrun__cp; | |
81 (#say smlrun__cp) (!smlrun__prev); | |
82 (#say smlrun__cp) s) | |
83 else (smlrun__prev := s; ())), | |
84 flush = fn s => () | |
85 }; | |
86 "@ -split "[\r\n]+" | |
87 | |
88 $outro = @" | |
89 val _ = repoint $arglist; | |
90 val _ = OS.Process.exit (OS.Process.success); | |
91 "@ -split "[\r\n]+" | |
92 | |
93 $script = @() | |
94 $script += $intro | |
95 $script += $lines | |
96 $script += $outro | |
97 | |
98 $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml" | |
99 | |
100 $script | Out-File -Encoding "ASCII" $tmpfile | |
101 | |
102 $env:CM_VERBOSE="false" | |
103 | |
104 sml $tmpfile | |
105 | |
106 if (-not $?) { | |
107 del $tmpfile | |
108 exit $LastExitCode | |
109 } | |
110 | |
111 del $tmpfile | |
112 | |
113 } else { | |
114 | |
115 "Unknown SML implementation name: $sml" | |
116 exit 2 | |
117 } |