annotate vext.ps1 @ 212:9b858df4e8b0

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