Skip to content

Commit

Permalink
Get rid of setupV8
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 edf7b9c commit fb34090
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 62 deletions.
2 changes: 1 addition & 1 deletion compiler/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
kotlin("jvm")
id("jps-compatible")
id("d8-configuration")
}

val compilerModules: Array<String> by rootProject.extra
Expand Down Expand Up @@ -44,7 +45,6 @@ sourceSets {
}
}

useD8Plugin()
projectTest(
parallel = true,
defineJDKEnvVariables = listOf(JdkMajorVersion.JDK_1_8, JdkMajorVersion.JDK_11_0, JdkMajorVersion.JDK_17_0)
Expand Down
3 changes: 1 addition & 2 deletions compiler/fir/analysis-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.ideaExt.idea
plugins {
kotlin("jvm")
id("jps-compatible")
id("d8-configuration")
}

dependencies {
Expand Down Expand Up @@ -62,8 +63,6 @@ if (kotlinBuildProperties.isInJpsBuildIdeaSync) {
}
}

useD8Plugin()

projectTest(
jUnitMode = JUnitMode.JUnit5,
defineJDKEnvVariables = listOf(
Expand Down
3 changes: 1 addition & 2 deletions compiler/incremental-compilation-impl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
kotlin("jvm")
id("jps-compatible")
id("d8-configuration")
}

dependencies {
Expand Down Expand Up @@ -41,8 +42,6 @@ sourceSets {
"test" { projectDefault() }
}

useD8Plugin()

projectTest(parallel = true) {
workingDir = rootDir
useJsIrBoxTests(version = version, buildDir = layout.buildDirectory)
Expand Down
7 changes: 5 additions & 2 deletions js/js.tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 All @@ -12,6 +13,7 @@ plugins {
kotlin("plugin.serialization")
id("jps-compatible")
alias(libs.plugins.gradle.node)
id("d8-configuration")
}

val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
Expand Down Expand Up @@ -88,7 +90,6 @@ dependencies {

val generationRoot = projectDir.resolve("tests-gen")

useD8Plugin()
optInToExperimentalCompilerApi()

sourceSets {
Expand Down Expand Up @@ -213,7 +214,9 @@ fun Test.setupNodeJs() {
}

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

setupNodeJs()
dependsOn(npmInstall)
Expand Down
7 changes: 5 additions & 2 deletions js/js.tests/klib-compatibility/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import org.jetbrains.kotlin.build.d8.D8Extension
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute

plugins {
kotlin("jvm")
id("d8-configuration")
}

dependencies {
Expand Down Expand Up @@ -46,13 +48,14 @@ sourceSets {
testsJar {}

fun Test.setUpJsBoxTests() {
setupV8()
with(project.the<D8Extension>()) {
setupV8()
}
dependsOn(":dist")

workingDir = rootDir
}

useD8Plugin()
projectTest(jUnitMode = JUnitMode.JUnit5) {
dependsOn(releasedCompilerDist)
systemProperty("kotlin.internal.js.test.latestReleasedCompilerLocation", releasedCompilerArtifactsTarget.get().asFile.absolutePath)
Expand Down
6 changes: 1 addition & 5 deletions libraries/stdlib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ plugins {
`maven-publish`
signing
id("nodejs-cache-redirector-configuration")
id("d8-configuration")
}

description = "Kotlin Standard Library"
Expand Down Expand Up @@ -596,11 +597,6 @@ 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
2 changes: 1 addition & 1 deletion plugins/atomicfu/atomicfu-compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description = "Atomicfu Compiler Plugin"
plugins {
kotlin("jvm")
id("jps-compatible")
id("d8-configuration")
}

// WARNING: Native target is host-dependent. Re-running the same build on another host OS may bring to a different result.
Expand Down Expand Up @@ -174,7 +175,6 @@ sourceSets {
}

testsJar()
useD8Plugin()

projectTest(jUnitMode = JUnitMode.JUnit5) {
useJUnitPlatform {
Expand Down
3 changes: 1 addition & 2 deletions plugins/js-plain-objects/compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description = "JavaScript Plain Objects Compiler Plugin"
plugins {
kotlin("jvm")
id("jps-compatible")
id("d8-configuration")
}

val jsoIrRuntimeForTests by configurations.creating {
Expand Down Expand Up @@ -74,8 +75,6 @@ sourcesJar()
javadocJar()
testsJar()

useD8Plugin()

projectTest(parallel = true, jUnitMode = JUnitMode.JUnit5) {
useJUnitPlatform()
useJsIrBoxTests(version = version, buildDir = layout.buildDirectory)
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlinx-serialization/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description = "Kotlin Serialization Compiler Plugin"
plugins {
kotlin("jvm")
id("jps-compatible")
id("d8-configuration")
}

val jsonJsIrRuntimeForTests: Configuration by configurations.creating {
Expand Down Expand Up @@ -88,7 +89,6 @@ val runtimeJar = runtimeJar {
sourcesJar()
javadocJar()
testsJar()
useD8Plugin()

val distCompat by configurations.creating {
isCanBeResolved = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:${project.bootstrapKotlinVersion}")
implementation(libs.gson)
implementation(libs.kotlinx.metadataJvm)
implementation(project(":d8-configuration"))
}

tasks.register("checkBuild") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ fun Project.kotlinxCollectionsImmutable() =
val Project.kotlinNativeVersion: String get() = property("versions.kotlin-native") as String

val Project.nodejsVersion: String get() = property("versions.nodejs") as String
val Project.v8Version: String get() = property("versions.v8") as String

fun File.matchMaybeVersionedArtifact(baseName: String) = name.matches(baseName.toMaybeVersionedJarRegex())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.the
import org.jetbrains.kotlin.build.d8.D8Extension

fun Test.useJsIrBoxTests(
version: Any,
Expand All @@ -13,7 +15,9 @@ fun Test.useJsIrBoxTests(
reducedStdlibPath: String = "libraries/stdlib/js-ir-minimal-for-test/build/classes/kotlin/js/main",
domApiCompatPath: String = "libraries/kotlin-dom-api-compat/build/classes/kotlin/main"
) {
setupV8()
with(project.the<D8Extension>()) {
setupV8()
}
dependsOn(":kotlin-stdlib:jsJar")
dependsOn(":kotlin-stdlib:jsJarForTests") // TODO: think how to remove dependency on the artifact in this place
dependsOn(":kotlin-test:jsJar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,9 @@

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.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin

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

fun useD8Plugin(project: Project) {
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)
}

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


private object NodeJsUtils {
lateinit var nodeJsPlugin: NodeJsRootExtension
Expand Down
27 changes: 27 additions & 0 deletions repo/gradle-build-conventions/d8-configuration/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
`kotlin-dsl`
id("org.jetbrains.kotlin.jvm")
}

repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
gradlePluginPortal()

extra["bootstrapKotlinRepo"]?.let {
maven(url = it)
}
}

kotlin {
jvmToolchain(8)

compilerOptions {
allWarningsAsErrors.set(true)
}
}

dependencies {
compileOnly(kotlin("stdlib", embeddedKotlinVersion))
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@file:OptIn(ExperimentalWasmDsl::class)

import org.jetbrains.kotlin.build.d8.D8Extension
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

project.plugins.apply(D8Plugin::class.java)
val d8EnvSpec = project.the<D8EnvSpec>()
project.rootProject.plugins.apply(D8Plugin::class.java)
val d8Root = project.rootProject.the<D8RootExtension>()

val d8KotlinBuild = extensions.create<D8Extension>(
"d8KotlinBuild",
d8EnvSpec,
d8Root
)

with(d8KotlinBuild) {
d8EnvSpec.version.set(project.v8Version)

@Suppress("DEPRECATION")
d8Root.version = project.v8Version
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2010-2024 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.
*/

@file:OptIn(ExperimentalWasmDsl::class)

package org.jetbrains.kotlin.build.d8

import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.d8.D8EnvSpec
import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension

abstract class D8Extension(
private val d8envSpec: D8EnvSpec,
private val d8Root: D8RootExtension
) {
val Project.v8Version: String get() = property("versions.v8") as String

fun Test.setupV8() {
with(d8envSpec) {
dependsOn(project.d8SetupTaskProvider)
}
dependsOn(d8Root.setupTaskProvider)
val v8ExecutablePath = project.provider {
d8Root.requireConfigured().executablePath.absolutePath
}
doFirst {
systemProperty("javascript.engine.path.V8", v8ExecutablePath.get())
}
}

}
3 changes: 2 additions & 1 deletion repo/gradle-build-conventions/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ include(":android-sdk-provisioner")
include(":asm-deprecating-transformer")
include(":binary-compatibility-extended")
include(":gradle-plugins-documentation")
include(":gradle-plugins-common")
include(":gradle-plugins-common")
include(":d8-configuration")
Loading

0 comments on commit fb34090

Please sign in to comment.