-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test to show incremental compilation works under pipelining
- Loading branch information
1 parent
9f412f5
commit 7e11005
Showing
7 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package a | ||
|
||
enum A { | ||
case A, B | ||
} |
4 changes: 4 additions & 0 deletions
4
sbt-test/pipelining/pipelining-changes/project/CompileState.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
11 changes: 11 additions & 0 deletions
11
sbt-test/pipelining/pipelining-changes/project/DottyInjectedPlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
sbt-test/pipelining/pipelining-changes/src/main/scala/a/A.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
sbt-test/pipelining/pipelining-changes/src/main/scala/a/App.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |