[Gradle] Implement integration test to cover ^KT-48138

This commit is contained in:
sebastian.sellmair
2021-08-06 15:34:46 +02:00
committed by Space
parent c07dcb27df
commit 9a39b1f4d1
6 changed files with 86 additions and 0 deletions
@@ -566,6 +566,23 @@ class CommonizerIT : BaseGradleIT() {
}
}
@Test
fun `test KT-48138 commonizing c-interops when nativeTest and nativeMain have different targets`() {
with(Project("commonize-kt-48138-nativeMain-nativeTest-different-targets")) {
reportSourceSetCommonizerDependencies(this) {
val nativeMain = getCommonizerDependencies("nativeMain")
nativeMain.onlyCInterops().assertDependencyFilesMatches(".*cinterop-dummy")
nativeMain.onlyNativeDistribution().assertNotEmpty()
nativeMain.assertTargetOnAllDependencies(CommonizerTarget(LINUX_X64, LINUX_ARM64, LINUX_ARM32_HFP))
val nativeTest = getCommonizerDependencies("nativeTest")
nativeTest.onlyNativeDistribution().assertNotEmpty()
nativeTest.onlyCInterops().assertDependencyFilesMatches(".*cinterop-dummy")
nativeTest.assertTargetOnAllDependencies(CommonizerTarget(LINUX_X64, LINUX_ARM64))
}
}
}
private fun preparedProject(name: String): Project {
return Project(name).apply {
setupWorkingDir()
@@ -0,0 +1,53 @@
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
operator fun KotlinSourceSet.invoke(builder: SourceSetHierarchyBuilder.() -> Unit): KotlinSourceSet {
SourceSetHierarchyBuilder(this).builder()
return this
}
class SourceSetHierarchyBuilder(private val node: KotlinSourceSet) {
operator fun KotlinSourceSet.unaryMinus() = this.dependsOn(node)
}
plugins {
kotlin("multiplatform")
}
repositories {
mavenLocal()
}
kotlin {
linuxX64()
linuxArm64()
linuxArm32Hfp()
val commonMain by sourceSets.getting
val nativeMain by sourceSets.creating
val linuxX64Main by sourceSets.getting
val linuxArm64Main by sourceSets.getting
val linuxArm32HfpMain by sourceSets.getting
nativeMain.dependsOn(commonMain)
linuxX64Main.dependsOn(nativeMain)
linuxArm64Main.dependsOn(nativeMain)
linuxArm32HfpMain.dependsOn(nativeMain)
val commonTest by sourceSets.getting
val nativeTest by sourceSets.creating
val linuxX64Test by sourceSets.getting
val linuxArm64Test by sourceSets.getting
nativeTest.dependsOn(commonTest)
linuxX64Test.dependsOn(nativeTest)
linuxArm64Test.dependsOn(nativeTest)
/* NOTE: linuxArm32HfpTest does not depend on nativeTest */
targets.withType<KotlinNativeTarget>().forEach { target ->
target.compilations.getByName("main").cinterops.create("dummy") {
headers("libs/dummy.h")
}
}
}
@@ -0,0 +1,5 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.enableCompatibilityMetadataVariant=false
kotlin.mpp.enableIntransitiveMetadataConfiguration=true
@@ -0,0 +1,10 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
val kotlin_version: String by settings
plugins {
kotlin("multiplatform").version(kotlin_version)
}
}