Skip to content

Commit af21cea

Browse files
committed
Use stream instead of collect
1 parent 8696925 commit af21cea

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Sources/XCBuildSupport/XcodeBuildSystem.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,17 @@ public final class XcodeBuildSystem: SPMBuildCore.BuildSystem {
103103

104104
arguments += buildParameters.xcbuildFlags
105105

106-
let process = Process(arguments: arguments, outputRedirection: .collect)
106+
let delegate = createBuildDelegate()
107+
var hasStdout = false
108+
var stderrBuffer: [UInt8] = []
109+
let redirection: Process.OutputRedirection = .stream(stdout: { bytes in
110+
hasStdout = hasStdout || !bytes.isEmpty
111+
delegate.parse(bytes: bytes)
112+
}, stderr: { bytes in
113+
stderrBuffer.append(contentsOf: bytes)
114+
})
115+
116+
let process = Process(arguments: arguments, outputRedirection: redirection)
107117
try process.launch()
108118
let result = try process.waitUntilExit()
109119

@@ -115,14 +125,9 @@ public final class XcodeBuildSystem: SPMBuildCore.BuildSystem {
115125
throw Diagnostics.fatalError
116126
}
117127

118-
let stdout = try result.output.get()
119-
if !stdout.isEmpty {
120-
let delegate = createBuildDelegate()
121-
delegate.parse(bytes: stdout)
122-
} else {
123-
let stderr = try result.utf8stderrOutput()
124-
if !stderr.isEmpty {
125-
diagnostics.emit(StringError(stderr))
128+
if !hasStdout {
129+
if !stderrBuffer.isEmpty {
130+
diagnostics.emit(StringError(String(decoding: stderrBuffer, as: UTF8.self)))
126131
} else {
127132
diagnostics.emit(StringError("Unknown error: stdout and stderr are empty"))
128133
}

0 commit comments

Comments
 (0)