annotate vext.ps1 @ 523:9fc762aafd01

Switch to Vext
author Chris Cannam
date Mon, 10 Jul 2017 19:27:26 +0100
parents
children 2cc8700975db
rev   line source
Chris@523 1 <#
Chris@523 2
Chris@523 3 .SYNOPSIS
Chris@523 4 A simple manager for third-party source code dependencies.
Chris@523 5 Run "vext help" for more documentation.
Chris@523 6
Chris@523 7 #>
Chris@523 8
Chris@523 9 $sml = $env:VEXT_SML
Chris@523 10
Chris@523 11 $mydir = Split-Path $MyInvocation.MyCommand.Path -Parent
Chris@523 12 $program = "$mydir/vext.sml"
Chris@523 13
Chris@523 14 # We need either Poly/ML or SML/NJ. No great preference as to which.
Chris@523 15
Chris@523 16 if (!$sml) {
Chris@523 17 if (Get-Command "polyml" -ErrorAction SilentlyContinue) {
Chris@523 18 $sml = "poly"
Chris@523 19 } elseif (Get-Command "sml" -ErrorAction SilentlyContinue) {
Chris@523 20 $sml = "smlnj"
Chris@523 21 } else {
Chris@523 22 echo @"
Chris@523 23
Chris@523 24 ERROR: No supported SML compiler or interpreter found
Chris@523 25
Chris@523 26 The Vext external source code manager needs a Standard ML (SML)
Chris@523 27 compiler or interpreter to run.
Chris@523 28
Chris@523 29 Please ensure you have one of the following SML implementations
Chris@523 30 installed and present in your PATH, and try again.
Chris@523 31
Chris@523 32 1. Poly/ML
Chris@523 33 - executable name: polyml
Chris@523 34
Chris@523 35 2. Standard ML of New Jersey
Chris@523 36 - executable name: sml
Chris@523 37
Chris@523 38 "@
Chris@523 39 exit 1
Chris@523 40 }
Chris@523 41 }
Chris@523 42
Chris@523 43 if ($args -match "[^a-z]") {
Chris@523 44 $arglist = '["usage"]'
Chris@523 45 } else {
Chris@523 46 $arglist = '["' + ($args -join '","') + '"]'
Chris@523 47 }
Chris@523 48
Chris@523 49 if ($sml -eq "poly") {
Chris@523 50
Chris@523 51 $program = $program -replace "\\","\\\\"
Chris@523 52 echo "use ""$program""; vext $arglist" | polyml -q --error-exit | Out-Host
Chris@523 53
Chris@523 54 } elseif ($sml -eq "smlnj") {
Chris@523 55
Chris@523 56 $lines = @(Get-Content $program)
Chris@523 57 $lines = $lines -notmatch "val _ = main ()"
Chris@523 58
Chris@523 59 $intro = @"
Chris@523 60 val smlrun__cp =
Chris@523 61 let val x = !Control.Print.out in
Chris@523 62 Control.Print.out := { say = fn _ => (), flush = fn () => () };
Chris@523 63 x
Chris@523 64 end;
Chris@523 65 val smlrun__prev = ref "";
Chris@523 66 Control.Print.out := {
Chris@523 67 say = fn s =>
Chris@523 68 (if String.isSubstring "Error" s orelse String.isSubstring "Fail" s
Chris@523 69 then (Control.Print.out := smlrun__cp;
Chris@523 70 (#say smlrun__cp) (!smlrun__prev);
Chris@523 71 (#say smlrun__cp) s)
Chris@523 72 else (smlrun__prev := s; ())),
Chris@523 73 flush = fn s => ()
Chris@523 74 };
Chris@523 75 "@ -split "[\r\n]+"
Chris@523 76
Chris@523 77 $outro = @"
Chris@523 78 val _ = vext $arglist;
Chris@523 79 val _ = OS.Process.exit (OS.Process.success);
Chris@523 80 "@ -split "[\r\n]+"
Chris@523 81
Chris@523 82 $script = @()
Chris@523 83 $script += $intro
Chris@523 84 $script += $lines
Chris@523 85 $script += $outro
Chris@523 86
Chris@523 87 $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml"
Chris@523 88
Chris@523 89 $script | Out-File -Encoding "ASCII" $tmpfile
Chris@523 90
Chris@523 91 $env:CM_VERBOSE="false"
Chris@523 92
Chris@523 93 sml $tmpfile $args[1,$args.Length]
Chris@523 94
Chris@523 95 del $tmpfile
Chris@523 96
Chris@523 97 } else {
Chris@523 98
Chris@523 99 "Unknown SML implementation name: $sml"
Chris@523 100 exit 2
Chris@523 101 }