@@ -577,6 +577,7 @@ function Invoke-Program() {
577577 [string ] $Executable ,
578578 [switch ] $OutNull = $false ,
579579 [string ] $OutFile = " " ,
580+ [string ] $ErrorFile = " " ,
580581 [Parameter (Position = 1 , ValueFromRemainingArguments )]
581582 [string []] $Args
582583 )
@@ -605,16 +606,23 @@ function Invoke-Program() {
605606
606607 if ($OutNull ) {
607608 $OutputLine += " > nul"
608- } elseif (" " -ne $OutFile ) {
609+ } elseif ($OutFile ) {
609610 $OutputLine += " > `" $OutFile `" "
610611 }
612+ if ($ErrorFile ) {
613+ $OutputLine += " 2> `" $ErrorFile `" "
614+ }
611615
612616 Write-Output $OutputLine
613617 } else {
614618 if ($OutNull ) {
615619 & $Executable @Args | Out-Null
616- } elseif (" " -ne $OutFile ) {
617- & $Executable @Args | Out-File - Encoding UTF8 $OutFile
620+ } elseif ($OutFile -and $ErrorFile ) {
621+ & $Executable @Args > $OutFile 2> $ErrorFile
622+ } elseif ($OutFile ) {
623+ & $Executable @Args > $OutFile
624+ } elseif ($ErrorFile ) {
625+ & $Executable @Args 2> $ErrorFile
618626 } else {
619627 & $Executable @Args
620628 }
@@ -1822,9 +1830,17 @@ function Build-mimalloc() {
18221830 foreach ($Tool in $Tools ) {
18231831 $Binary = [IO.Path ]::Combine($Arch.ToolchainInstallRoot , " usr" , " bin" , $Tool )
18241832 # Binary-patch in place
1825- Start-Process - Wait - WindowStyle Hidden - FilePath " $SourceCache \mimalloc\bin\minject$BuildSuffix " - ArgumentList @ ( " -f" , " -i" , " -v" , " $Binary " )
1833+ Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -f" " -i" " -v" " $Binary "
18261834 # Log the import table
1827- Start-Process - Wait - WindowStyle Hidden - FilePath " $SourceCache \mimalloc\bin\minject$BuildSuffix " - ArgumentList @ (" -l" , " $Binary " )
1835+ $LogFile = " $BinaryCache \$ ( $Arch.LLVMTarget ) \mimalloc\minject-log-$Tool .txt"
1836+ $ErrorFile = " $BinaryCache \$ ( $Arch.LLVMTarget ) \mimalloc\minject-log-$Tool -error.txt"
1837+ Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -l" " $Binary " - OutFile $LogFile - ErrorFile $ErrorFile
1838+ # Verify patching
1839+ $Found = Select-String - Path $LogFile - Pattern " mimalloc"
1840+ if (-not $Found ) {
1841+ Get-Content $ErrorFile
1842+ throw " Failed to patch mimalloc for $Tool "
1843+ }
18281844 }
18291845}
18301846
0 commit comments