Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes for testFinalArtefacts
Co-authored-by: Oleksandr Karpovich <[email protected]>
  • Loading branch information
Schahen and eymar committed Jul 29, 2025
commit 0d3f551c2c33284e4fd74f581b43961b5926aa2c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.compose.web.tasks

import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.file.FileCollection
Expand All @@ -19,6 +20,7 @@ import org.jetbrains.compose.internal.utils.registerTask
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import javax.inject.Inject
import kotlin.math.log

abstract class WebCompatibilityTask : DefaultTask() {
@get:Inject
Expand All @@ -28,10 +30,10 @@ abstract class WebCompatibilityTask : DefaultTask() {
abstract val outputDir: DirectoryProperty

@get:InputFiles
lateinit var jsDistFiles: FileCollection
abstract val jsDistFiles: ConfigurableFileCollection

@get:InputFiles
lateinit var wasmDistFiles: FileCollection
abstract val wasmDistFiles: ConfigurableFileCollection

@get:Input
@get:Optional
Expand Down Expand Up @@ -126,23 +128,36 @@ abstract class WebCompatibilityTask : DefaultTask() {

private fun Project.registerWebCompatibilityTask(mppPlugin: KotlinMultiplatformExtension) = registerTask<WebCompatibilityTask>("composeWebCompatibilityDist") {
val webProductionDist = layout.buildDirectory.dir("dist/web/productionExecutable")
outputDir.set(webProductionDist)

mppPlugin.targets.matching { it is KotlinJsIrTarget }.all { target ->
val outputName = when {
(target as KotlinJsIrTarget).wasmTargetType == null -> wasmOutputName
(target as KotlinJsIrTarget).wasmTargetType != null -> wasmOutputName
else -> jsOutputName
}

outputName.set(target.outputModuleName)
}

onlyIf {
jsOutputName.orNull != null && wasmOutputName.orNull != null
val hasBothDistributions = !jsDistFiles.isEmpty && !wasmDistFiles.isEmpty
val hasBothOutputs = jsOutputName.orNull != null && wasmOutputName.orNull != null

if (!hasBothDistributions) {
logger.lifecycle("Task ${this.name} skipped: no js and wasm distributions found, both are required for compatibility")
} else if (!hasBothOutputs) {
logger.lifecycle("Task ${this.name} skipped: no js and wasm output names specified")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add tests for this logic too, please

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add a log check into one of existed tests for other cases with only one of the web targets

}
hasBothDistributions && hasBothOutputs
}

outputDir.set(webProductionDist)
jsDistFiles = tasks.named("jsBrowserDistribution").get().outputs.files
wasmDistFiles = tasks.named("wasmJsBrowserDistribution").get().outputs.files
jsDistFiles.from(project.provider {
project.tasks.findByName("jsBrowserDistribution")?.outputs?.files ?: project.files()
})

wasmDistFiles.from(project.provider {
project.tasks.findByName("wasmJsBrowserDistribution")?.outputs?.files ?: project.files()
})
}

internal fun Project.configureWebCompatibility() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a description what's going here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class GradlePluginTest : GradlePluginTestBase() {
) {
gradle(":composeApp:composeWebCompatibilityDist").checks {
check.taskSuccessful(":composeApp:composeWebCompatibilityDist")
check.taskSuccessful(":composeApp:jsBrowserDistribution")
check.taskSuccessful(":composeApp:wasmJsBrowserDistribution")

file("./composeApp/build/dist/web/productionExecutable").apply {
checkExists()
Expand Down
Loading