annotate repoint.ps1 @ 33:b21704074c9c spect tip

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