From 01c14a709a761469fd04feb82bab3a528f3488a5 Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Thu, 6 May 2021 11:24:24 +0100 Subject: [PATCH] KotlinCompile: Add `kotlin.incremental.useClasspathSnapshot` flag We are planning to improve incremental Kotlin compile with a new approach using classpath snapshot (see https://youtrack.jetbrains.com/issue/KT-45777 for more details). The estimated steps will be as follows: [x] Add a flag for the new approach, disabled by default [ ] Add tests for the new approach, and update them as we go [ ] Add computation of classpath snapshot using artifact transforms [ ] Add computation of classpath snapshot changes [ ] Ensure incremental compile is fully functional with the new approach [ ] Measure performance + optimize: Repeat until we see evidence that the new approach is clearly better than the current approach [ ] Advertise the flag, and later on enable it by default This commit is the first step. Although it's simple, it allows further changes to be made safely without impacting the current approach. Bug: KT-45777 Test: N/A (will be added in a subsequent change) --- .../kotlin/gradle/plugin/KotlinProperties.kt | 12 ++++++++++++ .../org/jetbrains/kotlin/gradle/tasks/Tasks.kt | 3 +++ 2 files changed, 15 insertions(+) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinProperties.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinProperties.kt index 51d16492aa2..55df0e4782a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinProperties.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinProperties.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild +import org.jetbrains.kotlin.gradle.utils.getSystemProperty import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.konan.target.presetName import org.jetbrains.kotlin.statistics.metrics.StringMetrics @@ -35,6 +36,7 @@ internal fun PropertiesProvider.mapKotlinTaskProperties(task: AbstractKotlinComp usePreciseJavaTracking?.let { task.usePreciseJavaTracking = it } + task.useClasspathSnapshot.value(useClasspathSnapshot).disallowChanges() useFir?.let { if (it == true) { task.kotlinOptions.useFir = true @@ -96,6 +98,16 @@ internal class PropertiesProvider private constructor(private val project: Proje val usePreciseJavaTracking: Boolean? get() = booleanProperty("kotlin.incremental.usePreciseJavaTracking") + val useClasspathSnapshot: Boolean + get() { + // The feature should be controlled by a Gradle property. + // Currently, we also allow it to be controlled by a system property to make it easier to test the feature during development. + // TODO: Remove the system property later. + val gradleProperty = booleanProperty("kotlin.incremental.useClasspathSnapshot") ?: false + val systemProperty = project.getSystemProperty("kotlin.incremental.useClasspathSnapshot")?.toBoolean() ?: false + return gradleProperty || systemProperty + } + val useFir: Boolean? get() = booleanProperty("kotlin.useFir") 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 4a68144b9e9..76d5ade54a8 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 @@ -421,6 +421,9 @@ abstract class KotlinCompile @Inject constructor( logger.kotlinDebug { "Set $this.usePreciseJavaTracking=$value" } } + @get:Input + abstract val useClasspathSnapshot: Property + init { incremental = true }