Skip to content

Commit

Permalink
[Wasm] Get back D8RootExtension as deprecated one, and per-project va…
Browse files Browse the repository at this point in the history
…riant is only envSpec
  • Loading branch information
ilgonmic authored and teamcity committed Sep 24, 2024
1 parent 9704f0c commit 943834f
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJ
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.d8.D8Plugin> {
// 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<org.jetbrains.kotlin.gradle.targets.js.d8.D8Extension>().version = (version as String)
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension>().version = (version as String)
}

allprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJ
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.d8.D8Plugin> {
// 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<org.jetbrains.kotlin.gradle.targets.js.d8.D8Extension>().version = (version as String)
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension>().version = (version as String)
}

allprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> ()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;
}
Expand All @@ -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 <init> (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;
Expand All @@ -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 <init> (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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -74,6 +77,9 @@ abstract class D8EnvSpec : EnvSpec<D8Env>() {
}
}

val Project.d8SetupTaskProvider: TaskProvider<out D8SetupTask>
get() = project.tasks.withType(D8SetupTask::class.java).named(D8SetupTask.NAME)

companion object {
const val EXTENSION_NAME: String = "kotlinD8Spec"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@ open class D8Exec : AbstractExecTask<D8Exec>(D8Exec::class.java) {
fun create(
compilation: KotlinJsIrCompilation,
name: String,
configuration: D8Exec.() -> Unit = {}
configuration: D8Exec.() -> Unit = {},
): TaskProvider<D8Exec> {
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()
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,14 +26,18 @@ open class D8Plugin : Plugin<Project> {

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>(D8SetupTask.NAME, listOf(spec)) {
it.group = TASKS_GROUP_NAME
Expand All @@ -59,7 +63,7 @@ open class D8Plugin : Plugin<Project> {
}

private fun D8EnvSpec.initializeD8EnvSpec(
d8: D8Extension,
d8: D8RootExtension,
) {
download.convention(d8.downloadProperty)
downloadBaseUrl.convention(d8.downloadBaseUrlProperty)
Expand All @@ -74,13 +78,23 @@ open class D8Plugin : Plugin<Project> {

// 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()
}
}
Original file line number Diff line number Diff line change
@@ -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
open class D8RootExtension(
@Transient val project: Project,
private val d8EnvSpec: D8EnvSpec,
) : AbstractSettings<D8Env>() {

private val gradleHome = project.gradle.gradleUserHomeDir.also {
project.logger.kotlinInfo("Storing cached files in $it")
}

override val downloadProperty: org.gradle.api.provider.Property<Boolean> = project.objects.property<Boolean>()
.convention(true)

// value not convention because this property can be nullable to not add repository
override val downloadBaseUrlProperty: org.gradle.api.provider.Property<String> = project.objects.property<String>()
.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<String> = project.objects.property<String>()
.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<String> = project.objects.property<String>()
.convention("rel")

override val commandProperty: org.gradle.api.provider.Property<String> = project.objects.property<String>()
.convention("d8")

override fun finalizeConfiguration(): D8Env {
return d8EnvSpec.produceEnv(project.providers).get()
}

val setupTaskProvider: TaskProvider<out D8SetupTask>
get() = with(d8EnvSpec) {
project.d8SetupTaskProvider
}

companion object {
const val EXTENSION_NAME: String = "kotlinD8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Directory> = compilation.npmProject.dir

Expand Down

0 comments on commit 943834f

Please sign in to comment.