annotate repoint.ps1 @ 1896:d06c8628c5e2

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