annotate repoint.ps1 @ 80:f84e12a1553c tip

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