Skip to content

Commit

Permalink
Expose & Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Friendseeker committed Sep 27, 2024
1 parent fa99c37 commit 1f2495e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
public abstract class CompileFailed2 extends CompileFailed {
/**
* Returns SourceInfos containing problems for each file.
* This includes problems found by most recent compilation run and by all prior compilation runs.
* This does not include problems found by prior compilation runs that are no longer valid.
* e.g. If A.scala previously has a problem, but no longer has a problem, it will not be included.
* This includes problems found by most recent compilation run.
*/
public abstract ReadSourceInfos sourceInfos();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package inc

import java.nio.file.Path
import sbt.internal.util.FeedbackProvidedException
import xsbti.compile.analysis.ReadSourceInfos
import xsbti.compile.{ ClasspathOptions, ScalaInstance => XScalaInstance }

/**
Expand Down Expand Up @@ -98,11 +99,12 @@ class CompileFailed(
val arguments: Array[String],
override val toString: String,
val problems: Array[xsbti.Problem],
val sourceInfosOption: Option[ReadSourceInfos],
cause: Throwable
) extends xsbti.CompileFailed(cause)
with FeedbackProvidedException {

def this(arguments: Array[String], toString: String, problems: Array[xsbti.Problem]) = {
this(arguments, toString, problems, null)
this(arguments, toString, problems, None, null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,19 @@ class IncrementalCompilerImpl extends IncrementalCompiler {
try {
compilerRun
} catch {
case e: xsbti.CompileFailed2 => throw new sbt.internal.inc.CompileFailed(
e.arguments,
e.toString,
e.problems,
Some(e.sourceInfos()),
e,
) // just ignore
case e: xsbti.CompileFailed =>
throw new sbt.internal.inc.CompileFailed(
e.arguments,
e.toString,
e.problems,
None,
e
) // just ignore
case e: CompileFailed => throw e // just ignore
Expand Down
21 changes: 21 additions & 0 deletions zinc/src/test/scala/sbt/inc/IncrementalCompilerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,25 @@ class IncrementalCompilerSpec extends BaseCompilerSpec {
}
} finally comp.close()
}

it should "emit SourceInfos when incremental compilation fails" in withTmpDir {
tmp =>
val project = VirtualSubproject(tmp.toPath / "p1")
val comp = project.setup.createCompiler()
val s1 = "object A { final val i = 1"
val f1 = StringVirtualFile("A.scala", s1)
try {
val exception = intercept[CompileFailed] {
comp.compile(f1)
}
exception.sourceInfosOption match {
case Some(sourceInfos) =>
assert(
!sourceInfos.getAllSourceInfos.isEmpty,
"Expected non-empty source infos"
)
case None => fail("Expected sourceInfos")
}
} finally comp.close()
}
}

0 comments on commit 1f2495e

Please sign in to comment.