[Gradle, MPP] Fix 'getCommonizerTarget' for source sets participating in multiple compilations of the same konanTarget
The previous implementation would return a 'SharedCommonizerTarget' containing just a single leaf target. This would trigger the commonizer. The new implementation will correctly return just a single LeafCommonizerTarget instead. ^KT-49735 Verification Pending
This commit is contained in:
committed by
Space
parent
cb37424831
commit
bec2f89a07
+10
@@ -426,6 +426,16 @@ class CommonizerIT : BaseGradleIT() {
|
||||
`test multiple cinterops with test source sets and compilations`(false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test KT-49735 two kotlin targets with same konanTarget`() {
|
||||
with(Project("commonize-kt-49735-twoKotlinTargets-oneKonanTarget")) {
|
||||
build(":assemble") {
|
||||
assertTasksExecuted(":compileCommonMainKotlinMetadata")
|
||||
assertSuccessful()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun `test multiple cinterops with test source sets and compilations`(testSourceSetsDependingOnMain: Boolean) {
|
||||
with(Project("commonizeMultipleCInteropsWithTests", minLogLevel = INFO)) {
|
||||
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
val platformTargetA = when {
|
||||
HostManager.hostIsMac -> macosX64("platformA")
|
||||
HostManager.hostIsMingw -> mingwX64("platformA")
|
||||
HostManager.hostIsLinux -> linuxX64("platformA")
|
||||
else -> error("Unexpected host: ${HostManager.host}")
|
||||
}
|
||||
|
||||
val platformTargetB = when {
|
||||
HostManager.hostIsMac -> macosX64("platformB")
|
||||
HostManager.hostIsMingw -> mingwX64("platformB")
|
||||
HostManager.hostIsLinux -> linuxX64("platformB")
|
||||
else -> error("Unexpected host: ${HostManager.host}")
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
kotlin.code.style=official
|
||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.mpp.enableCInteropCommonization=true
|
||||
kotlin.native.enableDependencyPropagation=false
|
||||
kotlin.mpp.enableIntransitiveMetadataConfiguration=true
|
||||
kotlin.mpp.enableCompatibilityMetadataVariant=false
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
val kotlin_version: String by settings
|
||||
plugins {
|
||||
kotlin("multiplatform").version(kotlin_version)
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
object CommonMain {
|
||||
fun x(stat: platform.posix.stat) = Unit
|
||||
}
|
||||
+28
@@ -12,6 +12,7 @@ import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.ExtraPropertiesExtension
|
||||
import org.gradle.testfixtures.ProjectBuilder
|
||||
import org.jetbrains.kotlin.commonizer.CommonizerTarget
|
||||
import org.jetbrains.kotlin.commonizer.LeafCommonizerTarget
|
||||
import org.jetbrains.kotlin.commonizer.SharedCommonizerTarget
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.getCommonizerTarget
|
||||
@@ -83,6 +84,33 @@ class SourceSetCommonizerTargetTest {
|
||||
assertEquals(CommonizerTarget(LINUX_X64, MACOS_X64), project.getCommonizerTarget(commonTest))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `nativeMain linuxX64-a linuxX64-b`() {
|
||||
kotlin.linuxX64("linuxA")
|
||||
kotlin.linuxX64("linuxB")
|
||||
|
||||
val commonMain = kotlin.sourceSets.getByName("commonMain")
|
||||
val commonTest = kotlin.sourceSets.getByName("commonTest")
|
||||
val nativeMain = kotlin.sourceSets.create("nativeMain")
|
||||
val linuxAMain = kotlin.sourceSets.getByName("linuxAMain")
|
||||
val linuxBMain = kotlin.sourceSets.getByName("linuxBMain")
|
||||
val linuxATest = kotlin.sourceSets.getByName("linuxATest")
|
||||
val linuxBTest = kotlin.sourceSets.getByName("linuxBTest")
|
||||
|
||||
nativeMain.dependsOn(commonMain)
|
||||
linuxAMain.dependsOn(nativeMain)
|
||||
linuxBMain.dependsOn(nativeMain)
|
||||
|
||||
assertEquals(LeafCommonizerTarget(LINUX_X64), project.getCommonizerTarget(linuxAMain))
|
||||
assertEquals(LeafCommonizerTarget(LINUX_X64), project.getCommonizerTarget(linuxATest))
|
||||
assertEquals(LeafCommonizerTarget(LINUX_X64), project.getCommonizerTarget(linuxBMain))
|
||||
assertEquals(LeafCommonizerTarget(LINUX_X64), project.getCommonizerTarget(linuxBTest))
|
||||
|
||||
assertEquals(LeafCommonizerTarget(LINUX_X64), project.getCommonizerTarget(nativeMain))
|
||||
assertEquals(LeafCommonizerTarget(LINUX_X64), project.getCommonizerTarget(commonMain))
|
||||
assertEquals(LeafCommonizerTarget(LINUX_X64), project.getCommonizerTarget(commonTest))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `nativeMain iosMain linux macos iosX64 iosArm64`() {
|
||||
kotlin.linuxX64("linux")
|
||||
|
||||
+6
-5
@@ -14,17 +14,18 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.CompilationSourceSetUtil.compilati
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataCompilation
|
||||
|
||||
internal fun Project.getCommonizerTarget(sourceSet: KotlinSourceSet): CommonizerTarget? {
|
||||
val compilationTargets = compilationsBySourceSets(this)[sourceSet].orEmpty()
|
||||
val allCompilationLeafTargets = compilationsBySourceSets(this)[sourceSet].orEmpty()
|
||||
.filter { compilation -> compilation !is KotlinMetadataCompilation }
|
||||
.map { compilation -> getCommonizerTarget(compilation) ?: return null }
|
||||
.allLeaves()
|
||||
|
||||
return when {
|
||||
compilationTargets.isEmpty() -> null
|
||||
compilationTargets.size == 1 -> compilationTargets.single()
|
||||
else -> SharedCommonizerTarget(compilationTargets.allLeaves())
|
||||
allCompilationLeafTargets.isEmpty() -> null
|
||||
allCompilationLeafTargets.size == 1 -> allCompilationLeafTargets.single()
|
||||
else -> SharedCommonizerTarget(allCompilationLeafTargets)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Project.getSharedCommonizerTarget(sourceSet: KotlinSourceSet): SharedCommonizerTarget? {
|
||||
return getCommonizerTarget(sourceSet) as? SharedCommonizerTarget
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user