annotate repoint.ps1 @ 125:34e428693f5d vext

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