From 943834f6111dca7250e6fe541bee11020e938bfc Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Fri, 20 Sep 2024 14:14:52 +0200 Subject: [PATCH] [Wasm] Get back D8RootExtension as deprecated one, and per-project variant is only envSpec --- .../build.gradle.kts | 2 +- .../build.gradle.kts | 2 +- .../api/all/kotlin-gradle-plugin.api | 31 ++++----- .../kotlin/gradle/targets/js/d8/D8EnvSpec.kt | 6 ++ .../kotlin/gradle/targets/js/d8/D8Exec.kt | 10 +-- .../gradle/targets/js/d8/D8Extension.kt | 63 ------------------- .../kotlin/gradle/targets/js/d8/D8Plugin.kt | 38 +++++++---- .../gradle/targets/js/d8/D8RootExtension.kt | 61 ++++++++++++++++-- .../kotlin/gradle/targets/js/ir/KotlinD8Ir.kt | 6 +- .../gradle/targets/js/testing/KotlinWasmD8.kt | 4 +- 10 files changed, 118 insertions(+), 105 deletions(-) delete mode 100644 libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Extension.kt diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-wasm-wasi-js-test/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-wasm-wasi-js-test/build.gradle.kts index 01f933672dd30..c098664829804 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-wasm-wasi-js-test/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-wasm-wasi-js-test/build.gradle.kts @@ -14,7 +14,7 @@ rootProject.plugins.withType { // Test that we can set the version and it is a String. // But use the default version since update this place every time anyway. - rootProject.the().version = (version as String) + rootProject.the().version = (version as String) } allprojects { diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/wasm-wasi-js-with-wasi-only-dependency/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/wasm-wasi-js-with-wasi-only-dependency/build.gradle.kts index 01f933672dd30..c098664829804 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/wasm-wasi-js-with-wasi-only-dependency/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/wasm-wasi-js-with-wasi-only-dependency/build.gradle.kts @@ -14,7 +14,7 @@ rootProject.plugins.withType { // Test that we can set the version and it is a String. // But use the default version since update this place every time anyway. - rootProject.the().version = (version as String) + rootProject.the().version = (version as String) } allprojects { diff --git a/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api b/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api index 69b5e10daf88e..33cef2e3dd104 100644 --- a/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api +++ b/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api @@ -3339,6 +3339,7 @@ public abstract class org/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec : org/ public static final field Companion Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec$Companion; public static final field EXTENSION_NAME Ljava/lang/String; public fun ()V + public final fun getD8SetupTaskProvider (Lorg/gradle/api/Project;)Lorg/gradle/api/tasks/TaskProvider; public abstract fun getEdition ()Lorg/gradle/api/provider/Property; public abstract fun getVersion ()Lorg/gradle/api/provider/Property; } @@ -3360,20 +3361,6 @@ public final class org/jetbrains/kotlin/gradle/targets/js/d8/D8Exec$Companion { public static synthetic fun create$default (Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8Exec$Companion;Lorg/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrCompilation;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/gradle/api/tasks/TaskProvider; } -public class org/jetbrains/kotlin/gradle/targets/js/d8/D8Extension : org/jetbrains/kotlin/gradle/targets/js/AbstractSettings { - public static final field Companion Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8Extension$Companion; - public static final field EXTENSION_NAME Ljava/lang/String; - public fun (Lorg/gradle/api/Project;Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec;)V - public synthetic fun finalizeConfiguration ()Ljava/lang/Object; - protected fun finalizeConfiguration ()Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8Env; - public final fun getEdition ()Lorg/gradle/api/provider/Property; - public final fun getProject ()Lorg/gradle/api/Project; - public final fun getSetupTaskProvider ()Lorg/gradle/api/tasks/TaskProvider; -} - -public final class org/jetbrains/kotlin/gradle/targets/js/d8/D8Extension$Companion { -} - public class org/jetbrains/kotlin/gradle/targets/js/d8/D8Plugin : org/gradle/api/Plugin { public static final field Companion Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8Plugin$Companion; public static final field TASKS_GROUP_NAME Ljava/lang/String; @@ -3383,7 +3370,21 @@ public class org/jetbrains/kotlin/gradle/targets/js/d8/D8Plugin : org/gradle/api } public final class org/jetbrains/kotlin/gradle/targets/js/d8/D8Plugin$Companion { - public final fun apply (Lorg/gradle/api/Project;)Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8Extension; + public final fun apply (Lorg/gradle/api/Project;)Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8RootExtension; +} + +public class org/jetbrains/kotlin/gradle/targets/js/d8/D8RootExtension : org/jetbrains/kotlin/gradle/targets/js/AbstractSettings { + public static final field Companion Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8RootExtension$Companion; + public static final field EXTENSION_NAME Ljava/lang/String; + public fun (Lorg/gradle/api/Project;Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec;)V + public synthetic fun finalizeConfiguration ()Ljava/lang/Object; + protected fun finalizeConfiguration ()Lorg/jetbrains/kotlin/gradle/targets/js/d8/D8Env; + public final fun getEdition ()Lorg/gradle/api/provider/Property; + public final fun getProject ()Lorg/gradle/api/Project; + public final fun getSetupTaskProvider ()Lorg/gradle/api/tasks/TaskProvider; +} + +public final class org/jetbrains/kotlin/gradle/targets/js/d8/D8RootExtension$Companion { } public abstract class org/jetbrains/kotlin/gradle/targets/js/d8/D8SetupTask : org/jetbrains/kotlin/gradle/targets/js/AbstractSetupTask { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec.kt index 788ac561878f3..3109a3c86e592 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec.kt @@ -5,10 +5,13 @@ package org.jetbrains.kotlin.gradle.targets.js.d8 +import org.gradle.api.Project import org.gradle.api.provider.Provider import org.gradle.api.provider.ProviderFactory +import org.gradle.api.tasks.TaskProvider import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.js.EnvSpec +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsSetupTask import org.jetbrains.kotlin.gradle.tasks.internal.CleanableStore import org.jetbrains.kotlin.gradle.utils.getFile @@ -74,6 +77,9 @@ abstract class D8EnvSpec : EnvSpec() { } } + val Project.d8SetupTaskProvider: TaskProvider + get() = project.tasks.withType(D8SetupTask::class.java).named(D8SetupTask.NAME) + companion object { const val EXTENSION_NAME: String = "kotlinD8Spec" } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Exec.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Exec.kt index 438fdf1b4b2ee..e17a5e2fe829f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Exec.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Exec.kt @@ -55,16 +55,18 @@ open class D8Exec : AbstractExecTask(D8Exec::class.java) { fun create( compilation: KotlinJsIrCompilation, name: String, - configuration: D8Exec.() -> Unit = {} + configuration: D8Exec.() -> Unit = {}, ): TaskProvider { val target = compilation.target val project = target.project - val d8 = D8Plugin.apply(project) + val d8 = D8Plugin.applyWithEnvSpec(project) return project.registerTask( name ) { - it.executable = d8.d8EnvSpec.produceEnv(project.providers).get().executable - it.dependsOn(d8.setupTaskProvider) + it.executable = d8.produceEnv(project.providers).get().executable + with(d8) { + it.dependsOn(project.d8SetupTaskProvider) + } it.dependsOn(compilation.compileTaskProvider) it.configuration() } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Extension.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Extension.kt deleted file mode 100644 index f9fbd2578c193..0000000000000 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Extension.kt +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.gradle.targets.js.d8 - -import org.gradle.api.Project -import org.gradle.api.file.DirectoryProperty -import org.gradle.api.tasks.TaskProvider -import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl -import org.jetbrains.kotlin.gradle.logging.kotlinInfo -import org.jetbrains.kotlin.gradle.targets.js.AbstractSettings -import org.jetbrains.kotlin.gradle.utils.property - -@OptIn(ExperimentalWasmDsl::class) -open class D8Extension( - @Transient val project: Project, - internal val d8EnvSpec: D8EnvSpec, -) : AbstractSettings() { - - private val gradleHome = project.gradle.gradleUserHomeDir.also { - project.logger.kotlinInfo("Storing cached files in $it") - } - - override val downloadProperty: org.gradle.api.provider.Property = project.objects.property() - .convention(true) - - // value not convention because this property can be nullable to not add repository - override val downloadBaseUrlProperty: org.gradle.api.provider.Property = project.objects.property() - .value("https://storage.googleapis.com/chromium-v8/official/canary") - - override val installationDirectory: DirectoryProperty = project.objects.directoryProperty() - .fileValue(gradleHome.resolve("d8")) - - /** - * The same as in [D8EnvSpec.version] - */ - override val versionProperty: org.gradle.api.provider.Property = project.objects.property() - .convention("11.9.85") - - /** - * Specify the edition of the D8. - * - * Valid options for bundled version are `rel` (release variant) and `dbg` (debug variant). - */ - val edition: org.gradle.api.provider.Property = project.objects.property() - .convention("rel") - - override val commandProperty: org.gradle.api.provider.Property = project.objects.property() - .convention("d8") - - val setupTaskProvider: TaskProvider - get() = project.tasks.withType(D8SetupTask::class.java).named(D8SetupTask.NAME) - - override fun finalizeConfiguration(): D8Env { - return d8EnvSpec.produceEnv(project.providers).get() - } - - companion object { - const val EXTENSION_NAME: String = "kotlinD8" - } -} diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Plugin.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Plugin.kt index 139d047032e5a..9249ba3dd1cef 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Plugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8Plugin.kt @@ -12,7 +12,7 @@ import org.gradle.api.plugins.ExtensionContainer import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.targets.js.MultiplePluginDeclarationDetector -import org.jetbrains.kotlin.gradle.targets.js.d8.D8Extension.Companion.EXTENSION_NAME +import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension.Companion.EXTENSION_NAME import org.jetbrains.kotlin.gradle.tasks.CleanDataTask import org.jetbrains.kotlin.gradle.tasks.registerTask import org.jetbrains.kotlin.gradle.utils.castIsolatedKotlinPluginClassLoaderAware @@ -26,14 +26,18 @@ open class D8Plugin : Plugin { val spec = project.extensions.createD8EnvSpec() - val settings = project.extensions.create( - EXTENSION_NAME, - D8Extension::class.java, - project, - spec - ) + if (project == project.rootProject) { + project.extensions.create( + EXTENSION_NAME, + D8RootExtension::class.java, + project, + spec + ) + } - spec.initializeD8EnvSpec(settings) + val d8RootExtension = applyRootProject(project.rootProject) + + spec.initializeD8EnvSpec(d8RootExtension) project.registerTask(D8SetupTask.NAME, listOf(spec)) { it.group = TASKS_GROUP_NAME @@ -59,7 +63,7 @@ open class D8Plugin : Plugin { } private fun D8EnvSpec.initializeD8EnvSpec( - d8: D8Extension, + d8: D8RootExtension, ) { download.convention(d8.downloadProperty) downloadBaseUrl.convention(d8.downloadBaseUrlProperty) @@ -74,13 +78,23 @@ open class D8Plugin : Plugin { // To prevent Kotlin build from failing (due to `-Werror`), only internalize after upgrade of bootstrap version // @InternalKotlinGradlePluginApi - fun apply(project: Project): D8Extension { + fun apply(project: Project): D8RootExtension { + project.plugins.apply(D8Plugin::class.java) + return project.extensions.getByName(EXTENSION_NAME) as D8RootExtension + } + + internal fun applyWithEnvSpec(project: Project): D8EnvSpec { project.plugins.apply(D8Plugin::class.java) - return project.extensions.getByName(EXTENSION_NAME) as D8Extension + return project.extensions.getByName(D8EnvSpec.EXTENSION_NAME) as D8EnvSpec + } + + private fun applyRootProject(project: Project): D8RootExtension { + project.rootProject.plugins.apply(D8Plugin::class.java) + return project.rootProject.extensions.getByName(EXTENSION_NAME) as D8RootExtension } @InternalKotlinGradlePluginApi - val Project.kotlinD8Extension: D8Extension + val Project.kotlinD8RootExtension: D8RootExtension get() = extensions.getByName(EXTENSION_NAME).castIsolatedKotlinPluginClassLoaderAware() } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8RootExtension.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8RootExtension.kt index f511d7928da01..8659f5b398547 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8RootExtension.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/d8/D8RootExtension.kt @@ -1,14 +1,65 @@ /* - * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.gradle.targets.js.d8 +import org.gradle.api.Project +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.tasks.TaskProvider import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.logging.kotlinInfo +import org.jetbrains.kotlin.gradle.targets.js.AbstractSettings +import org.jetbrains.kotlin.gradle.utils.property -// To be compatible with previous KGP version, we need to keep D8RootExtension as deprecated. -// To prevent Kotlin build from failing (due to `-Werror`), only deprecate after upgrade of bootstrap version -//@Deprecated("This extension is deprecated. Use D8Extension instead.", ReplaceWith("D8Extension")) @OptIn(ExperimentalWasmDsl::class) -typealias D8RootExtension = D8Extension \ No newline at end of file +open class D8RootExtension( + @Transient val project: Project, + private val d8EnvSpec: D8EnvSpec, +) : AbstractSettings() { + + private val gradleHome = project.gradle.gradleUserHomeDir.also { + project.logger.kotlinInfo("Storing cached files in $it") + } + + override val downloadProperty: org.gradle.api.provider.Property = project.objects.property() + .convention(true) + + // value not convention because this property can be nullable to not add repository + override val downloadBaseUrlProperty: org.gradle.api.provider.Property = project.objects.property() + .value("https://storage.googleapis.com/chromium-v8/official/canary") + + override val installationDirectory: DirectoryProperty = project.objects.directoryProperty() + .fileValue(gradleHome.resolve("d8")) + + /** + * The same as in [D8EnvSpec.version] + */ + override val versionProperty: org.gradle.api.provider.Property = project.objects.property() + .convention("11.9.85") + + /** + * Specify the edition of the D8. + * + * Valid options for bundled version are `rel` (release variant) and `dbg` (debug variant). + */ + val edition: org.gradle.api.provider.Property = project.objects.property() + .convention("rel") + + override val commandProperty: org.gradle.api.provider.Property = project.objects.property() + .convention("d8") + + override fun finalizeConfiguration(): D8Env { + return d8EnvSpec.produceEnv(project.providers).get() + } + + val setupTaskProvider: TaskProvider + get() = with(d8EnvSpec) { + project.d8SetupTaskProvider + } + + companion object { + const val EXTENSION_NAME: String = "kotlinD8" + } +} diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinD8Ir.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinD8Ir.kt index 2cc7a1a4206f0..7e68dd0ea26f7 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinD8Ir.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinD8Ir.kt @@ -21,7 +21,7 @@ abstract class KotlinD8Ir @Inject constructor(target: KotlinJsIrTarget) : KotlinJsIrSubTargetBase(target, "d8"), KotlinWasmD8Dsl { - private val d8 = D8Plugin.apply(project) + private val d8 = D8Plugin.applyWithEnvSpec(project) override val testTaskDescription: String get() = "Run all ${target.name} tests inside d8 using the builtin test framework" @@ -48,6 +48,8 @@ abstract class KotlinD8Ir @Inject constructor(target: KotlinJsIrTarget) : } override fun configureTestDependencies(test: KotlinJsTest) { - test.dependsOn(d8.setupTaskProvider) + with(d8) { + test.dependsOn(project.d8SetupTaskProvider) + } } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/testing/KotlinWasmD8.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/testing/KotlinWasmD8.kt index 1ed77cad3901a..469a1bab14dec 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/testing/KotlinWasmD8.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/testing/KotlinWasmD8.kt @@ -27,8 +27,8 @@ internal class KotlinWasmD8(kotlinJsTest: KotlinJsTest) : KotlinJsTestFramework @Transient override val compilation: KotlinJsIrCompilation = kotlinJsTest.compilation - private val d8 = D8Plugin.apply(kotlinJsTest.project) - private val d8Executable = d8.d8EnvSpec.produceEnv(compilation.project.providers).map { it.executable } + private val d8 = D8Plugin.applyWithEnvSpec(kotlinJsTest.project) + private val d8Executable = d8.produceEnv(compilation.project.providers).map { it.executable } override val workingDir: Provider = compilation.npmProject.dir