Skip to content

Commit 1b23aa9

Browse files
committed
composeCompatibilityBrowserDistribution: Skip web targets where executable is not configures (#5394)
composeCompatibilityBrowserDistribution: Skip web targets where executable is not configures Fixes https://youtrack.jetbrains.com/issue/CMP-8760/Compatibility-task-breaks-build-of-Compose-library-modules ## Testing Manual and running `WebCompatibilityDistributionTest` ## Release Notes N/A
1 parent 71dfccf commit 1b23aa9

File tree

38 files changed

+473
-31
lines changed

38 files changed

+473
-31
lines changed

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/WebCompatibilityTask.kt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,20 @@ private fun Project.registerWebCompatibilityTask(mppPlugin: KotlinMultiplatformE
133133

134134
mppPlugin.targets.withType(KotlinJsIrTarget::class.java).configureEach { target ->
135135
if (target.platformType == KotlinPlatformType.wasm) {
136-
wasmOutputName.set(
137-
tasks.named(
138-
"${target.name}BrowserProductionWebpack",
139-
KotlinWebpack::class.java
140-
).flatMap { it.mainOutputFileName }
141-
)
136+
tasks.withType(KotlinWebpack::class.java).findByName("${target.name}BrowserProductionWebpack")?.let {
137+
wasmOutputName.set(it.mainOutputFileName)
138+
}
139+
142140
wasmDistFiles.from(
143-
tasks.named("${target.name}BrowserDistribution").map { it.outputs.files }
141+
tasks.matching { it.name == "${target.name}BrowserDistribution" }.map { it.outputs.files }
144142
)
145143
} else if (target.platformType == KotlinPlatformType.js) {
146-
jsOutputName.set(
147-
tasks.named(
148-
"${target.name}BrowserProductionWebpack",
149-
KotlinWebpack::class.java
150-
).flatMap { it.mainOutputFileName }
151-
)
144+
tasks.withType(KotlinWebpack::class.java).findByName("${target.name}BrowserProductionWebpack")?.let {
145+
jsOutputName.set(it.mainOutputFileName)
146+
}
147+
152148
jsDistFiles.from(
153-
tasks.named("${target.name}BrowserDistribution").map { it.outputs.files }
149+
tasks.matching { it.name == "${target.name}BrowserDistribution" }.map { it.outputs.files }
154150
)
155151
}
156152

gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/WebCompatibilityDistributionTest.kt

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jetbrains.compose.test.tests.integration
22

3+
import org.jetbrains.compose.test.utils.ChecksWrapper
34
import org.jetbrains.compose.test.utils.GradlePluginTestBase
45
import org.jetbrains.compose.test.utils.TestProject
56
import org.jetbrains.compose.test.utils.checkExists
@@ -33,26 +34,40 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
3334
}
3435
}
3536

36-
private fun runCompatibilityTest(
37+
private fun runTaskAndCheck(projectPath: String, taskName: String, onExecution: ChecksWrapper.(project: TestProject) -> Unit) {
38+
with(
39+
testProject(
40+
projectPath,
41+
testEnvironment = defaultTestEnvironment.copy()
42+
)
43+
) {
44+
gradle(taskName).checks {
45+
onExecution(this@with)
46+
}
47+
}
48+
}
49+
50+
private fun assertSuccessfulCompatibilityRun(
3751
projectPath: String,
3852
successfulTasks: List<String>,
3953
distDir: String = defaultDistDir,
4054
expectedFiles: Set<String>
41-
) = with(
42-
testProject(
43-
projectPath,
44-
testEnvironment = defaultTestEnvironment.copy()
45-
)
4655
) {
47-
gradle(":composeApp:composeCompatibilityBrowserDistribution").checks {
56+
runTaskAndCheck(projectPath, ":composeApp:composeCompatibilityBrowserDistribution") { testProject ->
4857
check.taskSuccessful(":composeApp:composeCompatibilityBrowserDistribution")
4958
successfulTasks.forEach { check.taskSuccessful(it) }
50-
assertCompatibilityDistribution(dirPath = distDir, expectedFileNames = expectedFiles)
59+
testProject.assertCompatibilityDistribution(dirPath = distDir, expectedFileNames = expectedFiles)
60+
}
61+
}
62+
63+
private fun assertSkippedCompatibilityRun(projectPath: String) {
64+
runTaskAndCheck(projectPath, ":composeApp:composeCompatibilityBrowserDistribution") {
65+
check.taskSkipped(":composeApp:composeCompatibilityBrowserDistribution")
5166
}
5267
}
5368

5469
@Test
55-
fun testWebJsWasm() = runCompatibilityTest(
70+
fun testWebJsWasm() = assertSuccessfulCompatibilityRun(
5671
projectPath = "application/webJsWasm",
5772
successfulTasks = listOf(
5873
":composeApp:jsBrowserDistribution",
@@ -71,7 +86,22 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
7186
)
7287

7388
@Test
74-
fun testWebJsWasmNonStandard() = runCompatibilityTest(
89+
fun testWebJsOnly() = assertSkippedCompatibilityRun(
90+
projectPath = "application/webJsOnly"
91+
)
92+
93+
@Test
94+
fun testWebWasmOnly() = assertSkippedCompatibilityRun(
95+
projectPath = "application/webWasmOnly"
96+
)
97+
98+
@Test
99+
fun testWebJsNonExecutable() = assertSkippedCompatibilityRun(
100+
projectPath = "application/webJsWasmNonExecutable"
101+
)
102+
103+
@Test
104+
fun testWebJsWasmNonStandard() = assertSuccessfulCompatibilityRun(
75105
projectPath = "application/webJsWasmNonStandard",
76106
successfulTasks = listOf(
77107
":composeApp:webJsBrowserDistribution",
@@ -90,7 +120,7 @@ class WebCompatibilityDistributionTest : GradlePluginTestBase() {
90120
)
91121

92122
@Test
93-
fun testWebJsWasmReconfigured() = runCompatibilityTest(
123+
fun testWebJsWasmReconfigured() = assertSuccessfulCompatibilityRun(
94124
projectPath = "application/webJsWasmReconfigured",
95125
successfulTasks = listOf(
96126
":composeApp:wasmRepack",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--install.mutex network
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
// this is necessary to avoid the plugins to be loaded multiple times
3+
// in each subproject's classloader
4+
id("org.jetbrains.kotlin.multiplatform") apply false
5+
id("org.jetbrains.compose") apply false
6+
id("org.jetbrains.kotlin.plugin.compose") apply false
7+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
2+
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
3+
4+
plugins {
5+
id("org.jetbrains.kotlin.multiplatform")
6+
id("org.jetbrains.compose")
7+
id("org.jetbrains.kotlin.plugin.compose")
8+
}
9+
10+
kotlin {
11+
js(IR) {
12+
outputModuleName.set("composeApp")
13+
browser {
14+
commonWebpackConfig {
15+
outputFileName = "composeApp.js"
16+
}
17+
}
18+
binaries.executable()
19+
}
20+
21+
sourceSets {
22+
commonMain.dependencies {
23+
implementation(compose.runtime)
24+
}
25+
26+
val webMain by creating {
27+
resources.setSrcDirs(resources.srcDirs)
28+
dependsOn(commonMain.get())
29+
}
30+
31+
val jsMain by getting {
32+
dependsOn(webMain)
33+
}
34+
}
35+
}
36+
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.example.project
2+
3+
private class JsPlatform : Platform {
4+
override val name: String = "Web with Kotlin/JS"
5+
}
6+
7+
actual fun getPlatform(): Platform = JsPlatform()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.example.project
2+
3+
private class WasmPlatform : Platform {
4+
override val name: String = "Web with Kotlin/Wasm"
5+
}
6+
7+
actual fun getPlatform(): Platform = WasmPlatform()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.example.project
2+
3+
class Greeting {
4+
private val platform = getPlatform()
5+
6+
fun greet(): String {
7+
return "Hello, ${platform.name}!"
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.example.project
2+
3+
interface Platform {
4+
val name: String
5+
}
6+
7+
expect fun getPlatform(): Platform
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.example.project
2+
3+
fun main() {
4+
println(Greeting().greet())
5+
}

0 commit comments

Comments
 (0)