annotate repoint.ps1 @ 266:d04675d44928 tip master

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