annotate repoint.ps1 @ 399:a3912193ce69 tip

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