annotate vext.ps1 @ 50:ec5b5a9adac2

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