From 8d54b8d79a68451e4bf382d01a51932ed7fa633a Mon Sep 17 00:00:00 2001 From: Anton Lakotka Date: Mon, 29 Nov 2021 10:44:06 +0100 Subject: [PATCH] Don't publish wasm targets with KotlinJsCompilerAttribute Currently JS/IR and WASM targets share this attribute. This causes issues for HMPP projects on Variant-resolution stage when both JS/IR and WAS published. Given the fact that WASM compilation uses IR only it is logical to exclude such attribute which should fix variant resolution in HMPP --- .../kotlin/gradle/ConfigurationsTest.kt | 76 +++++++++++++++++++ .../gradle/plugin/KotlinTargetConfigurator.kt | 2 +- .../plugin/sources/KotlinSourceSetFactory.kt | 2 +- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt index d5972010f87..2ede9b1ae1d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/ConfigurationsTest.kt @@ -9,9 +9,11 @@ package org.jetbrains.kotlin.gradle import org.gradle.api.attributes.Category import org.gradle.api.attributes.Usage +import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages +import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull @@ -44,4 +46,78 @@ class ConfigurationsTest : MultiplatformExtensionTest() { assertEquals(Category.LIBRARY, category.name, "Expected configuration $configuration to be 'LIBRARY' Category") } } + + @Test + fun `don't publish wasm targets with KotlinJsCompilerAttribute attribute`() { + with(kotlin) { + js("nodeJs", KotlinJsCompilerType.IR) + js("browser", KotlinJsCompilerType.IR) + wasm() + + val allJs = sourceSets.create("allJs") + targets.getByName("nodeJs").compilations.getByName("main").defaultSourceSet.dependsOn(allJs) + targets.getByName("browser").compilations.getByName("main").defaultSourceSet.dependsOn(allJs) + } + + project.evaluate() + + val targetSpecificConfigurationsToCheck = listOf( + "ApiElements", + "RuntimeElements", + + "MainApiDependenciesMetadata", + "MainCompileOnlyDependenciesMetadata", + "MainImplementationDependenciesMetadata", + "MainRuntimeOnlyDependenciesMetadata", + + "TestApiDependenciesMetadata", + "TestCompileOnlyDependenciesMetadata", + "TestImplementationDependenciesMetadata", + "TestRuntimeOnlyDependenciesMetadata", + ) + + // WASM + val actualWasmConfigurations = targetSpecificConfigurationsToCheck + .map { project.configurations.getByName("wasm$it") } + .filter { it.attributes.contains(KotlinJsCompilerAttribute.jsCompilerAttribute) } + + assertEquals( + emptyList(), + actualWasmConfigurations, + "All WASM configurations should not contain KotlinJsCompilerAttribute" + ) + + val commonSourceSetsConfigurationsToCheck = listOf( + "ApiDependenciesMetadata", + "CompileOnlyDependenciesMetadata", + "ImplementationDependenciesMetadata", + "RuntimeOnlyDependenciesMetadata", + ) + + // allJs + val expectedAllJsConfigurations = commonSourceSetsConfigurationsToCheck + .map { project.configurations.getByName("allJs$it") } + + val actualAllJsConfigurations = expectedAllJsConfigurations + .filter { it.attributes.contains(KotlinJsCompilerAttribute.jsCompilerAttribute) } + + assertEquals( + expectedAllJsConfigurations, + actualAllJsConfigurations, + "JS-only configurations should contain KotlinJsCompilerAttribute" + ) + + + // commonMain + val actualCommonMainConfigurations = commonSourceSetsConfigurationsToCheck + .map { project.configurations.getByName("commonMain$it") } + .filter { it.attributes.contains(KotlinJsCompilerAttribute.jsCompilerAttribute) } + + assertEquals( + emptyList(), + actualCommonMainConfigurations, + "commonMain configurations should not contain KotlinJsCompilerAttribute" + ) + + } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt index e5b99cfc97d..9d9656fe124 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt @@ -526,7 +526,7 @@ fun Configuration.usesPlatformOf(target: KotlinTarget): Configuration { attributes.attribute(KotlinJsCompilerAttribute.jsCompilerAttribute, KotlinJsCompilerAttribute.legacy) } - if (target is KotlinJsIrTarget) { + if (target is KotlinJsIrTarget && target.platformType == KotlinPlatformType.js) { attributes.attribute(KotlinJsCompilerAttribute.jsCompilerAttribute, KotlinJsCompilerAttribute.ir) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/KotlinSourceSetFactory.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/KotlinSourceSetFactory.kt index dce3ca38608..6ba917f2d34 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/KotlinSourceSetFactory.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/KotlinSourceSetFactory.kt @@ -145,7 +145,7 @@ internal class DefaultKotlinSourceSetFactory( } project.kotlinExtension.targets - .filter { it is KotlinJsTarget || it is KotlinJsIrTarget } + .filter { it is KotlinJsTarget || (it is KotlinJsIrTarget && it.platformType == KotlinPlatformType.js) } .forEach { target -> target.compilations .filterIsInstance()