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