Skip to content

Commit 5c31047

Browse files
committed
utils: cleanup Invoke-Program in build.ps1.
1 parent 28f9641 commit 5c31047

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

utils/build.ps1

+22-18
Original file line numberDiff line numberDiff line change
@@ -560,28 +560,30 @@ function Copy-Directory($Src, $Dst) {
560560

561561
function Invoke-Program() {
562562
[CmdletBinding(PositionalBinding = $false)]
563-
param(
563+
param
564+
(
564565
[Parameter(Position = 0, Mandatory = $true)]
565566
[string] $Executable,
566-
[switch] $OutNull = $false,
567+
[switch] $Silent,
568+
[switch] $OutNull,
567569
[string] $OutFile = "",
568570
[string] $ErrorFile = "",
569571
[Parameter(Position = 1, ValueFromRemainingArguments)]
570-
[string[]] $Args
572+
[string[]] $ExecutableArgs
571573
)
572574

573575
if ($ToBatch) {
574576
# Print the invocation in batch file-compatible format
575577
$OutputLine = "`"$Executable`""
576578
$ShouldBreakLine = $false
577-
for ($i = 0; $i -lt $Args.Length; $i++) {
579+
for ($i = 0; $i -lt $ExecutableArgs.Length; $i++) {
578580
if ($ShouldBreakLine -or $OutputLine.Length -ge 40) {
579581
$OutputLine += " ^"
580582
Write-Output $OutputLine
581583
$OutputLine = " "
582584
}
583585

584-
$Arg = $Args[$i]
586+
$Arg = $ExecutableArgs[$i]
585587
if ($Arg.Contains(" ")) {
586588
$OutputLine += " `"$Arg`""
587589
} else {
@@ -594,32 +596,34 @@ function Invoke-Program() {
594596

595597
if ($OutNull) {
596598
$OutputLine += " > nul"
597-
} elseif ($OutFile) {
598-
$OutputLine += " > `"$OutFile`""
599-
}
600-
if ($ErrorFile) {
601-
$OutputLine += " 2> `"$ErrorFile`""
599+
} elseif ($Silent) {
600+
$OutputLine += " *> nul"
601+
} else {
602+
if ($OutFile) { $OutputLine += " > `"$OutFile`"" }
603+
if ($ErrorFile) { $OutputLine += " 2> `"$ErrorFile`"" }
602604
}
603605

604606
Write-Output $OutputLine
605607
} else {
606608
if ($OutNull) {
607-
& $Executable @Args | Out-Null
609+
& $Executable @ExecutableArgs | Out-Null
610+
} elseif ($Silent) {
611+
& $Executable @ExecutableArgs *> $null
608612
} elseif ($OutFile -and $ErrorFile) {
609-
& $Executable @Args > $OutFile 2> $ErrorFile
613+
& $Executable @ExecutableArgs > $OutFile 2> $ErrorFile
610614
} elseif ($OutFile) {
611-
& $Executable @Args > $OutFile
615+
& $Executable @ExecutableArgs > $OutFile
612616
} elseif ($ErrorFile) {
613-
& $Executable @Args 2> $ErrorFile
617+
& $Executable @ExecutableArgs 2> $ErrorFile
614618
} else {
615-
& $Executable @Args
619+
& $Executable @ExecutableArgs
616620
}
617621

618622
if ($LastExitCode -ne 0) {
619623
$ErrorMessage = "Error: $([IO.Path]::GetFileName($Executable)) exited with code $($LastExitCode).`n"
620624

621625
$ErrorMessage += "Invocation:`n"
622-
$ErrorMessage += " $Executable $Args`n"
626+
$ErrorMessage += " $Executable $ExecutableArgs`n"
623627

624628
$ErrorMessage += "Call stack:`n"
625629
foreach ($Frame in @(Get-PSCallStack)) {
@@ -827,7 +831,7 @@ function Fetch-Dependencies {
827831

828832
function Install-PythonWheel([string] $ModuleName, [string] $WheelFile, [string] $WheelURL, [string] $WheelHash) {
829833
try {
830-
Invoke-Program "$(Get-PythonExecutable)" -c "import $ModuleName" *> $null
834+
Invoke-Program -Silent "$(Get-PythonExecutable)" -c "import $ModuleName"
831835
} catch {
832836
DownloadAndVerify $WheelURL "$BinaryCache\python\$WheelFile" $WheelHash
833837
Write-Output "Installing '$WheelFile' ..."
@@ -838,7 +842,7 @@ function Fetch-Dependencies {
838842
function Install-PythonModules() {
839843
# First ensure pip is installed, else bootstrap it
840844
try {
841-
Invoke-Program "$(Get-PythonExecutable)" -m pip *> $null
845+
Invoke-Program -Silent "$(Get-PythonExecutable)" -m pip
842846
} catch {
843847
Write-Output "Installing pip ..."
844848
Invoke-Program -OutNull "$(Get-PythonExecutable)" '-I' -m ensurepip -U --default-pip

0 commit comments

Comments
 (0)