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