Chris@79: <# Chris@79: Chris@79: .SYNOPSIS Chris@79: A simple manager for third-party source code dependencies. Chris@79: Run "repoint help" for more documentation. Chris@79: Chris@79: #> Chris@79: Chris@79: Set-StrictMode -Version 2.0 Chris@79: $ErrorActionPreference = "Stop" Chris@79: $env:HGPLAIN = "true" Chris@79: Chris@79: $sml = $env:REPOINT_SML Chris@79: Chris@79: $mydir = Split-Path $MyInvocation.MyCommand.Path -Parent Chris@79: $program = "$mydir/repoint.sml" Chris@79: Chris@79: # We need either Poly/ML or SML/NJ. No great preference as to which. Chris@79: Chris@79: # Typical locations Chris@79: $env:PATH = "$env:PATH;C:\Program Files (x86)\SMLNJ\bin;C:\Program Files\Poly ML;C:\Program Files (x86)\Poly ML" Chris@79: Chris@79: if (!$sml) { Chris@79: if (Get-Command "sml" -ErrorAction SilentlyContinue) { Chris@79: $sml = "smlnj" Chris@79: } elseif (Get-Command "polyml" -ErrorAction SilentlyContinue) { Chris@79: $sml = "poly" Chris@79: } else { Chris@79: echo @" Chris@79: Chris@79: ERROR: No supported SML compiler or interpreter found Chris@79: Chris@79: The Repoint external source code manager needs a Standard ML (SML) Chris@79: compiler or interpreter to run. Chris@79: Chris@79: Please ensure you have one of the following SML implementations Chris@79: installed and present in your PATH, and try again. Chris@79: Chris@79: 1. Standard ML of New Jersey Chris@79: - executable name: sml Chris@79: Chris@79: 2. Poly/ML Chris@79: - executable name: polyml Chris@79: Chris@79: "@ Chris@79: exit 1 Chris@79: } Chris@79: } Chris@79: Chris@79: if ($args -match "'""") { Chris@79: $arglist = '["usage"]' Chris@79: } else { Chris@79: $arglist = '["' + ($args -join '","') + '"]' Chris@79: } Chris@79: Chris@79: if ($sml -eq "poly") { Chris@79: Chris@79: $program = $program -replace "\\","\\\\" Chris@79: echo "use ""$program""; repoint $arglist" | polyml -q --error-exit | Out-Host Chris@79: Chris@79: if (-not $?) { Chris@79: exit $LastExitCode Chris@79: } Chris@79: Chris@79: } elseif ($sml -eq "smlnj") { Chris@79: Chris@79: $lines = @(Get-Content $program) Chris@79: $lines = $lines -notmatch "val _ = main ()" Chris@79: Chris@79: $intro = @" Chris@79: val smlrun__cp = Chris@79: let val x = !Control.Print.out in Chris@79: Control.Print.out := { say = fn _ => (), flush = fn () => () }; Chris@79: x Chris@79: end; Chris@79: val smlrun__prev = ref ""; Chris@79: Control.Print.out := { Chris@79: say = fn s => Chris@79: (if String.isSubstring "Error" s orelse String.isSubstring "Fail" s Chris@79: then (Control.Print.out := smlrun__cp; Chris@79: (#say smlrun__cp) (!smlrun__prev); Chris@79: (#say smlrun__cp) s) Chris@79: else (smlrun__prev := s; ())), Chris@79: flush = fn s => () Chris@79: }; Chris@79: "@ -split "[\r\n]+" Chris@79: Chris@79: $outro = @" Chris@79: val _ = repoint $arglist; Chris@79: val _ = OS.Process.exit (OS.Process.success); Chris@79: "@ -split "[\r\n]+" Chris@79: Chris@79: $script = @() Chris@79: $script += $intro Chris@79: $script += $lines Chris@79: $script += $outro Chris@79: Chris@79: $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml" Chris@79: Chris@79: $script | Out-File -Encoding "ASCII" $tmpfile Chris@79: Chris@79: $env:CM_VERBOSE="false" Chris@79: Chris@79: sml $tmpfile Chris@79: Chris@79: if (-not $?) { Chris@79: del $tmpfile Chris@79: exit $LastExitCode Chris@79: } Chris@79: Chris@79: del $tmpfile Chris@79: Chris@79: } else { Chris@79: Chris@79: "Unknown SML implementation name: $sml" Chris@79: exit 2 Chris@79: }