Skip to content

Commit

Permalink
add test to show incremental compilation works under pipelining
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Mar 19, 2024
1 parent 76deb1c commit 2b48e2e
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 0 deletions.
27 changes: 27 additions & 0 deletions sbt-test/pipelining/pipelining-changes/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sbt.internal.inc.Analysis
import complete.DefaultParsers._

ThisBuild / usePipelining := true

// Reset compiler iterations, necessary because tests run in batch mode
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
recordPreviousIterations := {
val log = streams.value.log
CompileState.previousIterations = {
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
previousAnalysis match {
case None =>
log.info("No previous analysis detected")
0
case Some(a: Analysis) => a.compilations.allCompilations.size
}
}
}

val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")

checkIterations := {
val expected: Int = (Space ~> NatBasic).parsed
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
assert(expected == actual, s"Expected $expected compilations, got $actual (previous: ${CompileState.previousIterations})")
}
5 changes: 5 additions & 0 deletions sbt-test/pipelining/pipelining-changes/changes/A1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package a

enum A {
case A, B
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This is necessary because tests are run in batch mode
object CompileState {
@volatile var previousIterations: Int = -1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sbt._
import Keys._

object DottyInjectedPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin
override def trigger = allRequirements

override val projectSettings = Seq(
scalaVersion := sys.props("plugin.scalaVersion"),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package a

enum A {
case A
}
11 changes: 11 additions & 0 deletions sbt-test/pipelining/pipelining-changes/src/main/scala/a/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package a

import scala.deriving.Mirror

object App {
val m = summon[Mirror.SumOf[a.A]]
def size = compiletime.constValue[Tuple.Size[m.MirroredElemTypes]]

@main def test =
assert(size == 2, s"Expected size 2, got $size")
}
7 changes: 7 additions & 0 deletions sbt-test/pipelining/pipelining-changes/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# test the interaction of incremental compilation and pipelining
> compile
> recordPreviousIterations
$ copy-file changes/A1.scala src/main/scala/a/A.scala
# A recompilation should trigger recompilation of App.scala, otherwise test assert will fail
> run
> checkIterations 2

0 comments on commit 2b48e2e

Please sign in to comment.