-
Notifications
You must be signed in to change notification settings - Fork 1.1k
sbt bridge reporter #1530
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
sbt bridge reporter #1530
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
trait A | ||
trait B | ||
|
||
trait Wr { | ||
val z: A with B | ||
} | ||
|
||
object Er { | ||
val a = er1 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Reporter.checkSettings |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import sbt._ | ||
import Keys._ | ||
|
||
object DottyInjectedPlugin extends AutoPlugin { | ||
override def requires = plugins.JvmPlugin | ||
override def trigger = allRequirements | ||
|
||
override val projectSettings = Seq( | ||
scalaVersion := "0.1-SNAPSHOT", | ||
scalaOrganization := "ch.epfl.lamp", | ||
scalacOptions += "-language:Scala2", | ||
scalaBinaryVersion := "2.11", | ||
autoScalaLibrary := false, | ||
libraryDependencies ++= Seq("org.scala-lang" % "scala-library" % "2.11.5"), | ||
scalaCompilerBridgeSource := ("ch.epfl.lamp" % "dotty-bridge" % "0.1.1-SNAPSHOT" % "component").sources() | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import sbt._ | ||
import Keys._ | ||
import KeyRanks.DTask | ||
|
||
object Reporter { | ||
import xsbti.{Reporter, Problem, Position, Severity, Maybe} | ||
|
||
lazy val check = TaskKey[Unit]("check", "make sure compilation info are forwared to sbt") | ||
|
||
// compilerReporter is marked private in sbt | ||
lazy val compilerReporter = TaskKey[Option[xsbti.Reporter]]("compilerReporter", "Experimental hook to listen (or send) compilation failure messages.", DTask) | ||
|
||
lazy val reporter = | ||
Some(new xsbti.Reporter { | ||
private val buffer = collection.mutable.ArrayBuffer.empty[Problem] | ||
def reset(): Unit = buffer.clear() | ||
def hasErrors: Boolean = buffer.exists(_.severity == Severity.Error) | ||
def hasWarnings: Boolean = buffer.exists(_.severity == Severity.Warn) | ||
def printSummary(): Unit = println(problems.mkString(System.lineSeparator)) | ||
def problems: Array[Problem] = buffer.toArray | ||
def log(pos: Position, msg: String, sev: Severity): Unit = { | ||
object MyProblem extends Problem { | ||
def category: String = null | ||
def severity: Severity = sev | ||
def message: String = msg | ||
def position: Position = pos | ||
override def toString = s"custom: $position:$severity: $message" | ||
} | ||
buffer.append(MyProblem) | ||
} | ||
def comment(pos: xsbti.Position, msg: String): Unit = () | ||
}) | ||
|
||
lazy val checkSettings = Seq( | ||
compilerReporter in (Compile, compile) := reporter, | ||
check <<= (compile in Compile).mapFailure( _ => { | ||
val problems = reporter.get.problems | ||
println(problems.toList) | ||
assert(problems.size == 3) | ||
assert(problems.count(_.severity == Severity.Error) == 1) // not found: er1, | ||
assert(problems.count(_.severity == Severity.Warn) == 1) // `with' as a type operator has been deprecated; use `&' instead, | ||
assert(problems.count(_.severity == Severity.Info) == 1) // one error found | ||
}) | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
> check |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,11 +207,28 @@ object DottyBuild extends Build { | |
). | ||
settings(publishing) | ||
|
||
// until sbt/sbt#2402 is fixed (https://github.com/sbt/sbt/issues/2402) | ||
lazy val cleanBridge = TaskKey[Unit]("clean-sbt-bridge", "delete dotty-sbt-bridge cache") | ||
|
||
lazy val `dotty-bridge` = project.in(file("bridge")). | ||
dependsOn(dotty). | ||
settings( | ||
overrideScalaVersionSetting, | ||
|
||
cleanBridge := { | ||
val dottyBridgeVersion = version.value | ||
val dottyVersion = (version in dotty).value | ||
val classVersion = System.getProperty("java.class.version") | ||
val sbtV = sbtVersion.value | ||
val home = System.getProperty("user.home") | ||
val org = organization.value | ||
val artifact = moduleName.value | ||
|
||
IO.delete(file(home) / ".ivy2" / "cache" / "org.scala-sbt" / s"$org-$artifact-$dottyBridgeVersion-bin_${dottyVersion}__$classVersion") | ||
IO.delete(file(home) / ".sbt" / "boot" / "scala-2.10.6" / "org.scala-sbt" / "sbt" / sbtV / s"$org-$artifact-$dottyBridgeVersion-bin_${dottyVersion}__$classVersion") | ||
}, | ||
publishLocal <<= publishLocal.dependsOn(cleanBridge), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome, finally! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oki There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
description := "sbt compiler bridge for Dotty", | ||
resolvers += Resolver.typesafeIvyRepo("releases"), | ||
libraryDependencies ++= Seq( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call this
cleanSbtBridge
since that's how you would call this from sbtThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the convention is to use
a-b-c
http://www.scala-sbt.org/0.13/sxr/sbt/Keys.scala.html#sbt.Keys.logLevel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah more or less: http://www.scala-sbt.org/0.13/sxr/sbt/Keys.scala.html#sbt.Keys.compileAnalysisFilename
:P. I will do as you said
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I wasn't totally clear, I meant that the
val
should be calledcleanSbtBridge
, but I'm fine with changing the key name too :)