@@ -577,6 +577,7 @@ function Invoke-Program() {
577
577
[string ] $Executable ,
578
578
[switch ] $OutNull = $false ,
579
579
[string ] $OutFile = " " ,
580
+ [string ] $ErrorFile = " " ,
580
581
[Parameter (Position = 1 , ValueFromRemainingArguments )]
581
582
[string []] $Args
582
583
)
@@ -605,16 +606,23 @@ function Invoke-Program() {
605
606
606
607
if ($OutNull ) {
607
608
$OutputLine += " > nul"
608
- } elseif (" " -ne $OutFile ) {
609
+ } elseif ($OutFile ) {
609
610
$OutputLine += " > `" $OutFile `" "
610
611
}
612
+ if ($ErrorFile ) {
613
+ $OutputLine += " 2> `" $ErrorFile `" "
614
+ }
611
615
612
616
Write-Output $OutputLine
613
617
} else {
614
618
if ($OutNull ) {
615
619
& $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
618
626
} else {
619
627
& $Executable @Args
620
628
}
@@ -1822,9 +1830,17 @@ function Build-mimalloc() {
1822
1830
foreach ($Tool in $Tools ) {
1823
1831
$Binary = [IO.Path ]::Combine($Arch.ToolchainInstallRoot , " usr" , " bin" , $Tool )
1824
1832
# 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 "
1826
1834
# 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
+ }
1828
1844
}
1829
1845
}
1830
1846
0 commit comments