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