From a6d0fcc676bc254a519da3cb8e55e3cd4a3c6207 Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Tue, 7 Sep 2021 10:46:54 +0100 Subject: [PATCH] KT-45777: Support compile avoidance Test: Updated existing incremental compilation integration tests --- .../gradle/IncrementalCompilationMultiProjectIT.kt | 4 ++-- .../kotlin/gradle/IncrementalJavaChangeIT.kt | 2 +- .../org/jetbrains/kotlin/gradle/tasks/Tasks.kt | 14 +++++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/IncrementalCompilationMultiProjectIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/IncrementalCompilationMultiProjectIT.kt index 1a50b533b0e..8e092bec906 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/IncrementalCompilationMultiProjectIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/IncrementalCompilationMultiProjectIT.kt @@ -159,7 +159,7 @@ class IncrementalCompilationClasspathSnapshotJvmMultiProjectIT : IncrementalComp modifyProject = changeMethodBodyInLib, assertResults = { 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")) } ) @@ -198,7 +198,7 @@ class IncrementalCompilationClasspathSnapshotJvmMultiProjectIT : IncrementalComp override fun testCompileLibWithGroovy() { testCompileLibWithGroovy_doTest { 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"))) } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/IncrementalJavaChangeIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/IncrementalJavaChangeIT.kt index 1357d3ce030..f044a62eb6a 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/IncrementalJavaChangeIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/IncrementalJavaChangeIT.kt @@ -50,7 +50,7 @@ class IncrementalJavaChangeClasspathSnapshotIT : IncrementalJavaChangeDefaultIT( javaClassInLib, changeMethodBody, assertResults = { assertTasksExecuted(":lib:compileKotlin") - assertTasksExecuted(":app:compileKotlin") // TODO: App compilation should have 'compile avoidance' + assertTasksUpToDate(":app:compileKotlin") // App compilation has 'compile avoidance' assertCompiledKotlinFiles(emptyList()) } ) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index b6ff7ab48b8..2cd7a37adb9 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -547,6 +547,8 @@ abstract class KotlinCompile @Inject constructor( val classpathSnapshotDir = getClasspathSnapshotDir(task) task.classpathSnapshotProperties.classpathSnapshotDir.value(classpathSnapshotDir).disallowChanges() 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" } } + @Internal // To support compile avoidance (ClasspathSnapshotProperties.classpathSnapshot will be used as input instead) + override fun getClasspath(): FileCollection { + return super.getClasspath() + } + @get:Nested abstract val classpathSnapshotProperties: ClasspathSnapshotProperties @@ -591,6 +598,11 @@ abstract class KotlinCompile @Inject constructor( @get:Optional // Set if useClasspathSnapshot == true 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:Optional // Set if useClasspathSnapshot == true abstract val classpathSnapshotDir: DirectoryProperty @@ -663,7 +675,7 @@ abstract class KotlinCompile @Inject constructor( } override val incrementalProps: List - get() = super.incrementalProps + listOf(classpathSnapshotProperties.classpathSnapshot) + get() = listOf(stableSources, commonSourceSet, classpathSnapshotProperties.classpath, classpathSnapshotProperties.classpathSnapshot) override fun getSourceRoots(): SourceRoots.ForJvm = jvmSourceRoots