annotate vext.ps1 @ 53:f8110ba54f1b

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