Browse Source

Don't disable compiler caches for Kotlin 1.9.20+ (#3648)

pull/3672/head
Alexey Tsvetkov 1 year ago committed by GitHub
parent
commit
4bb9072d8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureNativeCompilerCaching.kt
  2. 13
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt

20
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureNativeCompilerCaching.kt

@ -11,6 +11,7 @@ import org.jetbrains.compose.internal.mppExt
import org.jetbrains.compose.internal.service.ConfigurationProblemReporterService
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.KonanTarget
import org.jetbrains.kotlin.konan.target.presetName
@ -36,10 +37,15 @@ internal fun Project.configureNativeCompilerCaching() {
if (findProperty(COMPOSE_NATIVE_MANAGE_CACHE_KIND) == "false") return
plugins.withId(KOTLIN_MPP_PLUGIN_ID) {
val kotlinPluginVersion = kotlinVersionNumbers(project.getKotlinPluginVersion())
mppExt.targets.configureEachWithType<KotlinNativeTarget> {
if (konanTarget in SUPPORTED_NATIVE_TARGETS) {
checkExplicitCacheKind()
disableKotlinNativeCache()
if (kotlinPluginVersion < KotlinVersion(1, 9, 20)) {
// Pre-1.9.20 Kotlin compiler caches have known compatibility issues
// See KT-57329, KT-61270
disableKotlinNativeCache()
}
}
}
}
@ -97,4 +103,14 @@ private fun KotlinNativeTarget.disableKotlinNativeCache() {
} else {
project.extensions.extraProperties.set(targetCacheKindPropertyName, NONE_VALUE)
}
}
}
internal fun kotlinVersionNumbers(version: String): KotlinVersion {
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'"),
)
}

13
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt

@ -9,6 +9,7 @@ import org.gradle.util.GradleVersion
import org.jetbrains.compose.desktop.ui.tooling.preview.rpc.PreviewLogger
import org.jetbrains.compose.desktop.ui.tooling.preview.rpc.RemoteConnection
import org.jetbrains.compose.desktop.ui.tooling.preview.rpc.receiveConfigFromGradle
import org.jetbrains.compose.experimental.internal.kotlinVersionNumbers
import org.jetbrains.compose.internal.utils.OS
import org.jetbrains.compose.internal.utils.currentOS
import org.jetbrains.compose.test.utils.*
@ -132,6 +133,18 @@ class GradlePluginTest : GradlePluginTestBase() {
check.logDoesntContain("-Xauto-cache-from=")
}
}
val defaultKotlinVersion = kotlinVersionNumbers(TestKotlinVersions.Default)
if (defaultKotlinVersion >= KotlinVersion(1, 9, 20)) {
testWorkDir.deleteRecursively()
testWorkDir.mkdirs()
with(nativeCacheKindProject(TestKotlinVersions.Default) ) {
gradle(task, "--info").checks {
check.taskSuccessful(task)
check.logContains("-Xauto-cache-from=")
}
}
}
}
@Test

Loading…
Cancel
Save