Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert enabling caching for Kotlin 1.9.0 #3511

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<KotlinNativeTarget> {
checkCacheKindUserValueIsNotNone()
configureTargetCompilerCache(kotlinVersion)
disableKotlinNativeCache()
}
}
}
Expand All @@ -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
}
Expand All @@ -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}"
Expand All @@ -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'"),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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=")
}
}
}
Expand All @@ -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)
}
}
}
Expand Down