CommonizerIT: Implement test commonizeInterop using posix APIs
^KT-45497
This commit is contained in:
committed by
Space
parent
7f9fe6b332
commit
a0557ad937
+21
@@ -207,6 +207,27 @@ class CommonizerIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test commonizeInterop using posix APIs`() {
|
||||
with(preparedProject("commonizeInteropUsingPosixApis")) {
|
||||
build(":commonizeCInterop") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(":cinteropWithPosixTargetA")
|
||||
assertTasksExecuted(":cinteropWithPosixTargetB")
|
||||
assertTasksExecuted(":commonizeNativeDistribution")
|
||||
assertTasksExecuted(":commonizeCInterop")
|
||||
}
|
||||
|
||||
build(":compileNativeMainKotlinMetadata") {
|
||||
assertSuccessful()
|
||||
assertTasksUpToDate(":cinteropWithPosixTargetA")
|
||||
assertTasksUpToDate(":cinteropWithPosixTargetB")
|
||||
assertTasksUpToDate(":commonizeNativeDistribution")
|
||||
assertTasksUpToDate(":commonizeCInterop")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun preparedProject(name: String): Project {
|
||||
return Project(name).apply {
|
||||
setupWorkingDir()
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
val targetA = <targetA>("targetA")
|
||||
val targetB = <targetB>("targetB")
|
||||
|
||||
val commonMain by sourceSets.getting
|
||||
val nativeMain by sourceSets.creating
|
||||
val targetAMain by sourceSets.getting
|
||||
val targetBMain by sourceSets.getting
|
||||
|
||||
nativeMain.dependsOn(commonMain)
|
||||
targetAMain.dependsOn(nativeMain)
|
||||
targetBMain.dependsOn(nativeMain)
|
||||
|
||||
sourceSets.all {
|
||||
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
|
||||
}
|
||||
|
||||
targetA.compilations.getByName("main").cinterops.create("withPosix") {
|
||||
header(file("libs/withPosix.h"))
|
||||
}
|
||||
targetB.compilations.getByName("main").cinterops.create("withPosix") {
|
||||
header(file("libs/withPosix.h"))
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.mpp.enableCInteropCommonization=true
|
||||
kotlin.native.enableDependencyPropagation=false
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
#include <sys/stat.h>
|
||||
struct stat getFileStat();
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
val kotlin_version: String by settings
|
||||
plugins {
|
||||
kotlin("multiplatform").version(kotlin_version)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import kotlinx.cinterop.useContents
|
||||
import platform.posix.stat
|
||||
import withPosix.getFileStat
|
||||
|
||||
fun main() {
|
||||
repeat(10) {
|
||||
getFileStat().useContents { score(this) }
|
||||
}
|
||||
}
|
||||
expect fun score(stat: stat): Int
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import platform.posix.stat
|
||||
|
||||
actual fun score(stat: stat): Int {
|
||||
return stat.st_blocks.toInt()
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import platform.posix.stat
|
||||
|
||||
actual fun score(stat: stat): Int {
|
||||
return stat.rawPtr.toLong().toInt()
|
||||
}
|
||||
Reference in New Issue
Block a user