diff options
author | Jakob Odersky <jakob@driver.xyz> | 2018-09-21 11:50:52 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@driver.xyz> | 2018-09-21 11:50:52 -0700 |
commit | 7002cd940434120f73385d322a28d54c994d0955 (patch) | |
tree | e882f68da5a525556ebb90c030bf90fae6c7e21f | |
parent | 3f5422eb715c214a0043c9ea0dc0db593b2f13f5 (diff) | |
download | sbt-settings-7002cd940434120f73385d322a28d54c994d0955.tar.gz sbt-settings-7002cd940434120f73385d322a28d54c994d0955.tar.bz2 sbt-settings-7002cd940434120f73385d322a28d54c994d0955.zip |
Mark fatal warnings as suchv1.0.16
-rw-r--r-- | src/main/scala/xyz.driver.sbt/SbtSettings.scala | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/main/scala/xyz.driver.sbt/SbtSettings.scala b/src/main/scala/xyz.driver.sbt/SbtSettings.scala index dc336b6..311e976 100644 --- a/src/main/scala/xyz.driver.sbt/SbtSettings.scala +++ b/src/main/scala/xyz.driver.sbt/SbtSettings.scala @@ -91,18 +91,34 @@ object SbtSettings extends AutoPlugin { "-Ywarn-unused:_,-explicits,-implicits" ) }, + // Currently, scalac does not provide a way to fine-tune the treating of + // warnings as errors. Either all are considered errors + // (with -Xfatal-warnings), or none are. This hack analyzes the compiler's + // output and treats all warnings as errors, except for deprecations. compile in Compile := { + val log = streams.value.log val compiled = (compile in Compile).value val problems = compiled.readSourceInfos().getAllSourceInfos.asScala.flatMap { - case (_, info) => - info.getReportedProblems + case (_, info) => info.getReportedProblems } - - val deprecationsOnly = problems.forall { problem => - problem.message().contains("is deprecated") + var deprecationsOnly = true + problems.foreach { + problem => + if (!problem.message().contains("is deprecated")) { + deprecationsOnly = false + val pos = problem.position + val file = pos.sourcePath.asScala.getOrElse("?") + val line = pos.line.asScala.map(_.toString).getOrElse("?") + val col = pos.pointer.asScala.map(_.toString).getOrElse("?") + val msg = problem.message + val desc = pos.lineContent() + "\n" + pos.pointerSpace.asScala + .getOrElse("") + "^" + log.error(s"[fatal warning] $file:$line:$col $msg\n$desc") + } + } + if (!deprecationsOnly) { + throw new MessageOnlyException("Fatal warnings: some warnings other than deprecations were found.") } - - if (!deprecationsOnly) sys.error("Fatal warnings: some warnings other than deprecations were found.") compiled } ) |