diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt index f20b29931d1..47cfc76a92b 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt @@ -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) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerIT.kt index f203608bff1..724f1ffabd9 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerIT.kt @@ -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() diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/build.gradle.kts new file mode 100644 index 00000000000..edb5d3e9a30 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + kotlin("multiplatform") apply false +} + +allprojects { + repositories { + mavenLocal() + mavenCentral() + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/gradle.properties b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/gradle.properties new file mode 100644 index 00000000000..cacd80fd783 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/gradle.properties @@ -0,0 +1,4 @@ +kotlin.mpp.enableGranularSourceSetsMetadata=true +kotlin.native.enableDependencyPropagation=false +kotlin.mpp.enableCInteropCommonization=true +kotlin.mpp.enableHierarchicalCommonization=true diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/build.gradle.kts new file mode 100644 index 00000000000..ae94ea6f468 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/build.gradle.kts @@ -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().forEach { target -> + target.compilations.all { + cinterops.create("withPosix") { + header(file("libs/withPosix.h")) + } + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/libs/withPosix.h b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/libs/withPosix.h new file mode 100644 index 00000000000..d71048f7049 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/libs/withPosix.h @@ -0,0 +1,43 @@ +#include +#include +#include + +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 +}; diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/src/commonMain/kotlin/P1CommonMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/src/commonMain/kotlin/P1CommonMain.kt new file mode 100644 index 00000000000..5bc4ca23e3f --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/src/commonMain/kotlin/P1CommonMain.kt @@ -0,0 +1 @@ +object P1CommonMain \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/src/nativeInterop/cinterop/withPosix.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p1/src/nativeInterop/cinterop/withPosix.def new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/build.gradle.kts new file mode 100644 index 00000000000..48b5ef245b2 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/build.gradle.kts @@ -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().forEach { target -> + target.compilations.all { + cinterops.create("withPosix") { + header(file("libs/withPosix.h")) + } + + cinterops.create("withPosixP2") { + header(file("libs/withPosixP2.h")) + } + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/libs/withPosix.h b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/libs/withPosix.h new file mode 100644 index 00000000000..d71048f7049 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/libs/withPosix.h @@ -0,0 +1,43 @@ +#include +#include +#include + +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 +}; diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/libs/withPosixP2.h b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/libs/withPosixP2.h new file mode 100644 index 00000000000..d71048f7049 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/libs/withPosixP2.h @@ -0,0 +1,43 @@ +#include +#include +#include + +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 +}; diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/src/commonMain/kotlin/P2CommonMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/src/commonMain/kotlin/P2CommonMain.kt new file mode 100644 index 00000000000..3ee30eb47ae --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/src/commonMain/kotlin/P2CommonMain.kt @@ -0,0 +1 @@ +object P2CommonMain \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/src/nativeInterop/cinterop/withPosix.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/src/nativeInterop/cinterop/withPosix.def new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/src/nativeInterop/cinterop/withPosixP2.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/p2/src/nativeInterop/cinterop/withPosixP2.def new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/settings.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/settings.gradle.kts new file mode 100644 index 00000000000..41b18421c9b --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-47641-cinterops-compilation-dependency/settings.gradle.kts @@ -0,0 +1,13 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + } + val kotlin_version: String by settings + plugins { + kotlin("multiplatform").version(kotlin_version) + } +} + +include(":p1") +include(":p2")