|
| 1 | +import sbt.internal.inc.Analysis |
| 2 | +import xsbti.VirtualFileRef |
| 3 | +import xsbti.api.AnalyzedClass |
| 4 | +import xsbti.compile.{PreviousResult, CompileAnalysis, MiniSetup} |
| 5 | +import xsbti.compile.analysis.{ Compilation => XCompilation } |
| 6 | + |
1 | 7 | logLevel := Level.Debug
|
2 | 8 |
|
| 9 | +// Reset compile status because scripted tests are run in batch mode |
| 10 | +previousCompile in Compile := { |
| 11 | + val previous = (previousCompile in Compile).value |
| 12 | + if (!CompileState.isNew) { |
| 13 | + val res = PreviousResult.of(none[CompileAnalysis].asJava, none[MiniSetup].asJava) |
| 14 | + CompileState.isNew = true |
| 15 | + res |
| 16 | + } else previous |
| 17 | +} |
| 18 | + |
3 | 19 | // disable sbt's heuristic which recompiles everything in case
|
4 | 20 | // some fraction (e.g. 50%) of files is scheduled to be recompiled
|
5 | 21 | // in this test we want precise information about recompiled files
|
6 | 22 | // which that heuristic would distort
|
7 | 23 | incOptions := incOptions.value.withRecompileAllFraction(1.0)
|
8 | 24 |
|
| 25 | +Global / allowMachinePath := false |
| 26 | + |
9 | 27 | /* Performs checks related to compilations:
|
10 | 28 | * a) checks in which compilation given set of files was recompiled
|
11 | 29 | * b) checks overall number of compilations performed
|
12 | 30 | */
|
13 |
| -TaskKey[Unit]("check-compilations") := { |
14 |
| - val analysis = (compile in Compile).value.asInstanceOf[sbt.internal.inc.Analysis] |
| 31 | +TaskKey[Unit]("checkCompilations") := { |
| 32 | + val log = streams.value.log |
| 33 | + val c = fileConverter.value |
| 34 | + val vs = (Compile / sources).value.toVector map { x => |
| 35 | + c.toVirtualFile(x.toPath) |
| 36 | + } |
| 37 | + // log.info(vs.mkString(",")) |
| 38 | + |
| 39 | + val analysis = (compile in Compile).value match { case a: Analysis => a } |
15 | 40 | val srcDir = (scalaSource in Compile).value
|
16 |
| - val allCompilations = analysis.compilations.allCompilations |
17 |
| - val recompiledClasses: Seq[Set[String]] = allCompilations map { c => |
18 |
| - val recompiledClasses = analysis.apis.internal.collect { |
19 |
| - case (clazz, api) if api.compilationTimestamp() == c.getStartTime() => clazz |
| 41 | + def findFile(className: String): VirtualFileRef = { |
| 42 | + analysis.relations.definesClass(className).head |
| 43 | + } |
| 44 | + val allCompilations: Seq[XCompilation] = analysis.compilations.allCompilations |
| 45 | + log.info(s"allCompilations: $allCompilations") |
| 46 | + val recompiledFiles: Seq[Set[VirtualFileRef]] = allCompilations map { c: XCompilation => |
| 47 | + val recompiledFiles = analysis.apis.internal.collect { |
| 48 | + case (cn, api) if api.compilationTimestamp == c.getStartTime => findFile(cn) |
20 | 49 | }
|
21 |
| - recompiledClasses.toSet |
| 50 | + recompiledFiles.toSet |
22 | 51 | }
|
23 |
| - def recompiledClassesInIteration(iteration: Int, classNames: Set[String]): Unit = { |
24 |
| - assert(recompiledClasses(iteration) == classNames, "%s != %s".format(recompiledClasses(iteration), classNames)) |
| 52 | + def recompiledFilesInIteration(iteration: Int, fileNames: Set[String]) = { |
| 53 | + assert(recompiledFiles(iteration).map(_.name) == fileNames, |
| 54 | + s"""${recompiledFiles(iteration).map(_.name)} != $fileNames |
| 55 | + | |
| 56 | + |allCompilations = $allCompilations |
| 57 | + |""".stripMargin) |
25 | 58 | }
|
26 |
| - // test.Y is compiled only at the beginning as changes to test.A do not affect it |
27 |
| - recompiledClassesInIteration(0, Set("test.X", "test.Y")) |
28 |
| - // test.A is changed and recompiled |
29 |
| - recompiledClassesInIteration(1, Set("test.A")) |
30 |
| - // change in test.A causes recompilation of test.B, test.C, test.D which depend on transitively |
31 |
| - // and by inheritance on test.A |
32 |
| - // test.X is also recompiled because it depends by member reference on test.B |
33 |
| - // Note that test.Y is not recompiled because it depends just on X through member reference dependency |
34 |
| - recompiledClassesInIteration(2, Set("test.B", "test.C", "test.D")) |
| 59 | + // Y.scala is compiled only at the beginning as changes to A.scala do not affect it |
| 60 | + recompiledFilesInIteration(0, Set("X.scala", "Y.scala")) |
| 61 | + // A.scala is changed and recompiled |
| 62 | + recompiledFilesInIteration(1, Set("A.scala")) |
| 63 | + // change in A.scala causes recompilation of B.scala, C.scala, D.scala which depend on transitively |
| 64 | + // and by inheritance on A.scala |
| 65 | + // X.scala is also recompiled because it depends by member reference on B.scala |
| 66 | + // Note that Y.scala is not recompiled because it depends just on X through member reference dependency |
| 67 | + recompiledFilesInIteration(2, Set("B.scala", "C.scala", "D.scala")) |
35 | 68 | assert(allCompilations.size == 3)
|
36 | 69 | }
|
0 commit comments