Skip to content

Commit aa9ea35

Browse files
authored
Parse XCbuild stderr only if stdout is empty (#3584)
* Parse stderr from XCBuild only if stdout is empty * cleanup * Use stream instead of collect * format
1 parent ae1cb55 commit aa9ea35

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Sources/XCBuildSupport/XcodeBuildSystem.swift

+15-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,13 @@ public final class XcodeBuildSystem: SPMBuildCore.BuildSystem {
104104
arguments += buildParameters.xcbuildFlags
105105

106106
let delegate = createBuildDelegate()
107-
let redirection: Process.OutputRedirection = .stream(stdout: delegate.parse(bytes:), stderr: { bytes in
108-
self.diagnostics.emit(StringError(String(bytes: bytes, encoding: .utf8)!))
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)
109114
})
110115

111116
let process = Process(arguments: arguments, outputRedirection: redirection)
@@ -119,6 +124,14 @@ public final class XcodeBuildSystem: SPMBuildCore.BuildSystem {
119124
guard result.exitStatus == .terminated(code: 0) else {
120125
throw Diagnostics.fatalError
121126
}
127+
128+
if !hasStdout {
129+
if !stderrBuffer.isEmpty {
130+
diagnostics.emit(StringError(String(decoding: stderrBuffer, as: UTF8.self)))
131+
} else {
132+
diagnostics.emit(StringError("Unknown error: stdout and stderr are empty"))
133+
}
134+
}
122135
}
123136

124137
func createBuildParametersFile() throws -> AbsolutePath? {

0 commit comments

Comments
 (0)