[Gradle] Refactor getVisibleSourceSetsFromAssociateCompilations
To highlight the fact that there is an intersection of visible source sets of compilations where given source set participates
This commit is contained in:
committed by
Space Team
parent
f4681fb93a
commit
90a47e0488
+1
-3
@@ -36,9 +36,7 @@ internal fun getVisibleSourceSetsFromAssociateCompilations(
|
||||
return when (visibleInCompilations.size) {
|
||||
0 -> emptySet()
|
||||
1 -> visibleInCompilations.single()
|
||||
else -> visibleInCompilations.first().toMutableSet().apply {
|
||||
visibleInCompilations.subList(1, visibleInCompilations.size).forEach { retainAll(it) }
|
||||
}
|
||||
else -> visibleInCompilations.reduce { intersection, kotlinSourceSets -> intersection intersect kotlinSourceSets }
|
||||
}.toList()
|
||||
}
|
||||
|
||||
|
||||
+41
-3
@@ -10,7 +10,6 @@ package org.jetbrains.kotlin.gradle.unitTests.sources
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.getVisibleSourceSetsFromAssociateCompilations
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeAsciiOnly
|
||||
import kotlin.test.Test
|
||||
@@ -154,17 +153,56 @@ class SourceSetVisibilityFromAssociatedCompilationsTest {
|
||||
"jvmIntegrationTest".assertVisibleSourceSetsFromAssociatedCompilations("commonMain", "jvmMain", "commonTest", "jvmTest")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testVisibleSourceSetsIntersection() {
|
||||
/* Given Following Project Structure:
|
||||
commonTest
|
||||
|
|
||||
nativeTest
|
||||
|
|
||||
linuxTest
|
||||
/ \
|
||||
linuxX64Test linuxArm64Test -associatedWith-> linuxArm64Main2
|
||||
|
||||
by default each ${x}Test source sees ${x}Main and its transitive dependencies.
|
||||
*/
|
||||
kotlin.linuxArm64 {
|
||||
val test = compilations.getByName("test")
|
||||
val main2 = compilations.create("main2")
|
||||
test.associateWith(main2)
|
||||
}
|
||||
kotlin.linuxX64()
|
||||
|
||||
// Assert that linuxTest can see only source sets that
|
||||
// *ALL* its underlying compilations (linuxX64Test, linuxArm64Test)
|
||||
// can see as well (i.e. intersection of their visible source sets)
|
||||
"linuxX64Test".assertVisibleSourceSetsFromAssociatedCompilations(
|
||||
"commonMain",
|
||||
"nativeMain",
|
||||
"linuxMain",
|
||||
"linuxX64Main", // unique for given source set
|
||||
)
|
||||
"linuxArm64Test".assertVisibleSourceSetsFromAssociatedCompilations(
|
||||
"commonMain",
|
||||
"nativeMain",
|
||||
"linuxMain",
|
||||
"linuxArm64Main", // unique for given source set
|
||||
"linuxArm64Main2" // unique for given source set
|
||||
)
|
||||
"linuxTest".assertVisibleSourceSetsFromAssociatedCompilations("commonMain", "nativeMain", "linuxMain")
|
||||
}
|
||||
|
||||
private fun String.assertVisibleSourceSetsFromAssociatedCompilations(
|
||||
vararg expectedVisibleSourceSets: String
|
||||
) = assertEquals(
|
||||
expectedVisibleSourceSets.toSet(),
|
||||
getVisibleSourceSetsFromAssociateCompilations(kotlin.sourceSets.getByName(this).internal.compilations).map { it.name }.toSet()
|
||||
getVisibleSourceSetsFromAssociateCompilations(kotlin.sourceSets.getByName(this)).map { it.name }.toSet()
|
||||
)
|
||||
|
||||
private fun KotlinSourceSet.assertVisibleSourceSetsFromAssociatedCompilations(
|
||||
vararg expectedVisibleSourceSets: KotlinSourceSet
|
||||
) = assertEquals(
|
||||
expectedVisibleSourceSets.map { it.name }.toSet(),
|
||||
getVisibleSourceSetsFromAssociateCompilations(this.internal.compilations).map { it.name }.toSet()
|
||||
getVisibleSourceSetsFromAssociateCompilations(this).map { it.name }.toSet()
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user