To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / repoint.ps1

History | View | Annotate | Download (2.71 KB)

1 100:dd1207a4dfc9 Chris
<#
2
3
.SYNOPSIS
4
A simple manager for third-party source code dependencies.
5 105:fa09c8e155ec Chris
Run "repoint help" for more documentation.
6 100:dd1207a4dfc9 Chris
7
#>
8
9
Set-StrictMode -Version 2.0
10
$ErrorActionPreference = "Stop"
11 105:fa09c8e155ec Chris
$env:HGPLAIN = "true"
12 100:dd1207a4dfc9 Chris
13 105:fa09c8e155ec Chris
$sml = $env:REPOINT_SML
14 100:dd1207a4dfc9 Chris
15
$mydir = Split-Path $MyInvocation.MyCommand.Path -Parent
16 105:fa09c8e155ec Chris
$program = "$mydir/repoint.sml"
17 100:dd1207a4dfc9 Chris
18
# We need either Poly/ML or SML/NJ. No great preference as to which.
19
20 105:fa09c8e155ec Chris
# 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 100:dd1207a4dfc9 Chris
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 105:fa09c8e155ec Chris
  The Repoint external source code manager needs a Standard ML (SML)
34 100:dd1207a4dfc9 Chris
  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 105:fa09c8e155ec Chris
if ($args -match "'""") {
51 100:dd1207a4dfc9 Chris
    $arglist = '["usage"]'
52
} else {
53
    $arglist = '["' + ($args -join '","') + '"]'
54
}
55
56
if ($sml -eq "poly") {
57
58
    $program = $program -replace "\\","\\\\"
59 105:fa09c8e155ec Chris
    echo "use ""$program""; repoint $arglist" | polyml -q --error-exit | Out-Host
60 100:dd1207a4dfc9 Chris
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 105:fa09c8e155ec Chris
val _ = repoint $arglist;
90 100:dd1207a4dfc9 Chris
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
}