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