[Gradle] GetCommonizerTargetOfSourceSet: Gracefully handle common non-hmpp workaround

This commit is contained in:
sebastian.sellmair
2021-04-08 12:10:45 +02:00
parent 2aeb08e245
commit c4562fd1db
2 changed files with 20 additions and 5 deletions
@@ -163,4 +163,18 @@ class SourceSetCommonizerTargetTest {
assertNull(project.getCommonizerTarget(commonMain), "Expected commonMain to have no commonizer target")
assertNull(project.getCommonizerTarget(commonTest), "Expected commonTest to have no commonizer target")
}
@Test
fun `nativeMain with non hmpp workaround`() {
val linux1 = kotlin.linuxX64("linux1")
val linux2 = kotlin.linuxArm64("linux2")
val nativeMain = kotlin.sourceSets.create("nativeMain")
listOf(linux1, linux2).forEach { target ->
target.compilations.getByName("main").source(nativeMain)
}
assertNull(project.getCommonizerTarget(nativeMain), "Expected no commonizer target, since no real source set hierarchy is given")
}
}
@@ -40,12 +40,13 @@ private fun Project.getLeafCommonizerTarget(sourceSet: KotlinSourceSet): LeafCom
val konanTargets = compilationsBySourceSets(this)[sourceSet].orEmpty()
.flatMap { compilation -> compilation.konanTargets }
return when {
konanTargets.isEmpty() -> null
konanTargets.size == 1 -> LeafCommonizerTarget(konanTargets.single())
else -> error("Source set ${sourceSet.name} is not a leaf source set. konanTargets=$konanTargets")
}
return if (konanTargets.size == 1) LeafCommonizerTarget(konanTargets.single())
/*
Can even be more than one, when added using `KotlinCompilation.source`. Still returning null, since this
does not represent a 'proper' source set hierarchy
*/
else null
}
private fun KotlinSourceSetContainer.resolveSourceSetsDirectlyDependingOn(sourceSet: KotlinSourceSet): Set<KotlinSourceSet> {