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