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