Skip to content

Commit

Permalink
[Wasm] EnvSpec has executable provider and env instead of produceEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgonmic authored and qodana-bot committed Nov 19, 2024
1 parent a1c1fb2 commit 496ac4c
Show file tree
Hide file tree
Showing 27 changed files with 76 additions and 48 deletions.
3 changes: 1 addition & 2 deletions js/js.tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import com.github.gradle.node.npm.task.NpmTask
import com.github.gradle.node.variant.computeNodeExec
import org.apache.tools.ant.filters.FixCrLfFilter
import org.jetbrains.kotlin.build.d8.D8Extension
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute
Expand Down Expand Up @@ -214,7 +213,7 @@ fun Test.setupNodeJs() {
}

fun Test.setUpJsBoxTests(tags: String?) {
with(project.the<D8Extension>()) {
with(d8KotlinBuild) {
setupV8()
}

Expand Down
3 changes: 1 addition & 2 deletions js/js.tests/klib-compatibility/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.jetbrains.kotlin.build.d8.D8Extension
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute

plugins {
Expand Down Expand Up @@ -48,7 +47,7 @@ sourceSets {
testsJar {}

fun Test.setUpJsBoxTests() {
with(project.the<D8Extension>()) {
with(d8KotlinBuild) {
setupV8()
}
dependsOn(":dist")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3027,9 +3027,10 @@ public abstract class org/jetbrains/kotlin/gradle/targets/js/EnvSpec {
public abstract fun getCommand ()Lorg/gradle/api/provider/Property;
public abstract fun getDownload ()Lorg/gradle/api/provider/Property;
public abstract fun getDownloadBaseUrl ()Lorg/gradle/api/provider/Property;
public abstract fun getExecutable ()Lorg/gradle/api/provider/Provider;
public abstract fun getInstallationDirectory ()Lorg/gradle/api/file/DirectoryProperty;
public abstract fun getVersion ()Lorg/gradle/api/provider/Property;
public abstract fun produceEnv (Lorg/gradle/api/provider/ProviderFactory;)Lorg/gradle/api/provider/Provider;
protected abstract fun produceEnv ()Lorg/gradle/api/provider/Provider;
}

public final class org/jetbrains/kotlin/gradle/targets/js/JsAggregatingExecutionSource : org/jetbrains/kotlin/gradle/execution/KotlinAggregateExecutionSource {
Expand Down Expand Up @@ -3243,7 +3244,8 @@ public abstract class org/jetbrains/kotlin/gradle/targets/js/binaryen/BinaryenRo
public static final field Companion Lorg/jetbrains/kotlin/gradle/targets/js/binaryen/BinaryenRootEnvSpec$Companion;
public static final field EXTENSION_NAME Ljava/lang/String;
public fun <init> ()V
public fun produceEnv (Lorg/gradle/api/provider/ProviderFactory;)Lorg/gradle/api/provider/Provider;
public fun getExecutable ()Lorg/gradle/api/provider/Provider;
protected final fun produceEnv ()Lorg/gradle/api/provider/Provider;
}

public final class org/jetbrains/kotlin/gradle/targets/js/binaryen/BinaryenRootEnvSpec$Companion {
Expand Down Expand Up @@ -3317,8 +3319,9 @@ public abstract class org/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec : org/
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 fun getExecutable ()Lorg/gradle/api/provider/Provider;
public abstract fun getVersion ()Lorg/gradle/api/provider/Property;
public fun produceEnv (Lorg/gradle/api/provider/ProviderFactory;)Lorg/gradle/api/provider/Provider;
protected final fun produceEnv ()Lorg/gradle/api/provider/Provider;
}

public final class org/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec$Companion {
Expand Down Expand Up @@ -4121,8 +4124,9 @@ public abstract class org/jetbrains/kotlin/gradle/targets/js/nodejs/NodeJsEnvSpe
public static final field Companion Lorg/jetbrains/kotlin/gradle/targets/js/nodejs/NodeJsEnvSpec$Companion;
public static final field EXTENSION_NAME Ljava/lang/String;
public fun <init> ()V
public fun getExecutable ()Lorg/gradle/api/provider/Provider;
public final fun getNodeJsSetupTaskProvider (Lorg/gradle/api/Project;)Lorg/gradle/api/tasks/TaskProvider;
public fun produceEnv (Lorg/gradle/api/provider/ProviderFactory;)Lorg/gradle/api/provider/Provider;
protected final fun produceEnv ()Lorg/gradle/api/provider/Provider;
}

public final class org/jetbrains/kotlin/gradle/targets/js/nodejs/NodeJsEnvSpec$Companion {
Expand Down Expand Up @@ -5859,12 +5863,13 @@ public abstract class org/jetbrains/kotlin/gradle/targets/js/yarn/YarnRootEnvSpe
public static final field Companion Lorg/jetbrains/kotlin/gradle/targets/js/yarn/YarnRootEnvSpec$Companion;
public static final field YARN Ljava/lang/String;
public fun <init> ()V
public fun getExecutable ()Lorg/gradle/api/provider/Provider;
public abstract fun getIgnoreScripts ()Lorg/gradle/api/provider/Property;
public abstract fun getReportNewYarnLock ()Lorg/gradle/api/provider/Property;
public abstract fun getResolutions ()Lorg/gradle/api/provider/ListProperty;
public abstract fun getYarnLockAutoReplace ()Lorg/gradle/api/provider/Property;
public abstract fun getYarnLockMismatchReport ()Lorg/gradle/api/provider/Property;
public fun produceEnv (Lorg/gradle/api/provider/ProviderFactory;)Lorg/gradle/api/provider/Provider;
protected final fun produceEnv ()Lorg/gradle/api/provider/Provider;
}

public final class org/jetbrains/kotlin/gradle/targets/js/yarn/YarnRootEnvSpec$Companion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnEnv

/**
* Instance which describes specific runtimes for JS and Wasm targets
*
* It encapsulates necessary information about a tool to run application and tests
*/
abstract class EnvSpec<T> {
abstract class EnvSpec<T : AbstractEnv> {

/**
* Specify whether we need to download the tool
Expand Down Expand Up @@ -40,8 +41,18 @@ abstract class EnvSpec<T> {
*/
abstract val command: Property<String>

/**
* Full serializable cache-friendly entity without Gradle Provider API
*/
internal abstract val env: Provider<T>

/**
* Provider with full executable path
*/
abstract val executable: Provider<String>

/**
* Produce full serializable cache-friendly entity without Gradle Provider API
*/
abstract fun produceEnv(providerFactory: ProviderFactory): Provider<T>
protected abstract fun produceEnv(): Provider<T>
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class AbstractSetupTask<Env : AbstractEnv, Spec : EnvSpec<Env>>(
protected abstract val artifactName: String

@get:Internal
protected val env: Provider<Env> = spec.produceEnv(project.providers)
protected val env: Provider<Env> = spec.env

private val shouldDownload: Provider<Boolean> = env.map { it.download }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.EnvSpec
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsEnv
import org.jetbrains.kotlin.gradle.tasks.internal.CleanableStore
import org.jetbrains.kotlin.gradle.utils.getFile

Expand All @@ -24,9 +25,12 @@ abstract class BinaryenRootEnvSpec : EnvSpec<BinaryenEnv>() {
*/
internal abstract val platform: Property<BinaryenPlatform>

override fun produceEnv(providerFactory: ProviderFactory): Provider<BinaryenEnv> {
return providerFactory.provider {
val versionValue = version.get()
final override val env: Provider<BinaryenEnv> = produceEnv()

override val executable: Provider<String> = env.map { it.executable }

final override fun produceEnv(): Provider<BinaryenEnv> {
return version.map { versionValue ->
val requiredVersionName = "binaryen-version_$versionValue"
val cleanableStore = CleanableStore[installationDirectory.getFile().absolutePath]
val targetPath = cleanableStore[requiredVersionName].use()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ open class BinaryenRootExtension(
internal val platform: org.gradle.api.provider.Property<BinaryenPlatform> = rootProject.objects.property<BinaryenPlatform>()

override fun finalizeConfiguration(): BinaryenEnv {
return binaryenSpec.produceEnv(rootProject.providers).get()
return binaryenSpec.env.get()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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.binaryen.BinaryenEnv
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 @@ -45,9 +46,13 @@ abstract class D8EnvSpec : EnvSpec<D8Env>() {
*/
abstract val edition: org.gradle.api.provider.Property<String>

override fun produceEnv(providerFactory: ProviderFactory): Provider<D8Env> {
return providerFactory.provider {
val requiredVersion = "${D8Platform.platform}-${edition.get()}-${version.get()}"
final override val env: Provider<D8Env> = produceEnv()

override val executable: Provider<String> = env.map { it.executable }

final override fun produceEnv(): Provider<D8Env> {
return edition.map { editionValue ->
val requiredVersion = "${D8Platform.platform}-$editionValue-${version.get()}"
val requiredVersionName = "v8-$requiredVersion"
val cleanableStore = CleanableStore[installationDirectory.getFile().absolutePath]
val targetPath = cleanableStore[requiredVersionName].use()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ open class D8Exec : AbstractExecTask<D8Exec>(D8Exec::class.java) {
return project.registerTask(
name
) {
it.executable = d8.produceEnv(project.providers).get().executable
it.executable = d8.executable.get()
with(d8) {
it.dependsOn(project.d8SetupTaskProvider)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ open class D8Plugin : Plugin<Project> {
}

project.registerTask<CleanDataTask>("d8" + CleanDataTask.NAME_SUFFIX) {
it.cleanableStoreProvider = spec.produceEnv(project.providers).map { it.cleanableStore }
it.cleanableStoreProvider = spec.env.map { it.cleanableStore }
it.group = TASKS_GROUP_NAME
it.description = "Clean unused local d8 version"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ open class D8RootExtension(
.convention("d8")

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

val setupTaskProvider: TaskProvider<out D8SetupTask>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ abstract class NodeJsEnvSpec : EnvSpec<NodeJsEnv>() {
*/
internal abstract val platform: org.gradle.api.provider.Property<Platform>

override fun produceEnv(providerFactory: ProviderFactory): Provider<NodeJsEnv> {
return providerFactory.provider {
val platformValue = platform.get()
final override val env: Provider<NodeJsEnv> = produceEnv()

override val executable: Provider<String> = env.map { it.executable }

final override fun produceEnv(): Provider<NodeJsEnv> {
return platform.map { platformValue ->
val name = platformValue.name
val architecture = platformValue.arch

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ constructor(
listOf(compilation)
) {
it.nodeJsRoot = nodeJsRoot
it.executable = nodeJs.produceEnv(project.providers).get().executable
it.executable = nodeJs.executable.get()
if ((compilation.target as? KotlinJsIrTarget)?.wasmTargetType != KotlinWasmTargetType.WASI) {
it.workingDir(npmProject.dir)
it.dependsOn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ open class NodeJsRootExtension(

@Deprecated("Use NodeJsEnvSpec instead. This will be removed in 2.2")
fun requireConfigured(): NodeJsEnv {
return nodeJs().produceEnv(project.providers).get()
return nodeJs().env.get()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ open class NodeJsRootPlugin : Plugin<Project> {
val nodeJs = NodeJsPlugin.apply(project)

npm.nodeJsEnvironment.value(
nodeJs.produceEnv(project.providers)
nodeJs.env
).disallowChanges()

nodeJsRoot.packageManagerExtension.convention(
Expand Down Expand Up @@ -234,7 +234,7 @@ open class NodeJsRootPlugin : Plugin<Project> {
}

project.tasks.register("node" + CleanDataTask.NAME_SUFFIX, CleanDataTask::class.java) {
it.cleanableStoreProvider = nodeJs.produceEnv(project.providers).map { it.cleanableStore }
it.cleanableStoreProvider = nodeJs.env.map { it.cleanableStore }
it.group = TASKS_GROUP_NAME
it.description = "Clean unused local node version"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ open class NpmProject(@Transient val compilation: KotlinJsIrCompilation) : Seria
}

private val nodeExecutable by lazy {
nodeJs.produceEnv(project.providers).get().executable
nodeJs.executable.get()
}

fun useTool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class KotlinNpmInstallTask :
// -----

private val nodsJsEnvironment by lazy {
asNodeJsEnvironment(nodeJsRoot, nodeJs.produceEnv(project.providers).get())
asNodeJsEnvironment(nodeJsRoot, nodeJs.env.get())
}

private val packageManagerEnv by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ abstract class RootPackageJsonTask :
// -----

private val nodeJsEnvironment by lazy {
asNodeJsEnvironment(nodeJsRoot, nodeJs.produceEnv(project.providers).get())
asNodeJsEnvironment(nodeJsRoot, nodeJs.env.get())
}

private val packageManagerEnv by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ constructor(
@Transient
private val nodeJs = project.kotlinNodeJsEnvSpec

private val nodeExecutable = nodeJs.produceEnv(project.providers).map { it.executable }
private val nodeExecutable = nodeJs.executable

@Input
var environment = mutableMapOf<String, String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class KotlinWasmD8(kotlinJsTest: KotlinJsTest) : KotlinJsTestFramework

override val workingDir: Provider<Directory> = projectLayout.dir(kotlinJsTest.inputFileProperty.asFile.map { it.parentFile })

override val executable: Provider<String> = d8.produceEnv(compilation.project.providers).map { it.executable }
override val executable: Provider<String> = d8.executable

override fun createTestExecutionSpec(
task: KotlinJsTest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class KotlinWasmNode(kotlinJsTest: KotlinJsTest) : KotlinJsTestFramewor
}
}

override val executable: Provider<String> = nodeJs.produceEnv(kotlinJsTest.project.providers).map { it.executable }
override val executable: Provider<String> = nodeJs.executable

override fun createTestExecutionSpec(
task: KotlinJsTest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class KotlinKarma(
override val workingDir: Provider<Directory>
get() = npmProjectDir

override val executable: Provider<String> = nodeJsEnvSpec.produceEnv(project.providers).map { it.executable }
override val executable: Provider<String> = nodeJsEnvSpec.executable

override fun getPath() = "$basePath:kotlinKarma"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class KotlinMocha(@Transient override val compilation: KotlinJsIrCompilation, pr
override val workingDir: Provider<Directory>
get() = npmProjectDir

override val executable: Provider<String> = nodeJs.produceEnv(project.providers).map { it.executable }
override val executable: Provider<String> = nodeJs.executable

override val settingsState: String
get() = "mocha"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ open class YarnPlugin : Plugin<Project> {
}

yarnRootExtension.nodeJsEnvironment.value(
nodeJs.produceEnv(project.providers)
nodeJs.env
).disallowChanges()

tasks.register("yarn" + CleanDataTask.NAME_SUFFIX, CleanDataTask::class.java) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.jetbrains.kotlin.gradle.targets.js.EnvSpec
import org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenEnv
import org.jetbrains.kotlin.gradle.targets.js.nodejs.Platform
import org.jetbrains.kotlin.gradle.tasks.internal.CleanableStore
import org.jetbrains.kotlin.gradle.utils.getFile
Expand Down Expand Up @@ -60,11 +61,15 @@ abstract class YarnRootEnvSpec : EnvSpec<YarnEnv>() {
*/
abstract val resolutions: ListProperty<YarnResolution>

override fun produceEnv(providerFactory: ProviderFactory): Provider<YarnEnv> {
return providerFactory.provider {
final override val env: Provider<YarnEnv> = produceEnv()

override val executable: Provider<String> = env.map { it.executable }

final override fun produceEnv(): Provider<YarnEnv> {
return platform.map { platformValue ->
val cleanableStore = CleanableStore[installationDirectory.getFile().path]

val isWindows = platform.get().isWindows()
val isWindows = platformValue.isWindows()

val home = cleanableStore["yarn-v${version.get()}"].use()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ open class YarnRootExtension(
internal val nodeJsEnvironment: org.gradle.api.provider.Property<NodeJsEnv> = project.objects.property(NodeJsEnv::class.java)

override fun finalizeConfiguration(): YarnEnv {
return yarnSpec.produceEnv(project.providers).get()
return yarnSpec.env.get()
}

val restoreYarnLockTaskProvider: TaskProvider<YarnLockCopyTask>
Expand Down
Loading

0 comments on commit 496ac4c

Please sign in to comment.