annotate vext.ps1 @ 1711:10952e402220 vext

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