From 9cb7b309ae099d0467e3d313bbfd7ca106dd96a4 Mon Sep 17 00:00:00 2001 From: Jiaxiang Chen Date: Tue, 19 Apr 2022 00:18:44 -0700 Subject: [PATCH] UPDATE_KOTLIN_VERSION: 1.7.0-Beta --- buildSrc/settings.gradle.kts | 8 +--- compiler-plugin/testData/api/sealedClass.kt | 4 +- .../devtools/ksp/gradle/KspSubplugin.kt | 45 ++++++++++++++----- gradle.properties | 2 +- settings.gradle.kts | 8 +--- .../ksp/processor/SealedClassProcessor.kt | 2 +- .../devtools/ksp/testutils/AbstractKSPTest.kt | 8 +--- 7 files changed, 42 insertions(+), 35 deletions(-) diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index 6ddf46aac3..54ef6648f6 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -8,11 +8,7 @@ pluginManagement { props.load(it) } }["kotlinBaseVersion"] as String - resolutionStrategy { - eachPlugin { - if (requested.id.id == "org.jetbrains.kotlin.jvm") { - useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinBaseVersion") - } - } + plugins { + id("org.jetbrains.kotlin.jvm") version kotlinBaseVersion } } diff --git a/compiler-plugin/testData/api/sealedClass.kt b/compiler-plugin/testData/api/sealedClass.kt index ea87d8db42..ab514e2a62 100644 --- a/compiler-plugin/testData/api/sealedClass.kt +++ b/compiler-plugin/testData/api/sealedClass.kt @@ -17,7 +17,7 @@ // TEST PROCESSOR: SealedClassProcessor // EXPECTED: -// Expr : [Const, Sum, NotANumber] +// Expr : [Const, NotANumber, Sum] // Const : [] // Sum : [] // NotANumber : [] @@ -27,4 +27,4 @@ sealed class Expr data class Const(val number: Double) : Expr() data class Sum(val e1: Expr, val e2: Expr) : Expr() -object NotANumber : Expr() \ No newline at end of file +object NotANumber : Expr() diff --git a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt index ec595434ba..7019a08488 100644 --- a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt +++ b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt @@ -59,8 +59,8 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.enabledOnCurrentHost import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinCompilationData import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinNativeCompilationData import org.jetbrains.kotlin.gradle.tasks.* -import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.Configurator import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.gradle.tasks.configuration.AbstractKotlinCompileConfig import org.jetbrains.kotlin.incremental.ChangedFiles import org.jetbrains.kotlin.incremental.destinationAsFile import org.jetbrains.kotlin.incremental.isJavaFile @@ -73,6 +73,29 @@ import java.util.concurrent.Callable import javax.inject.Inject import kotlin.reflect.KProperty1 +@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_PARAMETER_TYPE") +internal class Configurator : AbstractKotlinCompileConfig> { + constructor(compilation: KotlinCompilationData<*>, kotlinCompile: AbstractKotlinCompile<*>) : super(compilation) { + configureTask { task -> + if (task is KspTaskJvm) { + // Assign moduleName different from kotlin compilation to + // work around https://github.com/google/ksp/issues/647 + // This will not be necessary once https://youtrack.jetbrains.com/issue/KT-45777 lands + task.moduleName.value(kotlinCompile.moduleName.map { "$it-ksp" }) + } + if (task is KspTaskJS) { + val libraryCacheService = project.rootProject.gradle.sharedServices.registerIfAbsent( + "${Kotlin2JsCompile.LibraryFilterCachingService::class.java.canonicalName}" + + "_${Kotlin2JsCompile.LibraryFilterCachingService::class.java.classLoader.hashCode()}", + Kotlin2JsCompile.LibraryFilterCachingService::class.java + ) {} + task.libraryCache.set(libraryCacheService).also { task.libraryCache.disallowChanges() } + task.pluginClasspath.setFrom(objectFactory.fileCollection()) + } + } + } +} + class KspGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : KotlinCompilerPluginSupportPlugin { companion object { @@ -338,7 +361,10 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool } else -> return project.provider { emptyList() } } - + kotlinCompileTask.safeAs>()?.let { + Configurator(kotlinCompilation as KotlinCompilationData<*>, kotlinCompileTask as AbstractKotlinCompile<*>) + .execute(kspTaskProvider as TaskProvider>) + } kotlinCompileProvider.configure { kotlinCompile -> kotlinCompile.dependsOn(kspTaskProvider) kotlinCompile.setSource(kotlinOutputDir, javaOutputDir) @@ -463,10 +489,6 @@ abstract class KspTaskJvm @Inject constructor( kotlinCompilation: KotlinCompilationData<*>, kotlinCompile: AbstractKotlinCompile<*>, ) { - Configurator(kotlinCompilation).configure(this) - // Assign moduleName different from kotlin compilation to work around https://github.com/google/ksp/issues/647 - // This will not be necessary once https://youtrack.jetbrains.com/issue/KT-45777 lands - this.moduleName.set(kotlinCompile.moduleName.map { "$it-ksp" }) kotlinCompile as KotlinCompile val providerFactory = kotlinCompile.project.providers compileKotlinArgumentsContributor.set( @@ -608,7 +630,7 @@ abstract class KspTaskJvm @Inject constructor( // Overrding an internal function is hacky. // TODO: Ask upstream to open it. @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_PARAMETER_TYPE") - fun `callCompilerAsync$kotlin_gradle_plugin`( + fun `callCompilerAsync$kotlin_gradle_plugin_common`( args: K2JVMCompilerArguments, kotlinSources: Set, inputChanges: InputChanges, @@ -678,7 +700,6 @@ abstract class KspTaskJS @Inject constructor( kotlinCompilation: KotlinCompilationData<*>, kotlinCompile: AbstractKotlinCompile<*>, ) { - Configurator(kotlinCompilation).configure(this) kotlinCompile as Kotlin2JsCompile kotlinOptions.freeCompilerArgs = kotlinCompile.kotlinOptions.freeCompilerArgs.filter { it in backendSelectionArgs @@ -728,7 +749,7 @@ abstract class KspTaskJS @Inject constructor( // Overrding an internal function is hacky. // TODO: Ask upstream to open it. @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_PARAMETER_TYPE") - fun `callCompilerAsync$kotlin_gradle_plugin`( + fun `callCompilerAsync$kotlin_gradle_plugin_common`( args: K2JSCompilerArguments, kotlinSources: Set, inputChanges: InputChanges, @@ -745,8 +766,9 @@ abstract class KspTaskJS @Inject constructor( // Overrding an internal function is hacky. // TODO: Ask upstream to open it. + @Internal @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_PARAMETER_TYPE") - fun `isIncrementalCompilationEnabled$kotlin_gradle_plugin`(): Boolean = false + fun `isIncrementalCompilationEnabled$kotlin_gradle_plugin_common`(): Boolean = false @get:InputFiles @get:SkipWhenEmpty @@ -766,7 +788,6 @@ abstract class KspTaskMetadata @Inject constructor( kotlinCompilation: KotlinCompilationData<*>, kotlinCompile: AbstractKotlinCompile<*>, ) { - Configurator(kotlinCompilation).configure(this) kotlinCompile as KotlinCompileCommon val providerFactory = kotlinCompile.project.providers compileKotlinArgumentsContributor.set( @@ -817,7 +838,7 @@ abstract class KspTaskMetadata @Inject constructor( // Overrding an internal function is hacky. // TODO: Ask upstream to open it. @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_PARAMETER_TYPE") - fun `callCompilerAsync$kotlin_gradle_plugin`( + fun `callCompilerAsync$kotlin_gradle_plugin_common`( args: K2MetadataCompilerArguments, kotlinSources: Set, inputChanges: InputChanges, diff --git a/gradle.properties b/gradle.properties index 5c2913ae70..8fd7d56235 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Copied from kotlinc org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx2200m -Dfile.encoding=UTF-8 -kotlinBaseVersion=1.7.0-dev-3025 +kotlinBaseVersion=1.7.0-Beta agpBaseVersion=7.0.0 intellijVersion=203.8084.24 junitVersion=4.12 diff --git a/settings.gradle.kts b/settings.gradle.kts index a3d93ae479..bde918d158 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,12 +5,8 @@ pluginManagement { maven("https://www.jetbrains.com/intellij-repository/snapshots") } val kotlinBaseVersion: String by settings - resolutionStrategy { - eachPlugin { - if (requested.id.id == "org.jetbrains.kotlin.jvm") { - useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinBaseVersion") - } - } + plugins { + id("org.jetbrains.kotlin.jvm") version kotlinBaseVersion } } diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/SealedClassProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/SealedClassProcessor.kt index b5b887d156..073474a197 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/SealedClassProcessor.kt +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/SealedClassProcessor.kt @@ -31,7 +31,7 @@ class SealedClassProcessor : AbstractTestProcessor() { resolver.getNewFiles().forEach { f -> f.declarations.forEach { if (it is KSClassDeclaration) { - val subs = it.getSealedSubclasses().map { it.simpleName.asString() }.toList() + val subs = it.getSealedSubclasses().map { it.simpleName.asString() }.toList().sorted() result.add("${it.simpleName.asString()} : $subs") } } diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/testutils/AbstractKSPTest.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/testutils/AbstractKSPTest.kt index 55f62d4060..79af3685f0 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/testutils/AbstractKSPTest.kt +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/testutils/AbstractKSPTest.kt @@ -40,16 +40,10 @@ import org.jetbrains.kotlin.test.model.FrontendKind import org.jetbrains.kotlin.test.model.ResultingArtifact import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerTest -import org.jetbrains.kotlin.test.services.JUnit5Assertions -import org.jetbrains.kotlin.test.services.KotlinTestInfo -import org.jetbrains.kotlin.test.services.TemporaryDirectoryManager -import org.jetbrains.kotlin.test.services.TestServices -import org.jetbrains.kotlin.test.services.compilerConfigurationProvider +import org.jetbrains.kotlin.test.services.* import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator import org.jetbrains.kotlin.test.services.impl.TemporaryDirectoryManagerImpl -import org.jetbrains.kotlin.test.services.isKtFile -import org.jetbrains.kotlin.test.services.javaFiles import org.jetbrains.kotlin.test.util.KtTestUtil import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions