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
This commit is contained in:
+76
@@ -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"
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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<KotlinJsCompilation>()
|
||||
|
||||
Reference in New Issue
Block a user