[Gradle, JS] Fix configuration cache for NodeJsExec and D8Exec
^KT-58250 fixed ^KT-58256 fixed
This commit is contained in:
committed by
Space Team
parent
83db4a06d9
commit
f8c51dcfee
+23
@@ -127,6 +127,29 @@ abstract class AbstractJsConfigurationCacheIT(protected val irBackend: Boolean)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Node.js run correctly works with configuration cache")
|
||||||
|
@GradleTest
|
||||||
|
fun testNodeJsRun(gradleVersion: GradleVersion) {
|
||||||
|
project("kotlin-js-nodejs-project", gradleVersion) {
|
||||||
|
build("nodeRun", buildOptions = buildOptions) {
|
||||||
|
assertTasksExecuted(":nodeRun")
|
||||||
|
assertOutputContains(
|
||||||
|
"Calculating task graph as no configuration cache is available for tasks: nodeRun"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertConfigurationCacheStored()
|
||||||
|
}
|
||||||
|
|
||||||
|
build("clean", buildOptions = buildOptions)
|
||||||
|
|
||||||
|
// Then run a build where tasks states are deserialized to check that they work correctly in this mode
|
||||||
|
build("nodeRun", buildOptions = buildOptions) {
|
||||||
|
assertTasksExecuted(":nodeRun")
|
||||||
|
assertConfigurationCacheReused()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsGradlePluginTests
|
@JsGradlePluginTests
|
||||||
|
|||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 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
|
||||||
|
|
||||||
|
import org.gradle.util.GradleVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||||
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
|
||||||
|
@MppGradlePluginTests
|
||||||
|
class WasmConfigurationCacheIT : KGPBaseTest() {
|
||||||
|
override val defaultBuildOptions =
|
||||||
|
super.defaultBuildOptions.copy(
|
||||||
|
configurationCache = true,
|
||||||
|
)
|
||||||
|
|
||||||
|
@DisplayName("configuration cache is working for wasm")
|
||||||
|
@GradleTest
|
||||||
|
fun testKotlinWasmCompilation(gradleVersion: GradleVersion) {
|
||||||
|
project("wasm-d8-simple-project", gradleVersion) {
|
||||||
|
assertSimpleConfigurationCacheScenarioWorks(
|
||||||
|
"assemble",
|
||||||
|
buildOptions = defaultBuildOptions,
|
||||||
|
executedTaskNames = listOf(":compileKotlinWasm")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("D8 run correctly works with configuration cache")
|
||||||
|
@GradleTest
|
||||||
|
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_6)
|
||||||
|
fun testD8Run(gradleVersion: GradleVersion) {
|
||||||
|
project("wasm-d8-simple-project", gradleVersion) {
|
||||||
|
build("wasmD8Run", buildOptions = buildOptions) {
|
||||||
|
assertTasksExecuted(":wasmD8Run")
|
||||||
|
assertOutputContains(
|
||||||
|
"Calculating task graph as no configuration cache is available for tasks: wasmD8Run"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertConfigurationCacheStored()
|
||||||
|
}
|
||||||
|
|
||||||
|
build("clean", buildOptions = buildOptions)
|
||||||
|
|
||||||
|
// Then run a build where tasks states are deserialized to check that they work correctly in this mode
|
||||||
|
build("wasmD8Run", buildOptions = buildOptions) {
|
||||||
|
assertTasksExecuted(":wasmD8Run")
|
||||||
|
assertConfigurationCacheReused()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
wasm {
|
||||||
|
binaries.executable()
|
||||||
|
d8 {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
println("Hello, world")
|
||||||
|
}
|
||||||
+3
-16
@@ -13,17 +13,8 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.addWasmExperimentalArguments
|
import org.jetbrains.kotlin.gradle.targets.js.addWasmExperimentalArguments
|
||||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||||
import org.jetbrains.kotlin.gradle.utils.newFileProperty
|
import org.jetbrains.kotlin.gradle.utils.newFileProperty
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
open class D8Exec
|
|
||||||
@Inject
|
|
||||||
constructor(
|
|
||||||
private val compilation: KotlinJsCompilation
|
|
||||||
) : AbstractExecTask<D8Exec>(D8Exec::class.java) {
|
|
||||||
@Transient
|
|
||||||
@get:Internal
|
|
||||||
lateinit var d8: D8RootExtension
|
|
||||||
|
|
||||||
|
open class D8Exec : AbstractExecTask<D8Exec>(D8Exec::class.java) {
|
||||||
init {
|
init {
|
||||||
onlyIf {
|
onlyIf {
|
||||||
!inputFileProperty.isPresent || inputFileProperty.asFile.map { it.exists() }.get()
|
!inputFileProperty.isPresent || inputFileProperty.asFile.map { it.exists() }.get()
|
||||||
@@ -45,9 +36,7 @@ constructor(
|
|||||||
if (inputFileProperty.isPresent) {
|
if (inputFileProperty.isPresent) {
|
||||||
val inputFile = inputFileProperty.asFile.get()
|
val inputFile = inputFileProperty.asFile.get()
|
||||||
workingDir = inputFile.parentFile
|
workingDir = inputFile.parentFile
|
||||||
if (compilation.target.platformType == KotlinPlatformType.wasm) {
|
newArgs.add("--module")
|
||||||
newArgs.add("--module")
|
|
||||||
}
|
|
||||||
newArgs.add(inputFile.canonicalPath)
|
newArgs.add(inputFile.canonicalPath)
|
||||||
}
|
}
|
||||||
args?.let {
|
args?.let {
|
||||||
@@ -70,10 +59,8 @@ constructor(
|
|||||||
val project = target.project
|
val project = target.project
|
||||||
val d8 = D8RootPlugin.apply(project.rootProject)
|
val d8 = D8RootPlugin.apply(project.rootProject)
|
||||||
return project.registerTask(
|
return project.registerTask(
|
||||||
name,
|
name
|
||||||
listOf(compilation)
|
|
||||||
) {
|
) {
|
||||||
it.d8 = d8
|
|
||||||
it.executable = d8.requireConfigured().executablePath.absolutePath
|
it.executable = d8.requireConfigured().executablePath.absolutePath
|
||||||
it.dependsOn(d8.setupTaskProvider)
|
it.dependsOn(d8.setupTaskProvider)
|
||||||
it.dependsOn(compilation.compileKotlinTaskProvider)
|
it.dependsOn(compilation.compileKotlinTaskProvider)
|
||||||
|
|||||||
+6
-2
@@ -23,12 +23,16 @@ open class NodeJsExec
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
@Internal
|
@Internal
|
||||||
override val compilation: KotlinJsCompilation
|
@Transient
|
||||||
|
override val compilation: KotlinJsCompilation,
|
||||||
) : AbstractExecTask<NodeJsExec>(NodeJsExec::class.java), RequiresNpmDependencies {
|
) : AbstractExecTask<NodeJsExec>(NodeJsExec::class.java), RequiresNpmDependencies {
|
||||||
@Transient
|
@Transient
|
||||||
@get:Internal
|
@get:Internal
|
||||||
lateinit var nodeJs: NodeJsRootExtension
|
lateinit var nodeJs: NodeJsRootExtension
|
||||||
|
|
||||||
|
@Internal
|
||||||
|
val npmProject = compilation.npmProject
|
||||||
|
|
||||||
init {
|
init {
|
||||||
onlyIf {
|
onlyIf {
|
||||||
!inputFileProperty.isPresent || inputFileProperty.asFile.map {
|
!inputFileProperty.isPresent || inputFileProperty.asFile.map {
|
||||||
@@ -70,7 +74,7 @@ constructor(
|
|||||||
if (sourceMapStackTraces) {
|
if (sourceMapStackTraces) {
|
||||||
val sourceMapSupportArgs = mutableListOf(
|
val sourceMapSupportArgs = mutableListOf(
|
||||||
"--require",
|
"--require",
|
||||||
compilation.npmProject.require("source-map-support/register.js")
|
npmProject.require("source-map-support/register.js")
|
||||||
)
|
)
|
||||||
|
|
||||||
args?.let { sourceMapSupportArgs.addAll(it) }
|
args?.let { sourceMapSupportArgs.addAll(it) }
|
||||||
|
|||||||
Reference in New Issue
Block a user