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