Skip to content

Commit aa69e48

Browse files
authored
fix getNetCoreAppReferences output leaking (#18928)
1 parent ced09df commit aa69e48

File tree

5 files changed

+17
-59
lines changed

5 files changed

+17
-59
lines changed

tests/FSharp.Test.Utilities/CompilerAssert.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,6 @@ module CompilerAssertHelpers =
627627
File.WriteAllText(runtimeconfigPath, runtimeconfig)
628628
#endif
629629
let rc, output, errors = Commands.executeProcess fileName arguments (Path.GetDirectoryName(outputFilePath))
630-
let output = String.Join(Environment.NewLine, output)
631-
let errors = String.Join(Environment.NewLine, errors)
632630
ExitCode rc, output, errors
633631

634632
open CompilerAssertHelpers

tests/FSharp.Test.Utilities/ILChecker.fs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ module ILChecker =
1515

1616
let private exec exe args =
1717
let arguments = args |> String.concat " "
18-
let exitCode, _output, errors = Commands.executeProcess exe arguments ""
19-
let errors = errors |> String.concat Environment.NewLine
20-
errors, exitCode
18+
Commands.executeProcess exe arguments ""
2119

2220
/// Filters i.e ['The system type \'System.ReadOnlySpan`1\' was required but no referenced system DLL contained this type']
2321
let private filterSpecialComment (text: string) =
@@ -101,7 +99,7 @@ module ILChecker =
10199

102100
let ildasmFullArgs = [ dllFilePath; $"-out=%s{ilFilePath}"; yield! ildasmArgs ]
103101

104-
let stdErr, exitCode =
102+
let exitCode, _, stdErr =
105103
let ildasmCommandPath = Path.ChangeExtension(dllFilePath, ".ildasmCommandPath")
106104
File.WriteAllLines(ildasmCommandPath, [| $"{ildasmPath} {ildasmFullArgs}" |] )
107105
exec ildasmPath ildasmFullArgs
@@ -212,5 +210,5 @@ module ILChecker =
212210

213211
let reassembleIL ilFilePath dllFilePath =
214212
let ilasmPath = config.ILASM
215-
let errors, _ = exec ilasmPath [ $"%s{ilFilePath} /output=%s{dllFilePath} /dll" ]
213+
let _, _, errors = exec ilasmPath [ $"%s{ilFilePath} /output=%s{dllFilePath} /dll" ]
216214
errors

tests/FSharp.Test.Utilities/ILVerifierModule.fs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ module ILVerifierModule =
2323

2424
let private exec (dotnetExe: string) args workingDirectory =
2525
let arguments = args |> String.concat " "
26-
let exitCode, _output, errors = Commands.executeProcess dotnetExe arguments workingDirectory
27-
let errors = errors |> String.concat Environment.NewLine
28-
errors, exitCode
26+
Commands.executeProcess dotnetExe arguments workingDirectory
2927

3028
let private verifyPEFileCore peverifierArgs (dllFilePath: string) =
3129
let nuget_packages =
@@ -36,17 +34,13 @@ module ILVerifierModule =
3634
| path -> path
3735
let peverifyFullArgs = [ yield "exec"; yield $"""{nuget_packages}/dotnet-ilverify/9.0.0/tools/net9.0/any/ILVerify.dll"""; yield "--verbose"; yield dllFilePath; yield! peverifierArgs ]
3836
let workingDirectory = Path.GetDirectoryName dllFilePath
39-
let _, exitCode =
37+
let exitCode, outputText, errorText =
4038
let peverifierCommandPath = Path.ChangeExtension(dllFilePath, ".peverifierCommandPath.cmd")
4139
let args = peverifyFullArgs |> Seq.fold(fun a acc -> $"{a} " + acc) ""
4240
File.WriteAllLines(peverifierCommandPath, [| $"{args}" |] )
4341
File.Copy(typeof<RequireQualifiedAccessAttribute>.Assembly.Location, Path.GetDirectoryName(dllFilePath) ++ "FSharp.Core.dll", true)
4442
exec config.DotNetExe peverifyFullArgs workingDirectory
4543

46-
// Grab output
47-
let outputText = File.ReadAllText(Path.Combine(workingDirectory, "StandardOutput.txt"))
48-
let errorText = File.ReadAllText(Path.Combine(workingDirectory, "StandardError.txt"))
49-
5044
match exitCode with
5145
| 0 -> {Outcome = NoExitCode; StdOut = outputText; StdErr = errorText }
5246
| _ -> {Outcome = ExitCode exitCode; StdOut = outputText; StdErr = errorText }

tests/FSharp.Test.Utilities/TestFramework.fs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,6 @@ module Commands =
6565
// returns exit code, stdio and stderr as string arrays
6666
let executeProcess pathToExe arguments workingDir =
6767
let commandLine = ResizeArray()
68-
let errorsList = ResizeArray()
69-
let outputList = ResizeArray()
70-
let errorslock = obj()
71-
let outputlock = obj()
72-
let outputDataReceived (message: string) =
73-
if not (isNull message) then
74-
lock outputlock (fun () ->
75-
printfn "%s" message
76-
outputList.Add(message))
77-
78-
let errorDataReceived (message: string) =
79-
if not (isNull message) then
80-
lock errorslock (fun () ->
81-
eprintfn "%s" message
82-
errorsList.Add(message))
8368

8469
commandLine.Add $"cd {workingDir}"
8570
commandLine.Add $"{pathToExe} {arguments} /bl"
@@ -103,29 +88,14 @@ module Commands =
10388
use p = new Process()
10489
p.StartInfo <- psi
10590

106-
p.OutputDataReceived.Add(fun a -> outputDataReceived a.Data)
107-
p.ErrorDataReceived.Add(fun a -> errorDataReceived a.Data)
108-
109-
if p.Start() then
110-
p.BeginOutputReadLine()
111-
p.BeginErrorReadLine()
112-
p.WaitForExit()
113-
114-
let workingDir' =
115-
if workingDir = ""
116-
then
117-
// Assign working dir to prevent default to C:\Windows\System32
118-
let executionLocation = Assembly.GetExecutingAssembly().Location
119-
Path.GetDirectoryName executionLocation
120-
else
121-
workingDir
122-
123-
lock gate (fun () ->
124-
File.WriteAllLines(Path.Combine(workingDir', "commandline.txt"), commandLine)
125-
File.WriteAllLines(Path.Combine(workingDir', "StandardOutput.txt"), outputList)
126-
File.WriteAllLines(Path.Combine(workingDir', "StandardError.txt"), errorsList)
127-
)
128-
p.ExitCode, outputList.ToArray(), errorsList.ToArray()
91+
if not (p.Start()) then failwith "new process did not start"
92+
93+
let readOutput = backgroundTask { return! p.StandardOutput.ReadToEndAsync() }
94+
let readErrors = backgroundTask { return! p.StandardError.ReadToEndAsync() }
95+
96+
p.WaitForExit()
97+
98+
p.ExitCode, readOutput.Result, readErrors.Result
12999

130100
let getfullpath workDir (path:string) =
131101
let rooted =

tests/FSharp.Test.Utilities/Utilities.fs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ open System
165165
let main argv = 0"""
166166

167167
let private getNetCoreAppReferences =
168-
let mutable output = [||]
169-
let mutable errors = [||]
168+
let mutable output = ""
169+
let mutable errors = ""
170170
let mutable cleanUp = true
171171
let pathToArtifacts = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "../../../.."))
172172
if Path.GetFileName(pathToArtifacts) <> "artifacts" then failwith "CompilerAssert did not find artifacts directory --- has the location changed????"
@@ -196,17 +196,15 @@ let main argv = 0"""
196196
errors <- dotneterrors
197197
output <- dotnetoutput
198198
printfn "Output:\n=======\n"
199-
output |> Seq.iter(fun line -> printfn "STDOUT:%s\n" line)
199+
printfn "%s" dotnetoutput
200200
printfn "Errors:\n=======\n"
201-
errors |> Seq.iter(fun line -> printfn "STDERR:%s\n" line)
201+
printfn "%s" dotneterrors
202202
Assert.True(false, "Errors produced generating References")
203203

204204
File.ReadLines(frameworkReferencesFileName) |> Seq.toArray
205205
with | e ->
206206
cleanUp <- false
207207
let message =
208-
let output = output |> String.concat "\nSTDOUT: "
209-
let errors = errors |> String.concat "\nSTDERR: "
210208
File.WriteAllText(Path.Combine(projectDirectory, "project.stdout"), output)
211209
File.WriteAllText(Path.Combine(projectDirectory, "project.stderror"), errors)
212210
$"""

0 commit comments

Comments
 (0)