Skip to content

Commit 1e2bbb2

Browse files
delegate compilation info to sbt reporter
1 parent bcbc62e commit 1e2bbb2

File tree

4 files changed

+72
-10
lines changed

4 files changed

+72
-10
lines changed

bridge/src/main/scala/xsbt/CompilerInterface.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ class CachedCompilerImpl(args: Array[String], output: Output, resident: Boolean)
5050
(outputArgs ++ args.toList ++ sources.map(_.getAbsolutePath).sortWith(_ < _)).toArray[String]
5151

5252
def run(sources: Array[File], changes: DependencyChanges, callback: AnalysisCallback, log: Logger, delegate: Reporter, progress: CompileProgress): Unit = synchronized {
53-
run(sources.toList, changes, callback, log, progress)
53+
run(sources.toList, changes, callback, log, delegate, progress)
5454
}
55-
private[this] def run(sources: List[File], changes: DependencyChanges, callback: AnalysisCallback, log: Logger, compileProgress: CompileProgress): Unit = {
55+
private[this] def run(sources: List[File], changes: DependencyChanges, callback: AnalysisCallback, log: Logger, delegate: Reporter, compileProgress: CompileProgress): Unit = {
5656
debug(log, args.mkString("Calling Dotty compiler with arguments (CompilerInterface):\n\t", "\n\t", ""))
5757
val ctx = (new ContextBase).initialCtx.fresh
5858
.setSbtCallback(callback)
59+
.setReporter(new DelegatingReporter(delegate))
60+
5961
val cl = getClass.getClassLoader.asInstanceOf[URLClassLoader]
6062

6163
val reporter = DottyMain.process(commandArguments(sources.toArray), ctx)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* sbt -- Simple Build Tool
2+
* Copyright 2008, 2009 Mark Harrah
3+
*/
4+
package xsbt
5+
6+
import dotty.tools._
7+
import dotc._
8+
import reporting._
9+
import core.Contexts._
10+
11+
import xsbti.{Maybe, Position}
12+
13+
final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter
14+
with UniqueMessagePositions
15+
with HideNonSensicalMessages {
16+
17+
override def printSummary(implicit ctx: Context): Unit = delegate.printSummary()
18+
19+
def doReport(d: Diagnostic)(implicit ctx: Context): Unit = {
20+
val severity =
21+
d match {
22+
case _: Reporter.Error => xsbti.Severity.Error
23+
case _: Reporter.Warning => xsbti.Severity.Warn
24+
case _ => xsbti.Severity.Info
25+
}
26+
val pos =
27+
if (d.pos.exists) Some(d.pos)
28+
else None
29+
30+
val file =
31+
if (d.pos.source.file.exists) Option(d.pos.source.file.file)
32+
else None
33+
34+
val offset0 = pos.map(_.point)
35+
36+
val position = new Position {
37+
def line: Maybe[Integer] = maybe(pos.map(_.line))
38+
def lineContent: String = pos.map(_.lineContent).getOrElse("")
39+
def offset: Maybe[Integer] = maybeInt(offset0)
40+
def pointer: Maybe[Integer] = offset
41+
def pointerSpace: Maybe[String] = maybe(offset0.map(" " * _))
42+
def sourceFile: Maybe[java.io.File] = maybe(file)
43+
def sourcePath: Maybe[String] = maybe(file.map(_.getPath))
44+
}
45+
46+
delegate.log(position, d.message, severity)
47+
}
48+
49+
private[this] def maybe[T](opt: Option[T]): Maybe[T] = opt match {
50+
case None => Maybe.nothing[T]
51+
case Some(s) => Maybe.just[T](s)
52+
}
53+
import java.lang.{ Integer => I }
54+
private[this] def maybeInt(opt: Option[Int]): Maybe[I] = opt match {
55+
case None => Maybe.nothing[I]
56+
case Some(s) => Maybe.just[I](s)
57+
}
58+
}

bridge/src/sbt-test/compilerReporter/simple/project/Reporter.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ object Reporter {
3636
check <<= (compile in Compile).mapFailure( _ => {
3737
val problems = reporter.get.problems
3838
println(problems.toList)
39-
assert(problems.size == 3)
39+
assert(problems.size == 2)
4040
assert(problems.count(_.severity == Severity.Error) == 1) // not found: er1,
4141
assert(problems.count(_.severity == Severity.Warn) == 1) // `with' as a type operator has been deprecated; use `&' instead,
42-
assert(problems.count(_.severity == Severity.Info) == 1) // one error found
4342
})
4443
)
4544
}

project/Build.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,27 +208,30 @@ object DottyBuild extends Build {
208208
settings(publishing)
209209

210210
// until sbt/sbt#2402 is fixed (https://github.com/sbt/sbt/issues/2402)
211-
lazy val cleanBridge = TaskKey[Unit]("clean-sbt-bridge", "delete dotty-sbt-bridge cache")
211+
lazy val cleanSbtBridge = TaskKey[Unit]("cleanSbtBridge", "delete dotty-sbt-bridge cache")
212212

213213
lazy val `dotty-bridge` = project.in(file("bridge")).
214214
dependsOn(dotty).
215215
settings(
216216
overrideScalaVersionSetting,
217217

218-
cleanBridge := {
218+
cleanSbtBridge := {
219219
val dottyBridgeVersion = version.value
220220
val dottyVersion = (version in dotty).value
221221
val classVersion = System.getProperty("java.class.version")
222+
222223
val sbtV = sbtVersion.value
224+
val sbtOrg = "org.scala-sbt"
225+
val sbtScalaVersion = "2.10.6"
226+
223227
val home = System.getProperty("user.home")
224228
val org = organization.value
225229
val artifact = moduleName.value
226230

227-
IO.delete(file(home) / ".ivy2" / "cache" / "org.scala-sbt" / s"$org-$artifact-$dottyBridgeVersion-bin_${dottyVersion}__$classVersion")
228-
IO.delete(file(home) / ".sbt" / "boot" / "scala-2.10.6" / "org.scala-sbt" / "sbt" / sbtV / s"$org-$artifact-$dottyBridgeVersion-bin_${dottyVersion}__$classVersion")
231+
IO.delete(file(home) / ".ivy2" / "cache" / sbtOrg / s"$org-$artifact-$dottyBridgeVersion-bin_${dottyVersion}__$classVersion")
232+
IO.delete(file(home) / ".sbt" / "boot" / s"scala-$sbtScalaVersion" / sbtOrg / "sbt" / sbtV / s"$org-$artifact-$dottyBridgeVersion-bin_${dottyVersion}__$classVersion")
229233
},
230-
publishLocal <<= publishLocal.dependsOn(cleanBridge),
231-
234+
publishLocal := (publishLocal.dependsOn(cleanSbtBridge)).value,
232235
description := "sbt compiler bridge for Dotty",
233236
resolvers += Resolver.typesafeIvyRepo("releases"),
234237
libraryDependencies ++= Seq(

0 commit comments

Comments
 (0)