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

log scalafix --check diffs as errors via a sbt logger #106

Merged
merged 3 commits into from
May 25, 2020

Conversation

bjaglin
Copy link
Collaborator

@bjaglin bjaglin commented May 19, 2020

Diffs were dumped on stdout. When scalafix is run in parallel with many other tasks across multiple sub-projects, this makes it much easier to find out which files are the culprits and why, as the logs stand out and are available via sbt last scalafix.

Lint errors are already logged properly via https://github.com/scalacenter/sbt-scalafix/blob/v0.9.15-2/src/main/scala/scalafix/internal/sbt/ScalafixLogger.scala (and are not dumped to the printStream as far as I can tell, so we don't get duplicates).

import sbt.{Level, Logger}

/** Split an OutputStream into messages and feed them to a given logger at a specified level. Not thread-safe. */
class LoggingOutputStream(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly, I couldn't find any helper class in sbt... The best I found was https://github.com/sbt/util/blob/d31b9c509384ecaf37f2ffaec8731250e3c60532/internal/util-logging/src/main/scala/sbt/internal/util/LoggerWriter.scala, which is internal and doesn't match the types we need in that case.

@@ -140,6 +141,8 @@ object ScalafixPlugin extends AutoPlugin {
loadedRules = () => scalafixArgs().availableRules().asScala,
terminalWidth = Some(JLineAccess.terminalWidth)
).parser.parsed
val errorLogger =
new PrintStream(LoggingOutputStream(streams.value.log, Level.Error))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about deferring the logging until the point we know the status code, to adjust the level accordingly, but looking at the usage of that printStream, I think it's reasonnable to always log as error, except maybe for --stdout, but that's a lot of custom code for something that I don't see being used through sbt

Comment on lines 32 to 33
val taskStreams = (example / Compile / scalafix / streams).value
val reader = taskStreams.readText(taskStreams.key)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lastLogFile used in a few scripted did not work as it seems that the except failure just before this gets called flush out the output... In the end, this looks more readable IMHO.

@bjaglin bjaglin force-pushed the sbt-logger branch 3 times, most recently from 5cc3df3 to 7ed121c Compare May 19, 2020 14:36
@bjaglin
Copy link
Collaborator Author

bjaglin commented May 19, 2020

The scala 2.10 / sbt 0.13.x build has been failing a few times because of network issues, such as

2020-05-19T14:39:40.3511999Z [error] https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.dwijnand/sbt-dynver/scala_2.12/sbt_1.0/4.0.0/jars/sbt-dynver.jar: download error: Caught java.io.IOException: Server returned HTTP response code: 504 for URL: https://dl.bintray.com/sbt/sbt-plugin-releases/com.dwijnand/sbt-dynver/scala_2.12/sbt_1.0/4.0.0/jars/sbt-dynver.jar (Server returned HTTP response code: 504 for URL: https://dl.bintray.com/sbt/sbt-plugin-releases/com.dwijnand/sbt-dynver/scala_2.12/sbt_1.0/4.0.0/jars/sbt-dynver.jar) while downloading https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.dwijnand/sbt-dynver/scala_2.12/sbt_1.0/4.0.0/jars/sbt-dynver.jar
2020-05-19T14:39:40.5602727Z Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? 

I'll retry later.

Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution! This looks great, no objections from me 👍

Re the 0.13.x failure. I would be OK with dropping sbt 0.13.x support. Most of the sbt plugin ecosystem has moved on from 0.13 and the users on 0.13 can continue to use older sbt-scalafix versions.

@bjaglin
Copy link
Collaborator Author

bjaglin commented May 19, 2020

Re the 0.13.x failure. I would be OK with dropping sbt 0.13.x support. Most of the sbt plugin ecosystem has moved on from 0.13 and the users on 0.13 can continue to use older sbt-scalafix versions.

In that case it's just a transient infrastructure issue (bintray? I have seen it today on other scripted tests from other projects), but it did take quite a lot of effort to support 0.13.x in #102. Now that it's done, we might as well continue for a while, and revisit the decision next time it's a hassle I guess.

Diffs were dumped on stdout. When scalafix is run in parallel
with many other tasks across multiple sub-projects, this makes it
much easier to find out which files are the culprits and why, as the
logs stand out and are available via `sbt last scalafix`
@bjaglin
Copy link
Collaborator Author

bjaglin commented May 20, 2020

Rebased against #100 & #102. Since it was not trivial I added a preliminary commit.

@olafurpg
Copy link
Contributor

In that case it's just a transient infrastructure issue (bintray? I have seen it today on other scripted tests from other projects), but it did take quite a lot of effort to support 0.13.x in #102. Now that it's done, we might as well continue for a while, and revisit the decision next time it's a hassle I guess.

Sounds good 👍

@bjaglin
Copy link
Collaborator Author

bjaglin commented May 20, 2020

The infra failure was actually hiding flakiness in the new test case (due to the test protocol, not the implementation), particularly on sbt 0.13.x & windows, but with 13efb64 it's finally green.

@bjaglin bjaglin requested a review from olafurpg May 20, 2020 10:05
@bjaglin bjaglin marked this pull request as ready for review May 20, 2020 10:06
@bjaglin
Copy link
Collaborator Author

bjaglin commented May 24, 2020

@olafurpg should I go ahead and merge this then? I am wondering if I may, but other PRs also look like easy merges. I am willing to help out maintaining this repo in the foreseeable future.

Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@bjaglin bjaglin merged commit aaf9543 into scalacenter:master May 25, 2020
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