comparison vext.ps1 @ 70:2d3e1d1f99c0

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