From b11c485fdfb798b4056496e3c68112d35b712bc6 Mon Sep 17 00:00:00 2001 From: Ting-Yuan Huang Date: Mon, 16 Sep 2024 10:29:12 -0700 Subject: [PATCH 1/3] UPDATE_KOTLIN_VERSION: 2.1.0-dev-7621 --- .../google/devtools/ksp/gradle/KotlinFactories.kt | 14 +------------- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt index 9a47147340..36ed53b8b5 100644 --- a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt +++ b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt @@ -56,12 +56,9 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonCompilerOptionsH import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptions import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptionsDefault import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptionsHelper -import org.jetbrains.kotlin.gradle.internal.ClassLoadersCachingBuildService import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationInfo -import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider import org.jetbrains.kotlin.gradle.plugin.SubpluginOption -import org.jetbrains.kotlin.gradle.targets.native.KonanPropertiesBuildService import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -169,7 +166,7 @@ class KotlinFactories { from = compilerOptions, into = kspTask.compilerOptions ) - kspTask.produceUnpackedKlib.set(false) + kspTask.produceUnpackagedKlib.set(false) kspTask.onlyIf { // KonanTarget is not properly serializable, hence we should check by name // see https://youtrack.jetbrains.com/issue/KT-61657. @@ -178,15 +175,6 @@ class KotlinFactories { it.name == konanTargetName } } - kspTask.kotlinCompilerArgumentsLogLevel - .value(project.kotlinPropertiesProvider.kotlinCompilerArgumentsLogLevel) - .finalizeValueOnRead() - kspTask.konanPropertiesService - .value(KonanPropertiesBuildService.registerIfAbsent(project)) - .disallowChanges() - kspTask.classLoadersCachingService - .value(ClassLoadersCachingBuildService.registerIfAbsent(project)) - .disallowChanges() } } } diff --git a/gradle.properties b/gradle.properties index 5708037571..78f54ca93e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Copied from kotlinc org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx4096m -Dfile.encoding=UTF-8 -kotlinBaseVersion=2.1.0-dev-5441 +kotlinBaseVersion=2.1.0-dev-7621 agpBaseVersion=8.7.0 intellijVersion=233.13135.103 junitVersion=4.13.1 From 11aa3b1b6999d8578053c9b7eee0485bf7369e7a Mon Sep 17 00:00:00 2001 From: Ting-Yuan Huang Date: Tue, 15 Oct 2024 12:13:11 -0700 Subject: [PATCH 2/3] Replace the deprecated android with androidTarget --- .../google/devtools/ksp/gradle/SourceSetConfigurationsTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/SourceSetConfigurationsTest.kt b/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/SourceSetConfigurationsTest.kt index 5744fcf186..e0506ae756 100644 --- a/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/SourceSetConfigurationsTest.kt +++ b/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/SourceSetConfigurationsTest.kt @@ -81,7 +81,7 @@ class SourceSetConfigurationsTest { """ kotlin { jvm { } - android(name = "foo") { } + androidTarget(name = "foo") { } js(IR) { browser() } androidNativeX86 { } androidNativeX64(name = "bar") { } From f12968a9dba1480c7a7338105d5191e3c0a604e6 Mon Sep 17 00:00:00 2001 From: Ting-Yuan Huang Date: Tue, 15 Oct 2024 12:13:30 -0700 Subject: [PATCH 3/3] KSP1: Try to invalidate KotlinCliJavaFileManagerImpl.topLevelClassesCache See https://github.com/JetBrains/kotlin/pull/5369 for more details. --- .../ksp/KotlinSymbolProcessingExtension.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt index 92948f217c..27c01f2de7 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt @@ -50,8 +50,10 @@ import com.intellij.openapi.vfs.StandardFileSystems import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager +import com.intellij.psi.impl.file.impl.JavaFileManager import org.jetbrains.kotlin.analyzer.AnalysisResult import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCliJavaFileManagerImpl import org.jetbrains.kotlin.config.JvmAnalysisFlags import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.container.ComponentProvider @@ -157,6 +159,8 @@ abstract class AbstractKotlinSymbolProcessingExtension( val psiManager = PsiManager.getInstance(project) if (initialized) { psiManager.dropPsiCaches() + psiManager.dropResolveCaches() + invalidateKotlinCliJavaFileManagerCache(project) } else { // In case of broken builds. if (javaShadowBase.exists()) { @@ -509,3 +513,13 @@ fun findTargetInfos(languageVersionSettings: LanguageVersionSettings, module: Mo else -> UnknownPlatformInfoImpl(platform.toString()) } } ?: emptyList() + +// FIXME: remove as soon as possible. +private fun invalidateKotlinCliJavaFileManagerCache(project: Project): Boolean { + val javaFileManager = (JavaFileManager.getInstance(project) as? KotlinCliJavaFileManagerImpl) ?: return false + val privateCacheField = KotlinCliJavaFileManagerImpl::class.java.getDeclaredField("topLevelClassesCache") + if (!privateCacheField.trySetAccessible()) + return false + (privateCacheField.get(javaFileManager) as? MutableMap<*, *>)?.clear() ?: return false + return true +}