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