aboutsummaryrefslogtreecommitdiff
path: root/bridge
diff options
context:
space:
mode:
authorGuillaume Massé <masgui@gmail.com>2016-09-21 14:00:23 -0400
committerGuillaume Massé <masgui@gmail.com>2016-09-22 13:44:50 -0400
commit1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751 (patch)
tree93a2a5a47c044aedc64833960189ba4939adea39 /bridge
parentbcbc62ec8940fb9639da51778282cc805c23f84a (diff)
downloaddotty-1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751.tar.gz
dotty-1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751.tar.bz2
dotty-1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751.zip
delegate compilation info to sbt reporter
Diffstat (limited to 'bridge')
-rw-r--r--bridge/src/main/scala/xsbt/CompilerInterface.scala6
-rw-r--r--bridge/src/main/scala/xsbt/DelegatingReporter.scala58
-rw-r--r--bridge/src/sbt-test/compilerReporter/simple/project/Reporter.scala3
3 files changed, 63 insertions, 4 deletions
diff --git a/bridge/src/main/scala/xsbt/CompilerInterface.scala b/bridge/src/main/scala/xsbt/CompilerInterface.scala
index ee272b8b1..bf1488dad 100644
--- a/bridge/src/main/scala/xsbt/CompilerInterface.scala
+++ b/bridge/src/main/scala/xsbt/CompilerInterface.scala
@@ -50,12 +50,14 @@ class CachedCompilerImpl(args: Array[String], output: Output, resident: Boolean)
(outputArgs ++ args.toList ++ sources.map(_.getAbsolutePath).sortWith(_ < _)).toArray[String]
def run(sources: Array[File], changes: DependencyChanges, callback: AnalysisCallback, log: Logger, delegate: Reporter, progress: CompileProgress): Unit = synchronized {
- run(sources.toList, changes, callback, log, progress)
+ run(sources.toList, changes, callback, log, delegate, progress)
}
- private[this] def run(sources: List[File], changes: DependencyChanges, callback: AnalysisCallback, log: Logger, compileProgress: CompileProgress): Unit = {
+ private[this] def run(sources: List[File], changes: DependencyChanges, callback: AnalysisCallback, log: Logger, delegate: Reporter, compileProgress: CompileProgress): Unit = {
debug(log, args.mkString("Calling Dotty compiler with arguments (CompilerInterface):\n\t", "\n\t", ""))
val ctx = (new ContextBase).initialCtx.fresh
.setSbtCallback(callback)
+ .setReporter(new DelegatingReporter(delegate))
+
val cl = getClass.getClassLoader.asInstanceOf[URLClassLoader]
val reporter = DottyMain.process(commandArguments(sources.toArray), ctx)
diff --git a/bridge/src/main/scala/xsbt/DelegatingReporter.scala b/bridge/src/main/scala/xsbt/DelegatingReporter.scala
new file mode 100644
index 000000000..726570d71
--- /dev/null
+++ b/bridge/src/main/scala/xsbt/DelegatingReporter.scala
@@ -0,0 +1,58 @@
+/* sbt -- Simple Build Tool
+ * Copyright 2008, 2009 Mark Harrah
+ */
+package xsbt
+
+import dotty.tools._
+import dotc._
+import reporting._
+import core.Contexts._
+
+import xsbti.{Maybe, Position}
+
+final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter
+ with UniqueMessagePositions
+ with HideNonSensicalMessages {
+
+ override def printSummary(implicit ctx: Context): Unit = delegate.printSummary()
+
+ def doReport(d: Diagnostic)(implicit ctx: Context): Unit = {
+ val severity =
+ d match {
+ case _: Reporter.Error => xsbti.Severity.Error
+ case _: Reporter.Warning => xsbti.Severity.Warn
+ case _ => xsbti.Severity.Info
+ }
+ val pos =
+ if (d.pos.exists) Some(d.pos)
+ else None
+
+ val file =
+ if (d.pos.source.file.exists) Option(d.pos.source.file.file)
+ else None
+
+ val offset0 = pos.map(_.point)
+
+ val position = new Position {
+ def line: Maybe[Integer] = maybe(pos.map(_.line))
+ def lineContent: String = pos.map(_.lineContent).getOrElse("")
+ def offset: Maybe[Integer] = maybeInt(offset0)
+ def pointer: Maybe[Integer] = offset
+ def pointerSpace: Maybe[String] = maybe(offset0.map(" " * _))
+ def sourceFile: Maybe[java.io.File] = maybe(file)
+ def sourcePath: Maybe[String] = maybe(file.map(_.getPath))
+ }
+
+ delegate.log(position, d.message, severity)
+ }
+
+ private[this] def maybe[T](opt: Option[T]): Maybe[T] = opt match {
+ case None => Maybe.nothing[T]
+ case Some(s) => Maybe.just[T](s)
+ }
+ import java.lang.{ Integer => I }
+ private[this] def maybeInt(opt: Option[Int]): Maybe[I] = opt match {
+ case None => Maybe.nothing[I]
+ case Some(s) => Maybe.just[I](s)
+ }
+} \ No newline at end of file
diff --git a/bridge/src/sbt-test/compilerReporter/simple/project/Reporter.scala b/bridge/src/sbt-test/compilerReporter/simple/project/Reporter.scala
index 1c5952d28..c0a56ec82 100644
--- a/bridge/src/sbt-test/compilerReporter/simple/project/Reporter.scala
+++ b/bridge/src/sbt-test/compilerReporter/simple/project/Reporter.scala
@@ -36,10 +36,9 @@ object Reporter {
check <<= (compile in Compile).mapFailure( _ => {
val problems = reporter.get.problems
println(problems.toList)
- assert(problems.size == 3)
+ assert(problems.size == 2)
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
})
)
} \ No newline at end of file