Skip to content

Improve output when using XCBuild #2726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Sources/XCBuildSupport/XCBuildDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ extension XCBuildDelegate: XCBuildOutputParserDelegate {
queue.async {
self.progressAnimation.clear()
self.outputStream <<< info.data
self.outputStream <<< "\n"
self.outputStream.flush()
}
case .buildDiagnostic(let info):
queue.async {
self.progressAnimation.clear()
self.outputStream <<< info.message
self.outputStream <<< "\n"
self.outputStream.flush()
}
case .buildOutput(let info):
queue.async {
self.progressAnimation.clear()
self.outputStream <<< info.data
self.outputStream <<< "\n"
self.outputStream.flush()
}
case .didUpdateProgress(let info):
Expand All @@ -66,8 +81,14 @@ extension XCBuildDelegate: XCBuildOutputParserDelegate {
}
case .buildCompleted(let info):
queue.async {
if info.result == .ok, self.didEmitProgressOutput {
self.progressAnimation.update(step: 100, total: 100, text: "Build succeeded")
switch info.result {
case .aborted, .cancelled, .failed:
self.outputStream <<< "Build \(info.result)\n"
self.outputStream.flush()
case .ok:
if self.didEmitProgressOutput {
self.progressAnimation.update(step: 100, total: 100, text: "Build succeeded")
}
}
}
default:
Expand Down
11 changes: 10 additions & 1 deletion Sources/XCBuildSupport/XCBuildOutputParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ public enum XCBuildMessage {
case ok
case failed
case cancelled
case aborted
}

public let result: Result
}

public struct BuildOutputInfo {
let data: String
}

public struct DidUpdateProgressInfo {
public let message: String
public let percentComplete: Double
Expand Down Expand Up @@ -101,6 +106,7 @@ public enum XCBuildMessage {
case buildStarted
case buildDiagnostic(BuildDiagnosticInfo)
case buildCompleted(BuildCompletedInfo)
case buildOutput(BuildOutputInfo)
case preparationComplete
case didUpdateProgress(DidUpdateProgressInfo)
case targetUpToDate(TargetUpToDateInfo)
Expand Down Expand Up @@ -187,6 +193,7 @@ extension XCBuildOutputParser: JSONMessageStreamingParserDelegate {
extension XCBuildMessage.BuildDiagnosticInfo: Decodable, Equatable {}
extension XCBuildMessage.BuildCompletedInfo.Result: Decodable, Equatable {}
extension XCBuildMessage.BuildCompletedInfo: Decodable, Equatable {}
extension XCBuildMessage.BuildOutputInfo: Decodable, Equatable {}
extension XCBuildMessage.TargetUpToDateInfo: Decodable, Equatable {}
extension XCBuildMessage.TaskDiagnosticInfo: Decodable, Equatable {}
extension XCBuildMessage.TargetDiagnosticInfo: Decodable, Equatable {}
Expand Down Expand Up @@ -322,6 +329,8 @@ extension XCBuildMessage: Decodable, Equatable {
self = try .buildDiagnostic(BuildDiagnosticInfo(from: decoder))
case "buildCompleted":
self = try .buildCompleted(BuildCompletedInfo(from: decoder))
case "buildOutput":
self = try .buildOutput(BuildOutputInfo(from: decoder))
case "preparationComplete":
self = .preparationComplete
case "didUpdateProgress":
Expand All @@ -345,7 +354,7 @@ extension XCBuildMessage: Decodable, Equatable {
case "targetDiagnostic":
self = try .targetDiagnostic(TargetDiagnosticInfo(from: decoder))
default:
throw DecodingError.dataCorruptedError(forKey: .kind, in: container, debugDescription: "invalid kind")
throw DecodingError.dataCorruptedError(forKey: .kind, in: container, debugDescription: "invalid kind \(kind)")
}
}
}