Skip to content

Commit

Permalink
SwiftPM outputs raw diagnostics from SwiftDriver without trailing new…
Browse files Browse the repository at this point in the history
…lines

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
  • Loading branch information
abertelrud committed Dec 21, 2022
1 parent 754a55f commit c93d9a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
self.progressAnimation.clear()
}

self.outputStream <<< output
self.outputStream <<< output <<< "\n"
self.outputStream.flush()

// next we want to try and scoop out any errors from the output (if reasonable size, otherwise this will be very slow),
Expand Down
9 changes: 9 additions & 0 deletions Tests/CommandsTests/BuildToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,13 @@ final class BuildToolTests: CommandsTestCase {
XCTAssertMatch(output, .prefix("digraph Jobs {"))
}
}

func testSwiftDriverRawOutputGetsNewlines() throws {
try fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
// 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.
let result = try execute(["-c", "release", "-Xswiftc", "-wmo"], packagePath: fixturePath)
XCTAssertMatch(result.stdout, .contains("optimization\n["))
XCTAssertNoMatch(result.stdout, .contains("optimization["))
}
}
}

0 comments on commit c93d9a0

Please sign in to comment.