Skip to content

Commit 2b48e2e

Browse files
committed
add test to show incremental compilation works under pipelining
1 parent 76deb1c commit 2b48e2e

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed

Diff for: sbt-test/pipelining/pipelining-changes/build.sbt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sbt.internal.inc.Analysis
2+
import complete.DefaultParsers._
3+
4+
ThisBuild / usePipelining := true
5+
6+
// Reset compiler iterations, necessary because tests run in batch mode
7+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
8+
recordPreviousIterations := {
9+
val log = streams.value.log
10+
CompileState.previousIterations = {
11+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
12+
previousAnalysis match {
13+
case None =>
14+
log.info("No previous analysis detected")
15+
0
16+
case Some(a: Analysis) => a.compilations.allCompilations.size
17+
}
18+
}
19+
}
20+
21+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
22+
23+
checkIterations := {
24+
val expected: Int = (Space ~> NatBasic).parsed
25+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
26+
assert(expected == actual, s"Expected $expected compilations, got $actual (previous: ${CompileState.previousIterations})")
27+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package a
2+
3+
enum A {
4+
case A, B
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sbt._
2+
import Keys._
3+
4+
object DottyInjectedPlugin extends AutoPlugin {
5+
override def requires = plugins.JvmPlugin
6+
override def trigger = allRequirements
7+
8+
override val projectSettings = Seq(
9+
scalaVersion := sys.props("plugin.scalaVersion"),
10+
)
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package a
2+
3+
enum A {
4+
case A
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package a
2+
3+
import scala.deriving.Mirror
4+
5+
object App {
6+
val m = summon[Mirror.SumOf[a.A]]
7+
def size = compiletime.constValue[Tuple.Size[m.MirroredElemTypes]]
8+
9+
@main def test =
10+
assert(size == 2, s"Expected size 2, got $size")
11+
}

Diff for: sbt-test/pipelining/pipelining-changes/test

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# test the interaction of incremental compilation and pipelining
2+
> compile
3+
> recordPreviousIterations
4+
$ copy-file changes/A1.scala src/main/scala/a/A.scala
5+
# A recompilation should trigger recompilation of App.scala, otherwise test assert will fail
6+
> run
7+
> checkIterations 2

0 commit comments

Comments
 (0)