[Gradle] CommonizerIT: Add test asserting that cinterop commonization does not depend on any source compilation
^KT-47641
This commit is contained in:
committed by
Space
parent
a353719a6b
commit
8e6f84d5cd
+13
-1
@@ -517,7 +517,7 @@ abstract class BaseGradleIT {
|
||||
}
|
||||
|
||||
fun CompiledProject.assertNotContains(regex: Regex) {
|
||||
assertNull(regex.find(output), "Output should not contain '$regex'")
|
||||
assertNull(regex.find(output)?.value, "Output should not contain '$regex'")
|
||||
}
|
||||
|
||||
fun CompiledProject.assertNoWarnings(sanitize: (String) -> String = { it }) {
|
||||
@@ -670,6 +670,12 @@ abstract class BaseGradleIT {
|
||||
}
|
||||
}
|
||||
|
||||
fun CompiledProject.assertTasksRegisteredRegex(vararg tasks: String) {
|
||||
for (task in tasks) {
|
||||
assertContainsRegex("'Register task $task'".toRegex())
|
||||
}
|
||||
}
|
||||
|
||||
fun CompiledProject.assertTasksNotRegistered(vararg tasks: String) {
|
||||
for (task in tasks) {
|
||||
assertNotContains("'Register task $task'")
|
||||
@@ -694,6 +700,12 @@ abstract class BaseGradleIT {
|
||||
}
|
||||
}
|
||||
|
||||
fun CompiledProject.assertTasksNotRealizedRegex(vararg tasks: String) {
|
||||
for (task in tasks) {
|
||||
assertNotContains("'Realize task $task'".toRegex())
|
||||
}
|
||||
}
|
||||
|
||||
fun CompiledProject.assertTasksRegisteredAndNotRealized(vararg tasks: String) {
|
||||
assertTasksRegistered(*tasks)
|
||||
assertTasksNotRealized(*tasks)
|
||||
|
||||
+22
@@ -349,6 +349,28 @@ class CommonizerIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test KT-47641 commonizing c-interops does not depend on any source compilation`() {
|
||||
with(Project("commonize-kt-47641-cinterops-compilation-dependency")) {
|
||||
build("commonizeCInterop", options = BuildOptions(forceOutputToStdout = true)) {
|
||||
assertTasksExecuted(":p1:commonizeCInterop")
|
||||
assertTasksExecuted(":p2:commonizeCInterop")
|
||||
|
||||
assertTasksExecuted(":p1:cinteropTestWithPosix.*")
|
||||
assertTasksExecuted(":p2:cinteropTestWithPosix.*")
|
||||
assertTasksExecuted(":p2:cinteropTestWithPosixP2.*")
|
||||
|
||||
/* Make sure that we correctly reference any compile tasks in this test (test is useless otherwise) */
|
||||
assertTasksRegisteredRegex(":p1.*compile.*")
|
||||
assertTasksRegisteredRegex(":p2.*compile.*")
|
||||
|
||||
/* CInterops *shall not* require any compilation */
|
||||
assertTasksNotExecuted(":p1.*compile.*")
|
||||
assertTasksNotExecuted(":p2.*compile.*")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun preparedProject(name: String): Project {
|
||||
return Project(name).apply {
|
||||
setupWorkingDir()
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.native.enableDependencyPropagation=false
|
||||
kotlin.mpp.enableCInteropCommonization=true
|
||||
kotlin.mpp.enableHierarchicalCommonization=true
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js().nodejs()
|
||||
linuxX64()
|
||||
macosX64()
|
||||
mingwX64("windowsX64")
|
||||
mingwX86("windowsX86")
|
||||
|
||||
targets.withType<KotlinNativeTarget>().forEach { target ->
|
||||
target.compilations.all {
|
||||
cinterops.create("withPosix") {
|
||||
header(file("libs/withPosix.h"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+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
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
object P1CommonMain
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js().nodejs()
|
||||
|
||||
linuxX64()
|
||||
macosX64()
|
||||
mingwX64("windowsX64")
|
||||
mingwX86("windowsX86")
|
||||
|
||||
val commonMain by sourceSets.getting
|
||||
|
||||
commonMain.dependencies {
|
||||
implementation(project(":p1"))
|
||||
}
|
||||
|
||||
targets.withType<KotlinNativeTarget>().forEach { target ->
|
||||
target.compilations.all {
|
||||
cinterops.create("withPosix") {
|
||||
header(file("libs/withPosix.h"))
|
||||
}
|
||||
|
||||
cinterops.create("withPosixP2") {
|
||||
header(file("libs/withPosixP2.h"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+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
|
||||
};
|
||||
+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
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
object P2CommonMain
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
val kotlin_version: String by settings
|
||||
plugins {
|
||||
kotlin("multiplatform").version(kotlin_version)
|
||||
}
|
||||
}
|
||||
|
||||
include(":p1")
|
||||
include(":p2")
|
||||
Reference in New Issue
Block a user