[Gradle] Introduce getHostSpecificMainSharedSourceSets
^KT-48839
This commit is contained in:
committed by
Space Team
parent
42cda2633d
commit
5f26649246
+21
@@ -186,6 +186,27 @@ internal fun getHostSpecificSourceSets(project: Project): Set<KotlinSourceSet> {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all host-specific source sets that will be compiled to two or more targets
|
||||
*/
|
||||
internal fun getHostSpecificMainSharedSourceSets(project: Project): Set<KotlinSourceSet> {
|
||||
fun KotlinSourceSet.testOnly(): Boolean = internal.compilations.all { it.isTest() }
|
||||
|
||||
fun KotlinSourceSet.isCompiledToSingleTarget(): Boolean {
|
||||
return internal
|
||||
.compilations
|
||||
// if for some reason [it.target] is not a [KotlinNativeTarget] then assume that it is not a host-specific source set
|
||||
.distinctBy { (it.target as? KotlinNativeTarget)?.konanTarget ?: return false }
|
||||
.size == 1
|
||||
}
|
||||
|
||||
return getHostSpecificSourceSets(project)
|
||||
.filterNot { it.testOnly() }
|
||||
.filterNot { it.isCompiledToSingleTarget() }
|
||||
.toSet()
|
||||
}
|
||||
|
||||
|
||||
abstract class KotlinNativeTargetWithTests<T : KotlinNativeBinaryTestRun>(
|
||||
project: Project,
|
||||
konanTarget: KonanTarget
|
||||
|
||||
+62
@@ -10,10 +10,12 @@ package org.jetbrains.kotlin.gradle.sources
|
||||
import org.jetbrains.kotlin.gradle.assertAllImplementationsAlsoImplement
|
||||
import org.jetbrains.kotlin.gradle.buildProjectWithMPP
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.kotlin
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.InternalKotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.getHostSpecificMainSharedSourceSets
|
||||
import org.jetbrains.kotlin.gradle.reflections
|
||||
import org.junit.jupiter.api.assertAll
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
@@ -106,4 +108,64 @@ class InternalKotlinSourceSetTest {
|
||||
linuxX64Main.internal.withDependsOnClosure
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test getHostSpecificMainSharedSourceSets`() {
|
||||
val project = buildProjectWithMPP {
|
||||
kotlin {
|
||||
jvm()
|
||||
linuxX64()
|
||||
linuxArm64()
|
||||
ios() // host specific from preset
|
||||
}
|
||||
}
|
||||
|
||||
val kotlin = project.multiplatformExtension
|
||||
|
||||
with(kotlin.sourceSets) {
|
||||
val commonMain = getByName("commonMain")
|
||||
val commonTest = getByName("commonTest")
|
||||
val iosMain = getByName("iosMain")
|
||||
val iosTest = getByName("iosTest")
|
||||
|
||||
val iosX64Main = getByName("iosX64Main")
|
||||
val iosArm64Main = getByName("iosArm64Main")
|
||||
val iosX64Test = getByName("iosX64Test")
|
||||
val iosArm64Test = getByName("iosArm64Test")
|
||||
|
||||
val linuxX64Main = getByName("linuxX64Main")
|
||||
val linuxArm64Main = getByName("linuxArm64Main")
|
||||
val linuxX64Test = getByName("linuxX64Test")
|
||||
val linuxArm64Test = getByName("linuxArm64Test")
|
||||
|
||||
// common -> ios2 -> ios
|
||||
create("ios2Main") { it.dependsOn(commonMain); iosMain.dependsOn(it) }
|
||||
create("ios2Test") { it.dependsOn(commonTest); iosTest.dependsOn(it) }
|
||||
|
||||
// ... -> ios -> ios2{X64,Arm64} -> ios{X64,Arm64}
|
||||
create("ios2X64Main") { it.dependsOn(iosMain); iosX64Main.dependsOn(it) }
|
||||
create("ios2X64Test") { it.dependsOn(iosTest); iosX64Test.dependsOn(it) }
|
||||
create("ios2Arm64Main") { it.dependsOn(iosMain); iosArm64Main.dependsOn(it) }
|
||||
create("ios2Arm64Test") { it.dependsOn(iosTest); iosArm64Test.dependsOn(it) }
|
||||
|
||||
// common -> linux
|
||||
create("linuxMain") {
|
||||
it.dependsOn(commonMain)
|
||||
linuxX64Main.dependsOn(it)
|
||||
linuxArm64Main.dependsOn(it)
|
||||
}
|
||||
create("linuxTest") {
|
||||
it.dependsOn(commonTest)
|
||||
linuxX64Test.dependsOn(it)
|
||||
linuxArm64Test.dependsOn(it)
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
val expected = listOf("iosMain", "ios2Main").sorted()
|
||||
val actual = getHostSpecificMainSharedSourceSets(project).map { it.name }.sorted()
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user