Skip to content
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

SwiftPM outputs raw diagnostics from SwiftDriver without trailing newlines [5968] #5987

Conversation

abertelrud
Copy link
Contributor

@abertelrud abertelrud commented Dec 21, 2022

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 swiftlang/swift-driver#1241 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.

Modifications:

  • add a newline after emitting the unparseable line of Swift Driver output
  • add a unit test

Result:

Raw output from the Swift Driver has trailing newlines.

rdar://103608636

@abertelrud abertelrud self-assigned this Dec 21, 2022
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud enabled auto-merge (squash) December 21, 2022 20:12
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud force-pushed the eng/103608636-missing-newline-after-swift-driver-diagnostics branch from 886c299 to 642ea4e Compare December 21, 2022 23:09
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

…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 swiftlang#5968.

I filed swiftlang#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 a newline to the raw driver output, since the logic that parses JSON splits by newlines, so we won't find any terminating newlines that shouldn't be on the string.

Note that we do not add newlines to the output coming from messages from the compiler frontend, since that output already has trailing newlines.  So in essence this change makes the `.unparsableOutput()` case the same as the cases of regular output, from a newline perspective.

rdar://103608636
@abertelrud abertelrud force-pushed the eng/103608636-missing-newline-after-swift-driver-diagnostics branch from 642ea4e to d265d90 Compare December 22, 2022 01:43
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud merged commit 14d05cc into swiftlang:main Dec 22, 2022
abertelrud added a commit to abertelrud/swift-package-manager that referenced this pull request Dec 22, 2022
…ng newlines (swiftlang#5987)

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 swiftlang#5968.

I filed swiftlang/swift-driver#1241 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
(cherry picked from commit 14d05cc)
@abertelrud abertelrud deleted the eng/103608636-missing-newline-after-swift-driver-diagnostics branch December 22, 2022 18:59
abertelrud added a commit that referenced this pull request Jan 3, 2023
…ng newlines (#5987) (#5996)

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 swiftlang/swift-driver#1241 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
(cherry picked from commit 14d05cc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants