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