Skip to content

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

Merged
merged 3 commits into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bridge/src/sbt-test/compilerReporter/simple/Source.scala
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
}
1 change: 1 addition & 0 deletions bridge/src/sbt-test/compilerReporter/simple/build.sbt
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()
)
}
45 changes: 45 additions & 0 deletions bridge/src/sbt-test/compilerReporter/simple/project/Reporter.scala
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
})
)
}
1 change: 1 addition & 0 deletions bridge/src/sbt-test/compilerReporter/simple/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> check
17 changes: 17 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member

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 sbt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

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 called cleanSbtBridge, but I'm fine with changing the key name too :)


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),
Copy link
Member

Choose a reason for hiding this comment

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

<<= is deprecated: sbt/sbt#2716

Copy link
Member

Choose a reason for hiding this comment

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

Awesome, finally!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oki publishLocal := (publishLocal.dependsOn(cleanBridge)).value

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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(
Expand Down