Skip to content

Commit c93d9a0

Browse files
committed
SwiftPM outputs raw diagnostics from SwiftDriver without trailing newlines
SwiftPM uses the Swift Driver's `-parseable-output` flag to get a sequence of length-prefixed JSON-encoded messages that it can read. Unfortunately the Swift Driver doesn't JSON-encode its own diagnostics, leading to things like #5968. I filed #5968 on the Swift Driver to get it to encode its JSON messages, but meanwhile, it turns out that we can fairly easily fix the fallback logic that SwiftPM uses when it emits raw output. It was simply missing a newline. It's safe to always add one, since the logic that parses JSON splits by newlines, so we won't find any terminating newlines. rdar://103608636
1 parent 754a55f commit c93d9a0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Sources/Build/BuildOperationBuildSystemDelegateHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
773773
self.progressAnimation.clear()
774774
}
775775

776-
self.outputStream <<< output
776+
self.outputStream <<< output <<< "\n"
777777
self.outputStream.flush()
778778

779779
// next we want to try and scoop out any errors from the output (if reasonable size, otherwise this will be very slow),

Tests/CommandsTests/BuildToolTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,4 +390,13 @@ final class BuildToolTests: CommandsTestCase {
390390
XCTAssertMatch(output, .prefix("digraph Jobs {"))
391391
}
392392
}
393+
394+
func testSwiftDriverRawOutputGetsNewlines() throws {
395+
try fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
396+
// Building with `-wmo` should result in a `remark: Incremental compilation has been disabled: it is not compatible with whole module optimization` message, which should have a trailing newline.
397+
let result = try execute(["-c", "release", "-Xswiftc", "-wmo"], packagePath: fixturePath)
398+
XCTAssertMatch(result.stdout, .contains("optimization\n["))
399+
XCTAssertNoMatch(result.stdout, .contains("optimization["))
400+
}
401+
}
393402
}

0 commit comments

Comments
 (0)