annotate vext.ps1 @ 313:cf863362a9df

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