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