Skip to content

Commit

Permalink
[Wasm] Refactor environments in KotlinJsTarget and KotlinJsSubtarget
Browse files Browse the repository at this point in the history
Actually subtargets were like environments in KGP. Now all environments which we have (nodejs, browser and d8) have responsibilities to register task which are necessary for only them (like test and everything which is need to test and to setup NPM project).
Additional configurations are moved to other instances (Configurators).
SubTarget could work without knowledge of specific configurators.
Configurators could implement additional logic, for example bundle functionaility of webpack can be added separately (browser subtarget could work fine without it). NodeJs configurator could register run tasks, which could not be mandatory. So we keep all mandatory in SubTargets and extract all "optional" functionality to "configurators".
It can help to toggle optional features.

^KT-72175 fixed
  • Loading branch information
ilgonmic authored and qodana-bot committed Nov 19, 2024
1 parent d2e6c35 commit 08ac97b
Show file tree
Hide file tree
Showing 45 changed files with 1,223 additions and 791 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ class JsIrConfigurationCacheIT : KGPBaseTest() {
@GradleTest
fun testNodeJsRun(gradleVersion: GradleVersion) {
project("kotlin-js-nodejs-project", gradleVersion) {
build("nodeRun", buildOptions = buildOptions) {
assertTasksExecuted(":nodeRun")
build("nodeDevelopmentRun", buildOptions = buildOptions) {
assertTasksExecuted(":nodeDevelopmentRun")
if (gradleVersion < GradleVersion.version(TestVersions.Gradle.G_8_5)) {
assertOutputContains(
"Calculating task graph as no configuration cache is available for tasks: nodeRun"
"Calculating task graph as no configuration cache is available for tasks: nodeDevelopmentRun"
)
} else {
assertOutputContains(
"Calculating task graph as no cached configuration is available for tasks: nodeRun"
"Calculating task graph as no cached configuration is available for tasks: nodeDevelopmentRun"
)
}

Expand All @@ -164,8 +164,8 @@ class JsIrConfigurationCacheIT : KGPBaseTest() {
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")
build("nodeDevelopmentRun", buildOptions = buildOptions) {
assertTasksExecuted(":nodeDevelopmentRun")
assertConfigurationCacheReused()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|}
""".trimMargin()
)
build("nodeRun") {
build("nodeDevelopmentRun") {
assertOutputContains("ACCEPTED: test;'Hello, World'")
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {

val filesModified: MutableMap<String, Long> = mutableMapOf()

build("compileDevelopmentExecutableKotlinJs") {
build("developmentExecutableCompileSync") {
assertTasksExecuted(":app:developmentExecutableCompileSync")

projectPath.resolve("build/js/packages/kotlin-js-browser-app")
Expand All @@ -199,7 +199,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
fooTxt.parent.toFile().mkdirs()
fooTxt.createFile().writeText("foo")

build("compileDevelopmentExecutableKotlinJs") {
build("developmentExecutableCompileSync") {
assertTasksExecuted(":app:developmentExecutableCompileSync")

val modified = projectPath.resolve("build/js/packages/kotlin-js-browser-app")
Expand Down Expand Up @@ -229,7 +229,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {

fooTxt.writeText("bar")

build("compileDevelopmentExecutableKotlinJs") {
build("developmentExecutableCompileSync") {
assertTasksExecuted(":app:developmentExecutableCompileSync")

val modified = projectPath.resolve("build/js/packages/kotlin-js-browser-app")
Expand All @@ -251,7 +251,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
fooTxt.deleteExisting()


build("compileDevelopmentExecutableKotlinJs") {
build("developmentExecutableCompileSync") {
assertTasksExecuted(":app:developmentExecutableCompileSync")

assertFileInProjectNotExists("build/js/packages/kotlin-js-browser-app/kotlin/foo/foo.txt")
Expand Down Expand Up @@ -312,16 +312,16 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
""".trimMargin()
)

buildAndFail("compileDevelopmentExecutableKotlinJs") {
buildAndFail("developmentExecutableCompileSync") {
assertTasksFailed(":developmentExecutableValidateGeneratedByCompilerTypeScript")
assertFileInProjectExists("build/js/packages/js-ir-validate-ts/kotlin/js-ir-validate-ts.js")
assertFileInProjectExists("build/js/packages/js-ir-validate-ts/kotlin/js-ir-validate-ts.d.ts")
assertFileInProjectExists("build/compileSync/js/main/developmentExecutable/kotlin/js-ir-validate-ts.js")
assertFileInProjectExists("build/compileSync/js/main/developmentExecutable/kotlin/js-ir-validate-ts.d.ts")
}

build("compileProductionExecutableKotlinJs") {
build("productionExecutableCompileSync") {
assertTasksExecuted(":productionExecutableValidateGeneratedByCompilerTypeScript")
assertFileInProjectExists("build/js/packages/js-ir-validate-ts/kotlin/js-ir-validate-ts.js")
assertFileInProjectExists("build/js/packages/js-ir-validate-ts/kotlin/js-ir-validate-ts.d.ts")
assertFileInProjectExists("build/compileSync/js/main/developmentExecutable/kotlin/js-ir-validate-ts.js")
assertFileInProjectExists("build/compileSync/js/main/developmentExecutable/kotlin/js-ir-validate-ts.d.ts")
}
}
}
Expand Down Expand Up @@ -730,7 +730,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
@GradleTest
fun testKotlinJsSourceMap(gradleVersion: GradleVersion) {
project("kotlin2JsProjectWithSourceMap", gradleVersion) {
build("compileDevelopmentExecutableKotlinJs") {
build("developmentExecutableCompileSync") {
val appSourceMap = subProject("app").projectPath
.resolve("build/compileSync/js/main/developmentExecutable/kotlin/$projectName-app.js.map")
assertFileContains(
Expand Down Expand Up @@ -817,7 +817,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
""".trimMargin()
)
build("compileDevelopmentExecutableKotlinJs") {
build("developmentExecutableCompileSync") {
val jsFilePath = projectPath.resolve("build/js/packages/$projectName-app/kotlin/$projectName-app.js")
assertFileExists(jsFilePath)
assertFileNotExists(Path("$jsFilePath.map"))
Expand Down Expand Up @@ -847,7 +847,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
""".trimMargin()
)
build("compileDevelopmentExecutableKotlinJs") {
build("developmentExecutableCompileSync") {
val mapFilePath = projectPath.resolve("build/js/packages/$projectName-app/kotlin/$projectName-app.js.map")
assertFileContains(
mapFilePath,
Expand Down Expand Up @@ -880,7 +880,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
""".trimMargin()
)
build("compileDevelopmentExecutableKotlinJs") {
build("developmentExecutableCompileSync") {
val mapFilePath = projectPath.resolve("build/js/packages/$projectName-app/kotlin/$projectName-app.js.map")
assertFileDoesNotContain(
mapFilePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ abstract class Kotlin2JsIrBeIncrementalCompilationIT : KGPBaseTest() {
}

// -Xir-property-lazy-initialization default is true
build("nodeRun") {
build("nodeDevelopmentRun") {
assertTasksExecuted(":compileDevelopmentExecutableKotlinJs")
assertEquals(listOf("Hello, Gradle."), output.testScriptOutLines())
}

setLazyInitializationArg(false)
build("nodeRun") {
build("nodeDevelopmentRun") {
assertTasksExecuted(":compileDevelopmentExecutableKotlinJs")
assertEquals(listOf("TOP LEVEL!", "Hello, Gradle."), output.testScriptOutLines())
}

setLazyInitializationArg(true)
build("nodeRun") {
build("nodeDevelopmentRun") {
assertTasksExecuted(":compileDevelopmentExecutableKotlinJs")
assertEquals(listOf("Hello, Gradle."), output.testScriptOutLines())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class KotlinWasmGradlePluginIT : KGPBaseTest() {
@GradleTest
fun wasiRun(gradleVersion: GradleVersion) {
project("new-mpp-wasm-wasi-test", gradleVersion) {
build(":wasmWasiNodeRun") {
build(":wasmWasiNodeDevelopmentRun") {
assertOutputContains("Hello from Wasi")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class WasmConfigurationCacheIT : KGPBaseTest() {
gradleVersion,
dependencyManagement = DependencyManagement.DisabledDependencyManagement // :d8Download adds custom ivy repository during build
) {
build("wasmJsD8Run", buildOptions = buildOptions) {
assertTasksExecuted(":wasmJsD8Run")
build("wasmJsD8DevelopmentRun", buildOptions = buildOptions) {
assertTasksExecuted(":wasmJsD8DevelopmentRun")
if (gradleVersion < GradleVersion.version(TestVersions.Gradle.G_8_5)) {
assertOutputContains(
"Calculating task graph as no configuration cache is available for tasks: wasmJsD8Run"
"Calculating task graph as no configuration cache is available for tasks: wasmJsD8DevelopmentRun"
)
} else {
assertOutputContains(
"Calculating task graph as no cached configuration is available for tasks: wasmJsD8Run"
"Calculating task graph as no cached configuration is available for tasks: wasmJsD8DevelopmentRun"
)
}

Expand All @@ -55,8 +55,8 @@ class WasmConfigurationCacheIT : KGPBaseTest() {
build("clean", buildOptions = buildOptions)

// Then run a build where tasks states are deserialized to check that they work correctly in this mode
build("wasmJsD8Run", buildOptions = buildOptions) {
assertTasksExecuted(":wasmJsD8Run")
build("wasmJsD8DevelopmentRun", buildOptions = buildOptions) {
assertTasksExecuted(":wasmJsD8DevelopmentRun")
assertConfigurationCacheReused()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MppDslWasmIT : KGPBaseTest() {
val jsOutput = "$jsPackages/redefined-js-module-name/kotlin/"
assertFileInProjectExists("$jsOutput/redefined-js-module-name.js")

val wasmOutput = "$jsPackages/redefined-wasm-module-name/kotlin/"
val wasmOutput = "build/compileSync/wasmJs/main/productionExecutable/optimized"
assertFileInProjectExists("$wasmOutput/redefined-wasm-module-name.mjs")
assertFileInProjectExists("$wasmOutput/redefined-wasm-module-name.wasm")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
kotlin {
js {
val compilation = compilations.getByName("main")
org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.create(compilation, "checkConfigDevelopmentWebpack") {
org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.register(compilation, "checkConfigDevelopmentWebpack") {
inputFileProperty.set(provider { compilation.npmProject.require("webpack/bin/webpack.js") }.map { RegularFile { File(it) } })
dependsOn("browserDevelopmentWebpack")
args("configtest")
Expand All @@ -26,7 +26,7 @@ kotlin {
args(configFile.get().absolutePath)
}
}
org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.create(compilation, "checkConfigProductionWebpack") {
org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.register(compilation, "checkConfigProductionWebpack") {
inputFileProperty.set(provider { compilation.npmProject.require("webpack/bin/webpack.js") }.map { RegularFile { File(it) } })
dependsOn("browserProductionWebpack")
val configFile = tasks.named<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack>("browserProductionWebpack").flatMap { it.configFile }
Expand All @@ -36,7 +36,7 @@ kotlin {
args(configFile.get().absolutePath)
}
}
org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.create(compilation, "checkConfigDevelopmentRun") {
org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.register(compilation, "checkConfigDevelopmentRun") {
inputFileProperty.set(provider { compilation.npmProject.require("webpack/bin/webpack.js") }.map { RegularFile { File(it) } })
dependsOn("browserDevelopmentRun")
val configFile = tasks.named<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack>("browserDevelopmentRun").flatMap { it.configFile }
Expand All @@ -45,7 +45,7 @@ kotlin {
args(configFile.get().absolutePath)
}
}
org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.create(compilation, "checkConfigProductionRun") {
org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec.register(compilation, "checkConfigProductionRun") {
inputFileProperty.set(provider { compilation.npmProject.require("webpack/bin/webpack.js") }.map { RegularFile { File(it) } })
dependsOn("browserProductionRun")
val configFile = tasks.named<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack>("browserProductionRun").flatMap { it.configFile }
Expand Down
Loading

0 comments on commit 08ac97b

Please sign in to comment.