[Gradle][MPP] Add MppCInteropDependencyTransformationIT test for KT-50952
This commit is contained in:
committed by
Space
parent
e55f7459f4
commit
f7c3ed7888
+90
-9
@@ -24,23 +24,28 @@ import org.junit.Test
|
|||||||
* - dependency-mode=project: In this case p2 will just declare a regular project dependency on p1
|
* - dependency-mode=project: In this case p2 will just declare a regular project dependency on p1
|
||||||
* - dependency-mode=repository: In this case p2 will rely on a previously published version of p1
|
* - dependency-mode=repository: In this case p2 will rely on a previously published version of p1
|
||||||
*/
|
*/
|
||||||
class MppCInteropDependencyTransformationIT : BaseGradleIT() {
|
open class MppCInteropDependencyTransformationIT : BaseGradleIT() {
|
||||||
|
|
||||||
private val baseBuildOptions = defaultBuildOptions().copy(
|
protected val baseBuildOptions
|
||||||
|
get() = defaultBuildOptions().copy(
|
||||||
forceOutputToStdout = true,
|
forceOutputToStdout = true,
|
||||||
warningMode = WarningMode.Fail,
|
warningMode = WarningMode.Fail,
|
||||||
parallelTasksInProject = true,
|
parallelTasksInProject = true,
|
||||||
freeCommandLineArgs = defaultBuildOptions().freeCommandLineArgs + "-s"
|
freeCommandLineArgs = defaultBuildOptions().freeCommandLineArgs + "-s"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val projectDependencyOptions = baseBuildOptions.copy(
|
protected val projectDependencyOptions
|
||||||
|
get() = baseBuildOptions.copy(
|
||||||
freeCommandLineArgs = baseBuildOptions.freeCommandLineArgs + "-PdependencyMode=project"
|
freeCommandLineArgs = baseBuildOptions.freeCommandLineArgs + "-PdependencyMode=project"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val repositoryDependencyOptions = baseBuildOptions.copy(
|
protected val repositoryDependencyOptions
|
||||||
|
get() = baseBuildOptions.copy(
|
||||||
freeCommandLineArgs = baseBuildOptions.freeCommandLineArgs + "-PdependencyMode=repository"
|
freeCommandLineArgs = baseBuildOptions.freeCommandLineArgs + "-PdependencyMode=repository"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class ComplexProject : MppCInteropDependencyTransformationIT() {
|
||||||
|
|
||||||
private val project by lazy { Project("cinterop-MetadataDependencyTransformation") }
|
private val project by lazy { Project("cinterop-MetadataDependencyTransformation") }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -208,7 +213,7 @@ class MppCInteropDependencyTransformationIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test - transformation - UP-TO-DATE behaviour`() {
|
fun `test - transformation - UP-TO-DATE behaviour - on p3`() {
|
||||||
publishP1ToBuildRepository()
|
publishP1ToBuildRepository()
|
||||||
project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) {
|
project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = repositoryDependencyOptions) {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
@@ -253,17 +258,93 @@ class MppCInteropDependencyTransformationIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun publishP1ToBuildRepository() {
|
|
||||||
project.build(":p1:publishAllPublicationsToBuildRepository", options = repositoryDependencyOptions) {
|
@Test
|
||||||
|
fun `test - transformation - UP-TO-DATE behaviour - on removing and adding targets - on p2 - dependencyMode=repository`() {
|
||||||
|
publishP1ToBuildRepository()
|
||||||
|
`test - transformation - UP-TO-DATE behaviour - on removing and adding targets - on p2`(repositoryDependencyOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
private fun `test - transformation - UP-TO-DATE behaviour - on removing and adding targets - on p2 - dependencyMode=project`() {
|
||||||
|
`test - transformation - UP-TO-DATE behaviour - on removing and adding targets - on p2`(projectDependencyOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun `test - transformation - UP-TO-DATE behaviour - on removing and adding targets - on p2`(options: BuildOptions) {
|
||||||
|
project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = options) {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project.build(":p3:transformNativeMainCInteropDependenciesMetadata", options = options) {
|
||||||
|
assertTasksUpToDate(":p3:transformNativeMainCInteropDependenciesMetadata")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CompiledProject.assertProjectDependencyMode() {
|
private fun publishP1ToBuildRepository() = project.publishP1ToBuildRepository()
|
||||||
|
}
|
||||||
|
|
||||||
|
class KT46198 : MppCInteropDependencyTransformationIT() {
|
||||||
|
private val project by lazy { Project("cinterop-MetadataDependencyTransformation-kt-50952") }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test UP-TO-DATE - when changing consumer targets - dependencyMode=repository`() {
|
||||||
|
project.publishP1ToBuildRepository()
|
||||||
|
`test UP-TO-DATE - when changing consumer targets`(repositoryDependencyOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test UP-TO-DATE - when changing consumer targets - dependencyMode=project`() {
|
||||||
|
`test UP-TO-DATE - when changing consumer targets`(projectDependencyOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun `test UP-TO-DATE - when changing consumer targets`(options: BuildOptions) {
|
||||||
|
project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = options) {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
|
||||||
|
project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = options) {
|
||||||
|
assertSuccessful()
|
||||||
|
assertTasksNotExecuted(":p2:transformCommonMainCInteropDependenciesMetadata")
|
||||||
|
assertTasksUpToDate(":p2:transformCommonMainCInteropDependenciesMetadata")
|
||||||
|
}
|
||||||
|
|
||||||
|
val optionsWithAdditionalTargetEnabled = options.withFreeCommandLineArgument("-Pp2.enableLinuxArm32Hfp")
|
||||||
|
|
||||||
|
project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = optionsWithAdditionalTargetEnabled) {
|
||||||
|
assertSuccessful()
|
||||||
|
assertTasksExecuted(":p2:transformCommonMainCInteropDependenciesMetadata")
|
||||||
|
}
|
||||||
|
|
||||||
|
project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = optionsWithAdditionalTargetEnabled) {
|
||||||
|
assertSuccessful()
|
||||||
|
assertTasksNotExecuted(":p2:transformCommonMainCInteropDependenciesMetadata")
|
||||||
|
assertTasksUpToDate(":p2:transformCommonMainCInteropDependenciesMetadata")
|
||||||
|
}
|
||||||
|
|
||||||
|
project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = options) {
|
||||||
|
assertSuccessful()
|
||||||
|
assertTasksExecuted(":p2:transformCommonMainCInteropDependenciesMetadata")
|
||||||
|
}
|
||||||
|
|
||||||
|
project.build(":p2:transformCommonMainCInteropDependenciesMetadata", options = options) {
|
||||||
|
assertSuccessful()
|
||||||
|
assertTasksNotExecuted(":p2:transformCommonMainCInteropDependenciesMetadata")
|
||||||
|
assertTasksUpToDate(":p2:transformCommonMainCInteropDependenciesMetadata")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun CompiledProject.assertProjectDependencyMode() {
|
||||||
assertContains("dependencyMode = 'project'")
|
assertContains("dependencyMode = 'project'")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CompiledProject.assertRepositoryDependencyMode() {
|
protected fun CompiledProject.assertRepositoryDependencyMode() {
|
||||||
assertContains("dependencyMode = 'repository'")
|
assertContains("dependencyMode = 'repository'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun Project.publishP1ToBuildRepository() {
|
||||||
|
build(":p1:publishAllPublicationsToBuildRepository", options = repositoryDependencyOptions) {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform") apply false
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
google()
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
kotlin.mpp.enableCInteropCommonization=true
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||||
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
version = "1.0.0-SNAPSHOT"
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = "build"
|
||||||
|
url = rootProject.buildDir.resolve("repo").toURI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxArm32Hfp()
|
||||||
|
val targetsWithInterop = listOf(linuxX64(), linuxArm64())
|
||||||
|
|
||||||
|
targets.withType<KotlinNativeTarget>().forEach { target ->
|
||||||
|
if (!HostManager().isEnabled(target.konanTarget)) {
|
||||||
|
error("Expected all targets to be supported. ${target.konanTarget} is disabled on this host!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val commonMain by sourceSets.getting
|
||||||
|
val withInteropMain by sourceSets.creating
|
||||||
|
val linuxX64Main by sourceSets.getting
|
||||||
|
val linuxArm64Main by sourceSets.getting
|
||||||
|
|
||||||
|
withInteropMain.dependsOn(commonMain)
|
||||||
|
linuxX64Main.dependsOn(withInteropMain)
|
||||||
|
linuxArm64Main.dependsOn(withInteropMain)
|
||||||
|
|
||||||
|
targetsWithInterop.forEach { target ->
|
||||||
|
target.compilations.getByName("main").cinterops.create("withPosix") {
|
||||||
|
this.packageName = "withPosix"
|
||||||
|
header(file("libs/withPosix.h"))
|
||||||
|
}
|
||||||
|
target.compilations.getByName("main").cinterops.create("simple") {
|
||||||
|
header(file("libs/simple.h"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
void simpleInterop();
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
#include <sys/stat.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
struct stat getStructFromPosix();
|
||||||
|
|
||||||
|
struct stat* getStructPointerFromPosix();
|
||||||
|
|
||||||
|
struct MyStruct getMyStruct();
|
||||||
|
|
||||||
|
struct MyStruct* getMyStructPointer();
|
||||||
|
|
||||||
|
struct MyStruct {
|
||||||
|
struct stat posixProperty;
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
long long longProperty;
|
||||||
|
#else
|
||||||
|
long longProperty;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
double doubleProperty;
|
||||||
|
|
||||||
|
int32_t int32tProperty;
|
||||||
|
|
||||||
|
int64_t int64tProperty;
|
||||||
|
|
||||||
|
#if __linux__
|
||||||
|
bool linuxOnlyProperty;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __APPLE__
|
||||||
|
bool appleOnlyProperty;
|
||||||
|
#include "TargetConditionals.h"
|
||||||
|
#if TARGET_OS_IPHONE
|
||||||
|
bool iosOnlyProperty;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
bool windowsOnlyProperty;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
object P1CommonMain
|
||||||
|
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||||
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url = rootProject.buildDir.resolve("repo").toURI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64()
|
||||||
|
linuxArm64()
|
||||||
|
|
||||||
|
if (properties.containsKey("p2.enableLinuxArm32Hfp")) {
|
||||||
|
linuxArm32Hfp()
|
||||||
|
}
|
||||||
|
|
||||||
|
targets.withType<KotlinNativeTarget>().configureEach {
|
||||||
|
if (!HostManager().isEnabled(konanTarget)) {
|
||||||
|
error("Expected all targets to be supported. $konanTarget is disabled on this host!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets.commonMain.get().dependencies {
|
||||||
|
when (project.properties["dependencyMode"]?.toString()) {
|
||||||
|
null -> {
|
||||||
|
logger.warn("dependencyMode = null -> Using 'project'")
|
||||||
|
implementation(project(":p1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
"project" -> {
|
||||||
|
logger.quiet("dependencyMode = 'project'")
|
||||||
|
implementation(project(":p1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
"repository" -> {
|
||||||
|
logger.quiet("dependencyMode = 'repository'")
|
||||||
|
implementation("kotlin-multiplatform-projects:p1:1.0.0-SNAPSHOT")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
rootProject.name = "kotlin-multiplatform-projects"
|
||||||
|
|
||||||
|
include(":p1")
|
||||||
|
include(":p2")
|
||||||
Reference in New Issue
Block a user