@@ -557,6 +557,7 @@ function Invoke-Program() {
557
557
[string ] $Executable ,
558
558
[switch ] $OutNull = $false ,
559
559
[string ] $OutFile = " " ,
560
+ [string ] $ErrorFile = " " ,
560
561
[Parameter (Position = 1 , ValueFromRemainingArguments )]
561
562
[string []] $Args
562
563
)
@@ -585,16 +586,23 @@ function Invoke-Program() {
585
586
586
587
if ($OutNull ) {
587
588
$OutputLine += " > nul"
588
- } elseif (" " -ne $OutFile ) {
589
+ } elseif ($OutFile ) {
589
590
$OutputLine += " > `" $OutFile `" "
590
591
}
592
+ if ($ErrorFile ) {
593
+ $OutputLine += " 2> `" $ErrorFile `" "
594
+ }
591
595
592
596
Write-Output $OutputLine
593
597
} else {
594
598
if ($OutNull ) {
595
599
& $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
598
606
} else {
599
607
& $Executable @Args
600
608
}
@@ -1811,9 +1819,17 @@ function Build-mimalloc() {
1811
1819
foreach ($Tool in $Tools ) {
1812
1820
$Binary = [IO.Path ]::Combine($Arch.ToolchainInstallRoot , " usr" , " bin" , $Tool )
1813
1821
# 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 "
1815
1823
# 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
+ }
1817
1833
}
1818
1834
}
1819
1835
0 commit comments