diff options
author | Guillaume Massé <masgui@gmail.com> | 2016-09-21 14:00:23 -0400 |
---|---|---|
committer | Guillaume Massé <masgui@gmail.com> | 2016-09-22 13:44:50 -0400 |
commit | 1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751 (patch) | |
tree | 93a2a5a47c044aedc64833960189ba4939adea39 /bridge/src/main | |
parent | bcbc62ec8940fb9639da51778282cc805c23f84a (diff) | |
download | dotty-1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751.tar.gz dotty-1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751.tar.bz2 dotty-1e2bbb2c0bc7c9ba4bb626d4e45a5ab8519ec751.zip |
delegate compilation info to sbt reporter
Diffstat (limited to 'bridge/src/main')
-rw-r--r-- | bridge/src/main/scala/xsbt/CompilerInterface.scala | 6 | ||||
-rw-r--r-- | bridge/src/main/scala/xsbt/DelegatingReporter.scala | 58 |
2 files changed, 62 insertions, 2 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 |