Skip to content

Commit

Permalink
Don't disable compiler caches for Kotlin 1.9.20+ (#3648)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyTsvetkov authored Sep 13, 2023
1 parent 021b099 commit 4bb9072
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
}
}
Expand Down Expand Up @@ -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'"),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4bb9072

Please sign in to comment.