diff --git a/utils/build.ps1 b/utils/build.ps1 index bbeb1d2826d47..adb0f4867379c 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -557,6 +557,7 @@ function Invoke-Program() { [string] $Executable, [switch] $OutNull = $false, [string] $OutFile = "", + [string] $ErrorFile = "", [Parameter(Position = 1, ValueFromRemainingArguments)] [string[]] $Args ) @@ -585,16 +586,23 @@ function Invoke-Program() { if ($OutNull) { $OutputLine += " > nul" - } elseif ("" -ne $OutFile) { + } elseif ($OutFile) { $OutputLine += " > `"$OutFile`"" } + if ($ErrorFile) { + $OutputLine += " 2> `"$ErrorFile`"" + } Write-Output $OutputLine } else { if ($OutNull) { & $Executable @Args | Out-Null - } elseif ("" -ne $OutFile) { - & $Executable @Args | Out-File -Encoding UTF8 $OutFile + } elseif ($OutFile -and $ErrorFile) { + & $Executable @Args > $OutFile 2> $ErrorFile + } elseif ($OutFile) { + & $Executable @Args > $OutFile + } elseif ($ErrorFile) { + & $Executable @Args 2> $ErrorFile } else { & $Executable @Args } @@ -1811,9 +1819,17 @@ function Build-mimalloc() { foreach ($Tool in $Tools) { $Binary = [IO.Path]::Combine($Arch.ToolchainInstallRoot, "usr", "bin", $Tool) # Binary-patch in place - Start-Process -Wait -WindowStyle Hidden -FilePath "$SourceCache\mimalloc\bin\minject$BuildSuffix" -ArgumentList @("-f", "-i", "-v", "$Binary") + Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-f" "-i" "-v" "$Binary" # Log the import table - Start-Process -Wait -WindowStyle Hidden -FilePath "$SourceCache\mimalloc\bin\minject$BuildSuffix" -ArgumentList @("-l", "$Binary") + $LogFile = "$BinaryCache\$($Arch.LLVMTarget)\mimalloc\minject-log-$Tool.txt" + $ErrorFile = "$BinaryCache\$($Arch.LLVMTarget)\mimalloc\minject-log-$Tool-error.txt" + Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-l" "$Binary" -OutFile $LogFile -ErrorFile $ErrorFile + # Verify patching + $Found = Select-String -Path $LogFile -Pattern "mimalloc" + if (-not $Found) { + Get-Content $ErrorFile + throw "Failed to patch mimalloc for $Tool" + } } }