[Gradle] Test cinterop dependency from composite build
KT-58471 Verification Pending
This commit is contained in:
committed by
Space Team
parent
7c47ff0819
commit
fc33892e70
+19
@@ -18,12 +18,15 @@ import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.assertMatches
|
|||||||
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.binaryCoordinates
|
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.binaryCoordinates
|
||||||
import org.jetbrains.kotlin.gradle.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.jetbrains.kotlin.gradle.util.kotlinNativeDistributionDependencies
|
import org.jetbrains.kotlin.gradle.util.kotlinNativeDistributionDependencies
|
||||||
|
import org.jetbrains.kotlin.gradle.util.replaceText
|
||||||
import org.jetbrains.kotlin.gradle.util.resolveIdeDependencies
|
import org.jetbrains.kotlin.gradle.util.resolveIdeDependencies
|
||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget.*
|
import org.jetbrains.kotlin.konan.target.KonanTarget.*
|
||||||
import org.junit.AssumptionViolatedException
|
import org.junit.AssumptionViolatedException
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.io.TempDir
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
import java.nio.file.Path
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.CRC32
|
import java.util.zip.CRC32
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
@@ -258,6 +261,22 @@ class MppIdeDependencyResolutionIT : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GradleTest
|
||||||
|
fun `test dependency on composite build with commonized cinterops`(gradleVersion: GradleVersion, @TempDir tempDir: Path) {
|
||||||
|
val includedLib = project("composite-build-with-cinterop-commonization/includedLib", gradleVersion, localRepoDir = tempDir)
|
||||||
|
project("composite-build-with-cinterop-commonization", gradleVersion, localRepoDir = tempDir) {
|
||||||
|
settingsGradleKts.replaceText("<includedLib_path>", includedLib.projectPath.toUri().toString())
|
||||||
|
// Quick fix for: KT-58815
|
||||||
|
build(":lib:copyCommonizeCInteropForIde")
|
||||||
|
resolveIdeDependencies { dependencies ->
|
||||||
|
dependencies["linuxMain"].cinteropDependencies().assertMatches(
|
||||||
|
binaryCoordinates("org.example:included-lib-cinterop-a:null:(linux_arm64, linux_x64)"),
|
||||||
|
binaryCoordinates("org.example:lib-cinterop-a:null:(linux_arm64, linux_x64)"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun Iterable<IdeaKotlinDependency>.cinteropDependencies() =
|
private fun Iterable<IdeaKotlinDependency>.cinteropDependencies() =
|
||||||
this.filterIsInstance<IdeaKotlinBinaryDependency>().filter {
|
this.filterIsInstance<IdeaKotlinBinaryDependency>().filter {
|
||||||
it.klibExtra?.isInterop == true && !it.isNativeStdlib && !it.isNativeDistribution
|
it.klibExtra?.isInterop == true && !it.isNativeStdlib && !it.isNativeDistribution
|
||||||
|
|||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.example"
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
maven("<localRepo>")
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
targetHierarchy.default()
|
||||||
|
jvm()
|
||||||
|
linuxX64()
|
||||||
|
linuxArm64()
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
api("org.example:included-lib:1.0")
|
||||||
|
api(project(":lib"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
kotlin.mpp.enableCInteropCommonization=true
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.example"
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
fun KotlinNativeTarget.cinterop(name: String = "a") {
|
||||||
|
compilations
|
||||||
|
.getByName("main")
|
||||||
|
.cinterops
|
||||||
|
.create(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
targetHierarchy.default()
|
||||||
|
|
||||||
|
jvm()
|
||||||
|
|
||||||
|
linuxX64 {
|
||||||
|
cinterop()
|
||||||
|
cinterop("b")
|
||||||
|
}
|
||||||
|
linuxArm64 {
|
||||||
|
cinterop()
|
||||||
|
cinterop("c")
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven(rootDir.resolve("<localRepo>"))
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
kotlin.mpp.enableCInteropCommonization=true
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "included-lib"
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package includedLib
|
||||||
|
|
||||||
|
class CommonMain {
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package includedLib
|
||||||
|
|
||||||
|
fun linuxArm64(
|
||||||
|
a: cinterop.a.StructA
|
||||||
|
) {
|
||||||
|
cinterop.a.a()
|
||||||
|
cinterop.c.c()
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package includedLib
|
||||||
|
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
|
import kotlinx.cinterop.alloc
|
||||||
|
import kotlinx.cinterop.memScoped
|
||||||
|
|
||||||
|
fun linuxMain() {
|
||||||
|
cinterop.a.a()
|
||||||
|
@OptIn(ExperimentalForeignApi::class)
|
||||||
|
memScoped {
|
||||||
|
alloc<cinterop.a.StructA>()
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package includedLib
|
||||||
|
|
||||||
|
fun linuxX64(
|
||||||
|
a: cinterop.a.StructA
|
||||||
|
) {
|
||||||
|
cinterop.a.a()
|
||||||
|
cinterop.b.b()
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package=cinterop.a
|
||||||
|
---
|
||||||
|
|
||||||
|
static int a() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct StructA {
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
};
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package=cinterop.b
|
||||||
|
---
|
||||||
|
|
||||||
|
static int b() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package=cinterop.c
|
||||||
|
---
|
||||||
|
|
||||||
|
static int c() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.example"
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
fun KotlinNativeTarget.cinterop(name: String = "a") {
|
||||||
|
compilations
|
||||||
|
.getByName("main")
|
||||||
|
.cinterops
|
||||||
|
.create(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
targetHierarchy.default()
|
||||||
|
|
||||||
|
jvm()
|
||||||
|
|
||||||
|
linuxX64 {
|
||||||
|
cinterop()
|
||||||
|
cinterop("b")
|
||||||
|
}
|
||||||
|
linuxArm64 {
|
||||||
|
cinterop()
|
||||||
|
cinterop("c")
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
class CommonMain {
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
fun linuxArm64(
|
||||||
|
a: cinterop.lib.a.StructA
|
||||||
|
) {
|
||||||
|
cinterop.lib.a.a()
|
||||||
|
cinterop.lib.c.c()
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
|
import kotlinx.cinterop.alloc
|
||||||
|
import kotlinx.cinterop.memScoped
|
||||||
|
|
||||||
|
fun linuxMain() {
|
||||||
|
cinterop.lib.a.a()
|
||||||
|
@OptIn(ExperimentalForeignApi::class)
|
||||||
|
memScoped {
|
||||||
|
alloc<cinterop.lib.a.StructA>()
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
fun linuxX64(
|
||||||
|
a: cinterop.lib.a.StructA
|
||||||
|
) {
|
||||||
|
cinterop.lib.a.a()
|
||||||
|
cinterop.lib.b.b()
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package=cinterop.lib.a
|
||||||
|
---
|
||||||
|
|
||||||
|
static int a() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct StructA {
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
};
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package=cinterop.lib.b
|
||||||
|
---
|
||||||
|
|
||||||
|
static int b() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package=cinterop.lib.c
|
||||||
|
---
|
||||||
|
|
||||||
|
static int c() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
includeBuild("<includedLib_path>")
|
||||||
|
include(":lib")
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun common() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun linux() {
|
||||||
|
common()
|
||||||
|
|
||||||
|
includedLib.linuxMain()
|
||||||
|
cinterop.a.a()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user