From df5396fa97f2a82e96fc7c111f48e38f473b1b34 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Wed, 16 Aug 2023 22:06:58 +0200 Subject: [PATCH] Revert enabling caching for Kotlin 1.9.0 (#3511) We tried to enable the compiler cache, when Kotlin/Native 1.9.0 is used. Prior to Kotlin 1.9.0, the caching could not be used with Compose, because code generation would fail. With Kotlin 1.9.0, code generation succeeds, but generated debug symbols cause issues with dsymutil during xcode build. For more details, see https://youtrack.jetbrains.com/issue/KT-61270 This change partially reverts https://github.com/JetBrains/compose-multiplatform/pull/3477 and https://github.com/JetBrains/compose-multiplatform/pull/3496 Now, we always set `kotlin.native.cacheKind=none` in Compose Multiplatform Gradle plugin for all versions of Kotlin until KT-61270 is fixed. Also, explicit cache kind error becomes a warning again. --- .../configureNativeCompilerCaching.kt | 51 ++++--------------- .../tests/integration/GradlePluginTest.kt | 13 +++-- 2 files changed, 15 insertions(+), 49 deletions(-) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureNativeCompilerCaching.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureNativeCompilerCaching.kt index 7537f89bff..bc0b7b2296 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureNativeCompilerCaching.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureNativeCompilerCaching.kt @@ -11,7 +11,6 @@ import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID import org.jetbrains.compose.internal.mppExt import org.jetbrains.compose.internal.utils.KGPPropertyProvider import org.jetbrains.compose.internal.utils.configureEachWithType -import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.konan.target.presetName @@ -23,10 +22,9 @@ internal fun Project.configureNativeCompilerCaching() { if (findProperty(COMPOSE_NATIVE_MANAGE_CACHE_KIND) == "false") return plugins.withId(KOTLIN_MPP_PLUGIN_ID) { - val kotlinVersion = kotlinVersionNumbers(this) mppExt.targets.configureEachWithType { checkCacheKindUserValueIsNotNone() - configureTargetCompilerCache(kotlinVersion) + disableKotlinNativeCache() } } } @@ -46,7 +44,9 @@ private fun KotlinNativeTarget.checkCacheKindUserValueIsNotNone() { val value = provider.valueOrNull(cacheKindProperty) if (value != null) { if (value.equals(NONE_VALUE, ignoreCase = true)) { - error(cacheKindPropertyWarningMessage(cacheKindProperty, provider)) + ComposeMultiplatformBuildService + .getInstance(project) + .warnOnceAfterBuild(cacheKindPropertyWarningMessage(cacheKindProperty, provider)) } return } @@ -58,30 +58,14 @@ private fun cacheKindPropertyWarningMessage( cacheKindProperty: String, provider: KGPPropertyProvider ) = """ - |'$cacheKindProperty' is explicitly set to `none`. - |This option significantly slows the Kotlin/Native compiler. - |Compose Multiplatform Gradle plugin can set this property automatically, - |when it is necessary. + |Warning: '$cacheKindProperty' is explicitly set to `none`. + |Compose Multiplatform Gradle plugin can manage this property automatically + |based on a Kotlin compiler version being used. + |In future versions of Compose Multiplatform this warning will become an error. | * Recommended action: remove explicit '$cacheKindProperty=$NONE_VALUE' from ${provider.location}. - | * Alternative action: if you are sure you need '$cacheKindProperty=$NONE_VALUE', disable - |this error by adding '$COMPOSE_NATIVE_MANAGE_CACHE_KIND=false' to your 'gradle.properties'. + | * Alternative action: disable cache kind management by adding '$COMPOSE_NATIVE_MANAGE_CACHE_KIND=false' to your 'gradle.properties'. """.trimMargin() -private fun KotlinNativeTarget.configureTargetCompilerCache(kotlinVersion: KotlinVersion) { - // See comments in https://youtrack.jetbrains.com/issue/KT-57329 - when { - // Kotlin < 1.9.0 => disable cache - kotlinVersion < KotlinVersion(1, 9, 0) -> { - disableKotlinNativeCache() - } - // 1.9.0 <= Kotlin < 1.9.20 => add -Xlazy-ir-for-caches=disable - kotlinVersion < KotlinVersion(1, 9, 20) -> { - disableLazyIrForCaches() - } - // Kotlin >= 1.9.20 => do nothing - else -> {} - } -} private val KotlinNativeTarget.targetCacheKindPropertyName: String get() = "$PROJECT_CACHE_KIND_PROPERTY_NAME.${konanTarget.presetName}" @@ -92,21 +76,4 @@ private fun KotlinNativeTarget.disableKotlinNativeCache() { } else { project.extensions.extraProperties.set(targetCacheKindPropertyName, NONE_VALUE) } -} - -private fun KotlinNativeTarget.disableLazyIrForCaches() { - compilations.configureEach { compilation -> - compilation.kotlinOptions.freeCompilerArgs += listOf("-Xlazy-ir-for-caches=disable") - } -} - -private fun kotlinVersionNumbers(project: Project): KotlinVersion { - val version = project.getKotlinPluginVersion() - val m = Regex("(\\d+)\\.(\\d+)\\.(\\d+)").find(version) ?: error("Kotlin version has unexpected format: '$version'") - val (_, majorPart, minorPart, patchPart) = m.groupValues - return KotlinVersion( - major = majorPart.toIntOrNull() ?: error("Could not parse major part '$majorPart' of Kotlin plugin version: '$version'"), - minor = minorPart.toIntOrNull() ?: error("Could not parse minor part '$minorPart' of Kotlin plugin version: '$version'"), - patch = patchPart.toIntOrNull() ?: error("Could not parse patch part '$patchPart' of Kotlin plugin version: '$version'"), - ) } \ No newline at end of file diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt index 301f04f575..e47b9ca371 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt @@ -128,8 +128,7 @@ class GradlePluginTest : GradlePluginTestBase() { with(nativeCacheKindProject(kotlinVersion = TestKotlinVersions.v1_9_0) ) { gradle(task, "--info").checks { check.taskSuccessful(task) - check.logContains("-Xauto-cache-from=") - check.logContains("-Xlazy-ir-for-caches=disable") + check.logDoesntContain("-Xauto-cache-from=") } } } @@ -142,19 +141,19 @@ class GradlePluginTest : GradlePluginTestBase() { defaultTestEnvironment.copy(kotlinVersion = kotlinVersion) ) - val cacheKindError = "'kotlin.native.cacheKind' is explicitly set to `none`" + val cacheKindWarning = "'kotlin.native.cacheKind' is explicitly set to `none`" val args = arrayOf("build", "--dry-run", "-Pkotlin.native.cacheKind=none") with(nativeCacheKindWarningProject(kotlinVersion = TestKotlinVersions.v1_8_20)) { - gradleFailure(*args).checks { - check.logContains(cacheKindError) + gradle(*args).checks { + check.logContains(cacheKindWarning) } } testWorkDir.deleteRecursively() testWorkDir.mkdirs() with(nativeCacheKindWarningProject(kotlinVersion = TestKotlinVersions.v1_9_0) ) { - gradleFailure(*args).checks { - check.logContains(cacheKindError) + gradle(*args).checks { + check.logContains(cacheKindWarning) } } }