Skip to content

Commit

Permalink
[Wasm] Deprecate properties which are necessary to be deprecated afte…
Browse files Browse the repository at this point in the history
…r introducing EnvSpecs
  • Loading branch information
ilgonmic authored and qodana-bot committed Nov 19, 2024
1 parent 3e56c29 commit be7b03c
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 83 deletions.
24 changes: 17 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,13 +1147,18 @@ if (disableVerificationTasks) {

gradle.taskGraph.whenReady(checkYarnAndNPMSuppressed)

@Suppress("DEPRECATION")
plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class) {
extensions.configure(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class.java) {
if (kotlinBuildProperties.isCacheRedirectorEnabled) {
downloadBaseUrl = "https://cache-redirector.jetbrains.com/nodejs.org/dist"
allprojects {
plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlugin::class) {
extensions.configure(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsEnvSpec::class.java) {
if (kotlinBuildProperties.isCacheRedirectorEnabled) {
downloadBaseUrl = "https://cache-redirector.jetbrains.com/nodejs.org/dist"
}
}
}
}

plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class) {
extensions.configure(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class.java) {
npmInstallTaskProvider.configure {
args += listOf("--network-concurrency", "1", "--mutex", "network")
}
Expand All @@ -1171,9 +1176,14 @@ plugins.withType(com.github.gradle.node.NodePlugin::class) {
@Suppress("DEPRECATION")
afterEvaluate {
if (kotlinBuildProperties.isCacheRedirectorEnabled) {
allprojects {
plugins.withType(org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin::class.java) {
the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootEnvSpec>().downloadBaseUrl =
"https://cache-redirector.jetbrains.com/github.com/yarnpkg/yarn/releases/download"
}
}

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin::class.java) {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().downloadBaseUrl =
"https://cache-redirector.jetbrains.com/github.com/yarnpkg/yarn/releases/download"
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().yarnLockMismatchReport =
YarnLockMismatchReport.WARNING
}
Expand Down
1 change: 1 addition & 0 deletions compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ sourceSets {
}
}

useD8Plugin()
projectTest(
parallel = true,
defineJDKEnvVariables = listOf(JdkMajorVersion.JDK_1_8, JdkMajorVersion.JDK_11_0, JdkMajorVersion.JDK_17_0)
Expand Down
2 changes: 2 additions & 0 deletions compiler/fir/analysis-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ if (kotlinBuildProperties.isInJpsBuildIdeaSync) {
}
}

useD8Plugin()

projectTest(
jUnitMode = JUnitMode.JUnit5,
defineJDKEnvVariables = listOf(
Expand Down
2 changes: 2 additions & 0 deletions compiler/incremental-compilation-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ sourceSets {
"test" { projectDefault() }
}

useD8Plugin()

projectTest(parallel = true) {
workingDir = rootDir
useJsIrBoxTests(version = version, buildDir = layout.buildDirectory)
Expand Down
1 change: 1 addition & 0 deletions js/js.tests/klib-compatibility/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fun Test.setUpJsBoxTests() {
workingDir = rootDir
}

useD8Plugin()
projectTest(jUnitMode = JUnitMode.JUnit5) {
dependsOn(releasedCompilerDist)
systemProperty("kotlin.internal.js.test.latestReleasedCompilerLocation", releasedCompilerArtifactsTarget.get().asFile.absolutePath)
Expand Down
11 changes: 7 additions & 4 deletions libraries/stdlib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@file:Suppress("UNUSED_VARIABLE", "NAME_SHADOWING", "DEPRECATION")
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.GenerateProjectStructureMetadata
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootPlugin
import org.jetbrains.kotlin.gradle.targets.js.d8.D8Plugin
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinTargetWithNodeJsDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmTargetDsl
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
Expand Down Expand Up @@ -254,9 +255,6 @@ kotlin {
}
}

rootProject.plugins.apply(D8RootPlugin::class.java)
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension>().version = v8Version

fun KotlinWasmTargetDsl.commonWasmTargetConfiguration() {
(this as KotlinTargetWithNodeJsDsl).nodejs()
compilations {
Expand Down Expand Up @@ -597,6 +595,11 @@ kotlin {
}
}

plugins.apply(D8Plugin::class.java)

@OptIn(ExperimentalWasmDsl::class)
the<org.jetbrains.kotlin.gradle.targets.js.d8.D8EnvSpec>().version = v8Version

dependencies {
val jvmMainApi by configurations.getting
val metadataApiElements by configurations.getting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package org.jetbrains.kotlin.gradle

import org.gradle.api.Action
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsEnvSpec
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlugin
import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.test.TestMetadata
import org.junit.jupiter.api.DisplayName
Expand Down Expand Up @@ -72,8 +72,8 @@ class NodeJsGradlePluginIT : KGPBaseTest() {
) {
@Suppress("DEPRECATION")
buildScriptInjection {
project.rootProject.plugins.withType(NodeJsRootPlugin::class.java, Action {
project.rootProject.extensions.getByType(NodeJsRootExtension::class.java).version = "22.3.0"
project.rootProject.plugins.withType(NodeJsPlugin::class.java, Action {
project.rootProject.extensions.getByType(NodeJsEnvSpec::class.java).version.set("22.3.0")
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3029,6 +3029,7 @@ public abstract class org/jetbrains/kotlin/gradle/targets/js/EnvSpec {
public abstract fun getDownloadBaseUrl ()Lorg/gradle/api/provider/Property;
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;
}

public final class org/jetbrains/kotlin/gradle/targets/js/JsAggregatingExecutionSource : org/jetbrains/kotlin/gradle/execution/KotlinAggregateExecutionSource {
Expand Down Expand Up @@ -3242,6 +3243,7 @@ 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 final class org/jetbrains/kotlin/gradle/targets/js/binaryen/BinaryenRootEnvSpec$Companion {
Expand Down Expand Up @@ -3316,6 +3318,7 @@ public abstract class org/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec : org/
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;
public fun produceEnv (Lorg/gradle/api/provider/ProviderFactory;)Lorg/gradle/api/provider/Provider;
}

public final class org/jetbrains/kotlin/gradle/targets/js/d8/D8EnvSpec$Companion {
Expand Down Expand Up @@ -4119,6 +4122,7 @@ public abstract class org/jetbrains/kotlin/gradle/targets/js/nodejs/NodeJsEnvSpe
public static final field EXTENSION_NAME Ljava/lang/String;
public fun <init> ()V
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;
}

public final class org/jetbrains/kotlin/gradle/targets/js/nodejs/NodeJsEnvSpec$Companion {
Expand Down Expand Up @@ -5860,6 +5864,7 @@ public abstract class org/jetbrains/kotlin/gradle/targets/js/yarn/YarnRootEnvSpe
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;
}

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 @@ -43,5 +43,5 @@ abstract class EnvSpec<T> {
/**
* Produce full serializable cache-friendly entity without Gradle Provider API
*/
internal abstract fun produceEnv(providerFactory: ProviderFactory): Provider<T>
abstract fun produceEnv(providerFactory: ProviderFactory): Provider<T>
}
2 changes: 2 additions & 0 deletions plugins/js-plain-objects/compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ sourcesJar()
javadocJar()
testsJar()

useD8Plugin()

projectTest(parallel = true, jUnitMode = JUnitMode.JUnit5) {
useJUnitPlatform()
useJsIrBoxTests(version = version, buildDir = layout.buildDirectory)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenRootExtension
import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenRootEnvSpec
import org.jetbrains.kotlin.gradle.targets.js.d8.D8EnvSpec
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsEnvSpec
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootEnvSpec
import org.spdx.sbom.gradle.SpdxSbomExtension
import java.net.URI

Expand Down Expand Up @@ -43,7 +44,6 @@ val resolveJsTools by tasks.registering {
notCompatibleWithConfigurationCache("Uses project during task execution")
doNotTrackState("The task must always re-run to ensure that all dependencies are downloaded.")

@Suppress("DEPRECATION")
doLast {
fun Project.resolveDependencies(
vararg dependency: String,
Expand All @@ -56,73 +56,81 @@ val resolveJsTools by tasks.registering {
repo.run { repositories.remove(this) }
}

rootProject.extensions.findByType<D8RootExtension>()?.run {
project.resolveDependencies(
"google.d8:v8:linux64-rel-$version@zip",
"google.d8:v8:win64-rel-$version@zip",
"google.d8:v8:mac-arm64-rel-$version@zip",
"google.d8:v8:mac64-rel-$version@zip"
) {
ivy {
name = "D8-ResolveDependencies"
url = requireNotNull(downloadBaseUrl) { "downloadBaseUrl was null for $name repository" }.let(::URI)
patternLayout {
artifact("[artifact]-[revision].[ext]")
@OptIn(ExperimentalWasmDsl::class)
allprojects {
extensions.findByType<D8EnvSpec>()?.run {
val versionValue = version.get()
project.resolveDependencies(
"google.d8:v8:linux64-rel-$versionValue@zip",
"google.d8:v8:win64-rel-$versionValue@zip",
"google.d8:v8:mac-arm64-rel-$versionValue@zip",
"google.d8:v8:mac64-rel-$versionValue@zip"
) {
ivy {
name = "D8-ResolveDependencies"
url = requireNotNull(downloadBaseUrl.get()) { "downloadBaseUrl was null for $name repository" }.let(::URI)
patternLayout {
artifact("[artifact]-[revision].[ext]")
}
metadataSources { artifact() }
content { includeModule("google.d8", "v8") }
}
metadataSources { artifact() }
content { includeModule("google.d8", "v8") }
}
}
}

rootProject.extensions.findByType<BinaryenRootExtension>()?.run {
project.resolveDependencies(
"com.github.webassembly:binaryen:$version:[email protected]",
"com.github.webassembly:binaryen:$version:[email protected]",
"com.github.webassembly:binaryen:$version:[email protected]",
"com.github.webassembly:binaryen:$version:[email protected]"
) {
ivy {
name = "Binaryen-ResolveDependencies"
url = requireNotNull(downloadBaseUrl) { "downloadBaseUrl was null for $name repository" }.let(::URI)
patternLayout {
artifact("version_[revision]/binaryen-version_[revision]-[classifier].[ext]")
extensions.findByType<BinaryenRootEnvSpec>()?.run {
val versionValue = version.get()

project.resolveDependencies(
"com.github.webassembly:binaryen:$versionValue:[email protected]",
"com.github.webassembly:binaryen:$versionValue:[email protected]",
"com.github.webassembly:binaryen:$versionValue:[email protected]",
"com.github.webassembly:binaryen:$versionValue:[email protected]"
) {
ivy {
name = "Binaryen-ResolveDependencies"
url = requireNotNull(downloadBaseUrl.get()) { "downloadBaseUrl was null for $name repository" }.let(::URI)
patternLayout {
artifact("version_[revision]/binaryen-version_[revision]-[classifier].[ext]")
}
metadataSources { artifact() }
content { includeModule("com.github.webassembly", "binaryen") }
}
metadataSources { artifact() }
content { includeModule("com.github.webassembly", "binaryen") }
}
}
}

rootProject.extensions.findByType<NodeJsRootExtension>()?.run {
project.resolveDependencies(
"org.nodejs:node:$version:[email protected]",
"org.nodejs:node:$version:win-x64@zip",
"org.nodejs:node:$version:[email protected]",
"org.nodejs:node:$version:[email protected]"
) {
ivy {
name = "NodeJs-ResolveDependencies"
url = requireNotNull(downloadBaseUrl) { "downloadBaseUrl was null for $name repository" }.let(::URI)
patternLayout {
artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
extensions.findByType<NodeJsEnvSpec>()?.run {
val versionValue = version.get()

project.resolveDependencies(
"org.nodejs:node:$versionValue:[email protected]",
"org.nodejs:node:$versionValue:win-x64@zip",
"org.nodejs:node:$versionValue:[email protected]",
"org.nodejs:node:$versionValue:[email protected]"
) {
ivy {
name = "NodeJs-ResolveDependencies"
url = requireNotNull(downloadBaseUrl.get()) { "downloadBaseUrl was null for $name repository" }.let(::URI)
patternLayout {
artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
}
metadataSources { artifact() }
content { includeModule("org.nodejs", "node") }
}
metadataSources { artifact() }
content { includeModule("org.nodejs", "node") }
}
}
}

rootProject.extensions.findByType<YarnRootExtension>()?.run {
project.resolveDependencies("com.yarnpkg:yarn:$version@tar.gz") {
ivy {
name = "Yarn-ResolveDependencies"
url = requireNotNull(downloadBaseUrl) { "downloadBaseUrl was null for $name repository" }.let(::URI)
patternLayout {
artifact("v[revision]/[artifact](-v[revision]).[ext]")
extensions.findByType<YarnRootEnvSpec>()?.run {
project.resolveDependencies("com.yarnpkg:yarn:${version.get()}@tar.gz") {
ivy {
name = "Yarn-ResolveDependencies"
url = requireNotNull(downloadBaseUrl.get()) { "downloadBaseUrl was null for $name repository" }.let(::URI)
patternLayout {
artifact("v[revision]/[artifact](-v[revision]).[ext]")
}
metadataSources { artifact() }
content { includeModule("com.yarnpkg", "yarn") }
}
metadataSources { artifact() }
content { includeModule("com.yarnpkg", "yarn") }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,41 @@
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.the
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.d8.D8EnvSpec
import org.jetbrains.kotlin.gradle.targets.js.d8.D8Plugin
import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension
import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootPlugin
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin

@OptIn(ExperimentalWasmDsl::class)
private object V8Utils {
lateinit var d8Plugin: D8RootExtension
lateinit var d8Plugin: D8EnvSpec
lateinit var d8Root: D8RootExtension

fun useD8Plugin(project: Project) {
project.rootProject.plugins.apply(D8RootPlugin::class.java)
d8Plugin = project.rootProject.the<D8RootExtension>()
d8Plugin.version = project.v8Version
project.plugins.apply(D8Plugin::class.java)
d8Plugin = project.the<D8EnvSpec>()
project.rootProject.plugins.apply(D8Plugin::class.java)
d8Root = project.rootProject.the<D8RootExtension>()
d8Plugin.version.set(project.v8Version)
@Suppress("DEPRECATION")
d8Root.version = project.v8Version
}
}

fun Project.useD8Plugin() {
V8Utils.useD8Plugin(this)
}

@Suppress("DEPRECATION")
@OptIn(ExperimentalWasmDsl::class)
fun Test.setupV8() {
dependsOn(V8Utils.d8Plugin.setupTaskProvider)
with(V8Utils.d8Plugin) {
dependsOn(project.d8SetupTaskProvider)
}
dependsOn(V8Utils.d8Root.setupTaskProvider)
val v8ExecutablePath = project.provider {
V8Utils.d8Plugin.requireConfigured().executablePath.absolutePath
V8Utils.d8Root.requireConfigured().executablePath.absolutePath
}
doFirst {
systemProperty("javascript.engine.path.V8", v8ExecutablePath.get())
Expand Down

0 comments on commit be7b03c

Please sign in to comment.