KT-45777: Support compile avoidance

Test: Updated existing incremental compilation integration tests
This commit is contained in:
Hung Nguyen
2021-09-07 10:46:54 +01:00
committed by nataliya.valtman
parent f400305cc6
commit a6d0fcc676
3 changed files with 16 additions and 4 deletions
@@ -159,7 +159,7 @@ class IncrementalCompilationClasspathSnapshotJvmMultiProjectIT : IncrementalComp
modifyProject = changeMethodBodyInLib, modifyProject = changeMethodBodyInLib,
assertResults = { assertResults = {
assertTasksExecuted(":lib:$compileKotlinTaskName") assertTasksExecuted(":lib:$compileKotlinTaskName")
assertTasksExecuted(":app:$compileKotlinTaskName") // TODO: App compilation should have 'compile avoidance' assertTasksUpToDate(":app:$compileKotlinTaskName") // App compilation has 'compile avoidance'
assertCompiledKotlinFiles(File(project.projectDir, "lib").getFilesByNames("A.kt")) assertCompiledKotlinFiles(File(project.projectDir, "lib").getFilesByNames("A.kt"))
} }
) )
@@ -198,7 +198,7 @@ class IncrementalCompilationClasspathSnapshotJvmMultiProjectIT : IncrementalComp
override fun testCompileLibWithGroovy() { override fun testCompileLibWithGroovy() {
testCompileLibWithGroovy_doTest { testCompileLibWithGroovy_doTest {
assertTasksExecuted(":lib:$compileKotlinTaskName") assertTasksExecuted(":lib:$compileKotlinTaskName")
assertTasksExecuted(":app:$compileKotlinTaskName") // TODO: App compilation should have 'compile avoidance' assertTasksUpToDate(":app:$compileKotlinTaskName") // App compilation has 'compile avoidance'
assertCompiledKotlinFiles(listOf(File(project.projectDir, "lib").getFileByName("A.kt"))) assertCompiledKotlinFiles(listOf(File(project.projectDir, "lib").getFileByName("A.kt")))
} }
} }
@@ -50,7 +50,7 @@ class IncrementalJavaChangeClasspathSnapshotIT : IncrementalJavaChangeDefaultIT(
javaClassInLib, changeMethodBody, javaClassInLib, changeMethodBody,
assertResults = { assertResults = {
assertTasksExecuted(":lib:compileKotlin") assertTasksExecuted(":lib:compileKotlin")
assertTasksExecuted(":app:compileKotlin") // TODO: App compilation should have 'compile avoidance' assertTasksUpToDate(":app:compileKotlin") // App compilation has 'compile avoidance'
assertCompiledKotlinFiles(emptyList()) assertCompiledKotlinFiles(emptyList())
} }
) )
@@ -547,6 +547,8 @@ abstract class KotlinCompile @Inject constructor(
val classpathSnapshotDir = getClasspathSnapshotDir(task) val classpathSnapshotDir = getClasspathSnapshotDir(task)
task.classpathSnapshotProperties.classpathSnapshotDir.value(classpathSnapshotDir).disallowChanges() task.classpathSnapshotProperties.classpathSnapshotDir.value(classpathSnapshotDir).disallowChanges()
task.classpathSnapshotProperties.classpathSnapshotDirFileCollection.from(classpathSnapshotDir) task.classpathSnapshotProperties.classpathSnapshotDirFileCollection.from(classpathSnapshotDir)
} else {
task.classpathSnapshotProperties.classpath.from(task.project.provider { task.classpath })
} }
} }
} }
@@ -578,6 +580,11 @@ abstract class KotlinCompile @Inject constructor(
logger.kotlinDebug { "Set $this.usePreciseJavaTracking=$value" } logger.kotlinDebug { "Set $this.usePreciseJavaTracking=$value" }
} }
@Internal // To support compile avoidance (ClasspathSnapshotProperties.classpathSnapshot will be used as input instead)
override fun getClasspath(): FileCollection {
return super.getClasspath()
}
@get:Nested @get:Nested
abstract val classpathSnapshotProperties: ClasspathSnapshotProperties abstract val classpathSnapshotProperties: ClasspathSnapshotProperties
@@ -591,6 +598,11 @@ abstract class KotlinCompile @Inject constructor(
@get:Optional // Set if useClasspathSnapshot == true @get:Optional // Set if useClasspathSnapshot == true
abstract val classpathSnapshot: ConfigurableFileCollection abstract val classpathSnapshot: ConfigurableFileCollection
@get:Classpath
@get:Incremental
@get:Optional // Set if useClasspathSnapshot == false (to restore the existing classpath annotations when the feature is disabled)
abstract val classpath: ConfigurableFileCollection
@get:OutputDirectory @get:OutputDirectory
@get:Optional // Set if useClasspathSnapshot == true @get:Optional // Set if useClasspathSnapshot == true
abstract val classpathSnapshotDir: DirectoryProperty abstract val classpathSnapshotDir: DirectoryProperty
@@ -663,7 +675,7 @@ abstract class KotlinCompile @Inject constructor(
} }
override val incrementalProps: List<FileCollection> override val incrementalProps: List<FileCollection>
get() = super.incrementalProps + listOf(classpathSnapshotProperties.classpathSnapshot) get() = listOf(stableSources, commonSourceSet, classpathSnapshotProperties.classpath, classpathSnapshotProperties.classpathSnapshot)
override fun getSourceRoots(): SourceRoots.ForJvm = jvmSourceRoots override fun getSourceRoots(): SourceRoots.ForJvm = jvmSourceRoots