@@ -557,6 +557,7 @@ function Invoke-Program() {
557557 [string ] $Executable ,
558558 [switch ] $OutNull = $false ,
559559 [string ] $OutFile = " " ,
560+ [string ] $ErrorFile = " " ,
560561 [Parameter (Position = 1 , ValueFromRemainingArguments )]
561562 [string []] $Args
562563 )
@@ -585,16 +586,23 @@ function Invoke-Program() {
585586
586587 if ($OutNull ) {
587588 $OutputLine += " > nul"
588- } elseif (" " -ne $OutFile ) {
589+ } elseif ($OutFile ) {
589590 $OutputLine += " > `" $OutFile `" "
590591 }
592+ if ($ErrorFile ) {
593+ $OutputLine += " 2> `" $ErrorFile `" "
594+ }
591595
592596 Write-Output $OutputLine
593597 } else {
594598 if ($OutNull ) {
595599 & $Executable @Args | Out-Null
596- } elseif (" " -ne $OutFile ) {
597- & $Executable @Args | Out-File - Encoding UTF8 $OutFile
600+ } elseif ($OutFile -and $ErrorFile ) {
601+ & $Executable @Args > $OutFile 2> $ErrorFile
602+ } elseif ($OutFile ) {
603+ & $Executable @Args > $OutFile
604+ } elseif ($ErrorFile ) {
605+ & $Executable @Args 2> $ErrorFile
598606 } else {
599607 & $Executable @Args
600608 }
@@ -1811,9 +1819,17 @@ function Build-mimalloc() {
18111819 foreach ($Tool in $Tools ) {
18121820 $Binary = [IO.Path ]::Combine($Arch.ToolchainInstallRoot , " usr" , " bin" , $Tool )
18131821 # Binary-patch in place
1814- Start-Process - Wait - WindowStyle Hidden - FilePath " $SourceCache \mimalloc\bin\minject$BuildSuffix " - ArgumentList @ ( " -f" , " -i" , " -v" , " $Binary " )
1822+ Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -f" " -i" " -v" " $Binary "
18151823 # Log the import table
1816- Start-Process - Wait - WindowStyle Hidden - FilePath " $SourceCache \mimalloc\bin\minject$BuildSuffix " - ArgumentList @ (" -l" , " $Binary " )
1824+ $LogFile = " $BinaryCache \$ ( $Arch.LLVMTarget ) \mimalloc\minject-log-$Tool .txt"
1825+ $ErrorFile = " $BinaryCache \$ ( $Arch.LLVMTarget ) \mimalloc\minject-log-$Tool -error.txt"
1826+ Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -l" " $Binary " - OutFile $LogFile - ErrorFile $ErrorFile
1827+ # Verify patching
1828+ $Found = Select-String - Path $LogFile - Pattern " mimalloc"
1829+ if (-not $Found ) {
1830+ Get-Content $ErrorFile
1831+ throw " Failed to patch mimalloc for $Tool "
1832+ }
18171833 }
18181834}
18191835
0 commit comments