[Gradle] Implement test KT-48118 c-interops available in commonMain
Integration Test project was taken from: https://github.com/4qa/kotlin-multiplatform-issues/tree/cinterop-common The issue seems to be twofold: 1) The old `compileKotlinMetadata` task is still found, even when compatibilityMetadataVariant is disabled 2) The shared native compilation for commonMain can't be found, because it is not listing its default source set: (see: https://youtrack.jetbrains.com/issue/KT-45412) Covers ^KT-48118
This commit is contained in:
committed by
Space
parent
37d25a58e8
commit
b1c5c10233
+23
@@ -515,6 +515,29 @@ class CommonizerIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test KT-48118 c-interops available in commonMain`() {
|
||||
with(Project("commonize-kt-48118-c-interop-in-common-main")) {
|
||||
reportSourceSetCommonizerDependencies(this) {
|
||||
val upperMain = getCommonizerDependencies("upperMain")
|
||||
upperMain.onlyCInterops().assertDependencyFilesMatches(".*cinterop-dummy")
|
||||
upperMain.onlyNativeDistribution().assertNotEmpty()
|
||||
|
||||
val commonMain = getCommonizerDependencies("commonMain")
|
||||
commonMain.onlyCInterops().assertDependencyFilesMatches(".*cinterop-dummy")
|
||||
commonMain.onlyNativeDistribution().assertNotEmpty()
|
||||
}
|
||||
|
||||
build(":compileCommonMainKotlinMetadata") {
|
||||
assertSuccessful()
|
||||
}
|
||||
|
||||
build(":compileUpperMainKotlinMetadata") {
|
||||
assertSuccessful()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test KT-47641 commonizing c-interops does not depend on any source compilation`() {
|
||||
with(Project("commonize-kt-47641-cinterops-compilation-dependency")) {
|
||||
|
||||
+17
-2
@@ -38,6 +38,15 @@ data class SourceSetCommonizerDependencies(
|
||||
)
|
||||
}
|
||||
|
||||
fun onlyNativeDistribution(): SourceSetCommonizerDependencies {
|
||||
return SourceSetCommonizerDependencies(
|
||||
sourceSetName,
|
||||
dependencies.filter { dependency ->
|
||||
dependency.file.allParents.any { parentFile -> parentFile.name == ".konan" }
|
||||
}.toSet()
|
||||
)
|
||||
}
|
||||
|
||||
fun assertTargetOnAllDependencies(target: CommonizerTarget) {
|
||||
dependencies.forEach { dependency ->
|
||||
if (dependency.target != target) {
|
||||
@@ -52,6 +61,12 @@ data class SourceSetCommonizerDependencies(
|
||||
}
|
||||
}
|
||||
|
||||
fun assertNotEmpty() {
|
||||
if (dependencies.isEmpty()) {
|
||||
fail("$sourceSetName: Missing dependencies")
|
||||
}
|
||||
}
|
||||
|
||||
fun assertDependencyFilesMatches(@Language("RegExp") @RegEx @RegExp vararg fileMatchers: String?) {
|
||||
assertDependencyFilesMatches(fileMatchers.filterNotNull().map(::Regex).toSet())
|
||||
}
|
||||
@@ -137,12 +152,12 @@ private const val dollar = "\$"
|
||||
|
||||
private val taskSourceCode = """
|
||||
tasks.register("reportCommonizerSourceSetDependencies") {
|
||||
kotlin.sourceSets.withType(DefaultKotlinSourceSet::class).all {
|
||||
kotlin.sourceSets.withType(org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet::class).all {
|
||||
inputs.files(configurations.getByName(intransitiveMetadataConfigurationName))
|
||||
}
|
||||
|
||||
doLast {
|
||||
kotlin.sourceSets.filterIsInstance<DefaultKotlinSourceSet>().forEach { sourceSet ->
|
||||
kotlin.sourceSets.filterIsInstance<org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet>().forEach { sourceSet ->
|
||||
val configuration = configurations.getByName(sourceSet.intransitiveMetadataConfigurationName)
|
||||
val dependencies = configuration.files
|
||||
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
linuxArm64() {
|
||||
compilations.getByName("main") {
|
||||
cinterops {
|
||||
create("dummy") {
|
||||
headers("libs/include/dummy/dummy.h")
|
||||
compilerOpts.add("-Ilibs/include")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
linuxX64(){
|
||||
compilations.getByName("main") {
|
||||
cinterops {
|
||||
create("dummy") {
|
||||
headers("libs/include/dummy/dummy.h")
|
||||
compilerOpts.add("-Ilibs/include")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val commonMain by getting
|
||||
|
||||
val linuxArm64Main by getting
|
||||
val linuxX64Main by getting
|
||||
|
||||
val upperMain by creating {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
|
||||
val lowerMain by creating {
|
||||
dependsOn(upperMain)
|
||||
linuxArm64Main.dependsOn(this)
|
||||
linuxX64Main.dependsOn(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.native.enableDependencyPropagation=false
|
||||
kotlin.mpp.enableCInteropCommonization=true
|
||||
kotlin.mpp.enableCompatibilityMetadataVariant=false
|
||||
kotlin.mpp.enableIntransitiveMetadataConfiguration=true
|
||||
+1
@@ -0,0 +1 @@
|
||||
int max(int num1, int num2);
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
val kotlin_version: String by settings
|
||||
plugins {
|
||||
kotlin("multiplatform").version(kotlin_version)
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun c(){
|
||||
dummy.max(2,3)
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun sn(){
|
||||
dummy.max(1,2)
|
||||
}
|
||||
Reference in New Issue
Block a user