From 95a1a4e66a7798e9abdc33033bf00a8745748c2f Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Thu, 15 Apr 2021 11:17:24 +0200 Subject: [PATCH] CommonizerHierarchicalIT: Implement `test commonizeHierarchicallyMultiModule` ^KT-46107 --- .../kotlin/gradle/CommonizerHierarchicalIT.kt | 21 +++++ .../build.gradle.kts | 10 +++ .../gradle.properties | 6 ++ .../p1/build.gradle.kts | 79 ++++++++++++++++++ .../p1/libs/withPosix.h | 43 ++++++++++ .../kotlin/AppleAndLinuxMain.kt | 21 +++++ .../p1/src/appleMain/kotlin/AppleMain.kt | 22 +++++ .../p1/src/commonMain/kotlin/CommonMain.kt | 2 + .../p1/src/iosMain/kotlin/IosMain.kt | 23 ++++++ .../linuxArm64Main/kotlin/LinuxArm64Main.kt | 22 +++++ .../p1/src/linuxMain/kotlin/LinuxMain.kt | 22 +++++ .../src/linuxX64Main/kotlin/LinuxX64Main.kt | 22 +++++ .../p1/src/macosMain/kotlin/MacosMain.kt | 22 +++++ .../src/nativeInterop/cinterop/withPosix.def | 0 .../p1/src/nativeMain/kotlin/NativeMain.kt | 19 +++++ .../p1/src/windowsMain/kotlin/WindowsMain.kt | 22 +++++ .../p2/build.gradle.kts | 82 +++++++++++++++++++ .../p2/libs/withPosix.h | 48 +++++++++++ .../kotlin/AppleAndLinuxMain.kt | 21 +++++ .../p2/src/appleMain/kotlin/AppleMain.kt | 22 +++++ .../p2/src/commonMain/kotlin/CommonMain.kt | 2 + .../p2/src/iosMain/kotlin/IosMain.kt | 23 ++++++ .../linuxArm64Main/kotlin/LinuxArm64Main.kt | 22 +++++ .../p2/src/linuxMain/kotlin/LinuxMain.kt | 22 +++++ .../src/linuxX64Main/kotlin/LinuxX64Main.kt | 22 +++++ .../p2/src/macosMain/kotlin/MacosMain.kt | 22 +++++ .../nativeInterop/cinterop/withPosixOther.def | 0 .../p2/src/nativeMain/kotlin/NativeMain.kt | 19 +++++ .../p2/src/windowsMain/kotlin/WindowsMain.kt | 22 +++++ .../p3/build.gradle.kts | 78 ++++++++++++++++++ .../p3/libs/withPosix.h | 43 ++++++++++ .../kotlin/AppleAndLinuxMain.kt | 21 +++++ .../p3/src/appleMain/kotlin/AppleMain.kt | 22 +++++ .../p3/src/commonMain/kotlin/CommonMain.kt | 2 + .../p3/src/iosMain/kotlin/IosMain.kt | 23 ++++++ .../linuxArm64Main/kotlin/LinuxArm64Main.kt | 22 +++++ .../p3/src/linuxMain/kotlin/LinuxMain.kt | 22 +++++ .../src/linuxX64Main/kotlin/LinuxX64Main.kt | 22 +++++ .../p3/src/macosMain/kotlin/MacosMain.kt | 22 +++++ .../src/nativeInterop/cinterop/withPosix.def | 0 .../p3/src/nativeMain/kotlin/NativeMain.kt | 19 +++++ .../p3/src/windowsMain/kotlin/WindowsMain.kt | 22 +++++ .../settings.gradle.kts | 14 ++++ 43 files changed, 1015 insertions(+) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/gradle.properties create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/libs/withPosix.h create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/appleMain/kotlin/AppleMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/commonMain/kotlin/CommonMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/iosMain/kotlin/IosMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxArm64Main/kotlin/LinuxArm64Main.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxMain/kotlin/LinuxMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxX64Main/kotlin/LinuxX64Main.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/macosMain/kotlin/MacosMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/nativeInterop/cinterop/withPosix.def create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/nativeMain/kotlin/NativeMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/windowsMain/kotlin/WindowsMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/libs/withPosix.h create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/appleMain/kotlin/AppleMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/commonMain/kotlin/CommonMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/iosMain/kotlin/IosMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxArm64Main/kotlin/LinuxArm64Main.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxMain/kotlin/LinuxMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxX64Main/kotlin/LinuxX64Main.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/macosMain/kotlin/MacosMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/nativeInterop/cinterop/withPosixOther.def create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/nativeMain/kotlin/NativeMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/windowsMain/kotlin/WindowsMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/libs/withPosix.h create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/appleMain/kotlin/AppleMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/commonMain/kotlin/CommonMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/iosMain/kotlin/IosMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxArm64Main/kotlin/LinuxArm64Main.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxMain/kotlin/LinuxMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxX64Main/kotlin/LinuxX64Main.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/macosMain/kotlin/MacosMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/nativeInterop/cinterop/withPosix.def create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/nativeMain/kotlin/NativeMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/windowsMain/kotlin/WindowsMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/settings.gradle.kts diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerHierarchicalIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerHierarchicalIT.kt index 2ce20056284..82389594525 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerHierarchicalIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerHierarchicalIT.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.gradle import org.gradle.internal.os.OperatingSystem +import org.junit.Ignore import org.junit.Test class CommonizerHierarchicalIT : BaseGradleIT() { @@ -86,6 +87,26 @@ class CommonizerHierarchicalIT : BaseGradleIT() { } } + @Ignore("Waiting for next bootstrap compiler") + @Test + fun `test commonizeHierarchicallyMultiModule`() { + with(Project("commonizeHierarchicallyMultiModule")) { + build("assemble") { + assertSuccessful() + assertTasksExecuted(":p1:commonizeCInterop") + assertTasksExecuted(":p2:commonizeCInterop") + assertTasksExecuted(":p3:commonizeCInterop") + + /* + Commonized C-Interops are not published or forwarded to other Gradle projects. + The missing dependency will be ignored by the metadata compiler. + We still expect a warning being printed. + */ + assertContains("w: Could not find \"commonizeHierarchicallyMultiModule:p1-cinterop-withPosix\" in ") + } + } + } + private object Os { private val os = OperatingSystem.current() val canCompileApple get() = os.isMacOsX diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/build.gradle.kts new file mode 100644 index 00000000000..448f4930cb0 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + kotlin("multiplatform") apply false +} + +allprojects { + repositories { + mavenLocal() + mavenCentral() + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/gradle.properties b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/gradle.properties new file mode 100644 index 00000000000..14a6f9f265b --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/gradle.properties @@ -0,0 +1,6 @@ +kotlin.code.style=official +org.gradle.debug=false +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/commonizeHierarchicallyMultiModule/p1/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/build.gradle.kts new file mode 100644 index 00000000000..6252242da0c --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/build.gradle.kts @@ -0,0 +1,79 @@ +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget + +operator fun KotlinSourceSet.invoke(builder: SourceSetHierarchyBuilder.() -> Unit): KotlinSourceSet { + SourceSetHierarchyBuilder(this).builder() + return this +} + +class SourceSetHierarchyBuilder(private val node: KotlinSourceSet) { + operator fun KotlinSourceSet.unaryMinus() = this.dependsOn(node) +} + +plugins { + kotlin("multiplatform") +} + +kotlin { + js() + jvm() + + linuxX64() + linuxArm64() + + macosX64("macos") + ios() + + mingwX64("windowsX64") + mingwX86("windowsX86") + + val commonMain by sourceSets.getting + val concurrentMain by sourceSets.creating + val jvmMain by sourceSets.getting + val jsMain by sourceSets.getting + val nativeMain by sourceSets.creating + val appleAndLinuxMain by sourceSets.creating + val linuxMain by sourceSets.creating + val linuxX64Main by sourceSets.getting + val linuxArm64Main by sourceSets.getting + val appleMain by sourceSets.creating + val macosMain by sourceSets.getting + val iosMain by sourceSets.getting + val windowsMain by sourceSets.creating + val windowsX64Main by sourceSets.getting + val windowsX86Main by sourceSets.getting + + commonMain { + -jsMain + -concurrentMain { + -jvmMain + -nativeMain { + -appleAndLinuxMain { + -appleMain { + -iosMain + -macosMain + } + -linuxMain { + -linuxArm64Main + -linuxX64Main + } + } + -windowsMain { + -windowsX64Main + -windowsX86Main + } + } + } + } + + + sourceSets.all { + languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn") + } + + targets.withType().forEach { target -> + target.compilations.getByName("main").cinterops.create("withPosix") { + header(file("libs/withPosix.h")) + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/libs/withPosix.h b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/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/commonizeHierarchicallyMultiModule/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/commonizeHierarchicallyMultiModule/p1/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt new file mode 100644 index 00000000000..d6b2954179d --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt @@ -0,0 +1,21 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object AppleAndLinuxMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/appleMain/kotlin/AppleMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/appleMain/kotlin/AppleMain.kt new file mode 100644 index 00000000000..b2119df24b4 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/appleMain/kotlin/AppleMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object AppleMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val appleOnlyProperty: Boolean = struct.appleOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/commonMain/kotlin/CommonMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/commonMain/kotlin/CommonMain.kt new file mode 100644 index 00000000000..654793fae33 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/commonMain/kotlin/CommonMain.kt @@ -0,0 +1,2 @@ +class CommonMain { +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/iosMain/kotlin/IosMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/iosMain/kotlin/IosMain.kt new file mode 100644 index 00000000000..e4afdb6e07f --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/iosMain/kotlin/IosMain.kt @@ -0,0 +1,23 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object IosMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val appleOnly: Boolean = struct.appleOnlyProperty + val iosOnly: Boolean = struct.iosOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxArm64Main/kotlin/LinuxArm64Main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxArm64Main/kotlin/LinuxArm64Main.kt new file mode 100644 index 00000000000..f88f2b7e01c --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxArm64Main/kotlin/LinuxArm64Main.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object LinuxArm64Main { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val linuxOnlyProperty: Boolean = struct.linuxOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxMain/kotlin/LinuxMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxMain/kotlin/LinuxMain.kt new file mode 100644 index 00000000000..693a14477b6 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxMain/kotlin/LinuxMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object LinuxMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val linuxOnlyProperty: Boolean = struct.linuxOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxX64Main/kotlin/LinuxX64Main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxX64Main/kotlin/LinuxX64Main.kt new file mode 100644 index 00000000000..0bf119cfe88 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/linuxX64Main/kotlin/LinuxX64Main.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object LinuxX64Main { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val linuxOnlyProperty: Boolean = struct.linuxOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/macosMain/kotlin/MacosMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/macosMain/kotlin/MacosMain.kt new file mode 100644 index 00000000000..84d01735d9a --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/macosMain/kotlin/MacosMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object MacosMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val appleOnlyProperty: Boolean = struct.appleOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/nativeInterop/cinterop/withPosix.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/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/commonizeHierarchicallyMultiModule/p1/src/nativeMain/kotlin/NativeMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/nativeMain/kotlin/NativeMain.kt new file mode 100644 index 00000000000..148942f4698 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/nativeMain/kotlin/NativeMain.kt @@ -0,0 +1,19 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object NativeMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/windowsMain/kotlin/WindowsMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/windowsMain/kotlin/WindowsMain.kt new file mode 100644 index 00000000000..2c442617931 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p1/src/windowsMain/kotlin/WindowsMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object WindowsMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val windowsOnly: Boolean = struct.windowsOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/build.gradle.kts new file mode 100644 index 00000000000..daa84d98dfa --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/build.gradle.kts @@ -0,0 +1,82 @@ +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget + +operator fun KotlinSourceSet.invoke(builder: SourceSetHierarchyBuilder.() -> Unit): KotlinSourceSet { + SourceSetHierarchyBuilder(this).builder() + return this +} + +class SourceSetHierarchyBuilder(private val node: KotlinSourceSet) { + operator fun KotlinSourceSet.unaryMinus() = this.dependsOn(node) +} + +plugins { + kotlin("multiplatform") +} + +kotlin { + js() + jvm() + + linuxX64() + linuxArm64() + + macosX64("macos") + ios() + + mingwX64("windowsX64") + mingwX86("windowsX86") + + val commonMain by sourceSets.getting + val concurrentMain by sourceSets.creating + val jvmMain by sourceSets.getting + val jsMain by sourceSets.getting + val nativeMain by sourceSets.creating + val appleAndLinuxMain by sourceSets.creating + val linuxMain by sourceSets.creating + val linuxX64Main by sourceSets.getting + val linuxArm64Main by sourceSets.getting + val appleMain by sourceSets.creating + val macosMain by sourceSets.getting + val iosMain by sourceSets.getting + val windowsMain by sourceSets.creating + val windowsX64Main by sourceSets.getting + val windowsX86Main by sourceSets.getting + + commonMain { + -jsMain + -concurrentMain { + -jvmMain + -nativeMain { + -appleAndLinuxMain { + -appleMain { + -iosMain + -macosMain + } + -linuxMain { + -linuxArm64Main + -linuxX64Main + } + } + -windowsMain { + -windowsX64Main + -windowsX86Main + } + } + } + } + + commonMain.dependencies { + implementation(project(":p1")) + } + + sourceSets.all { + languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn") + } + + targets.withType().forEach { target -> + target.compilations.getByName("main").cinterops.create("withPosixOther") { + header(file("libs/withPosix.h")) + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/libs/withPosix.h b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/libs/withPosix.h new file mode 100644 index 00000000000..694da47fdc7 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/libs/withPosix.h @@ -0,0 +1,48 @@ +#include +#include +#include + +/* +Special function that will differentiate this header file from p1/../withPosix.h and p3/../withPosix.h +*/ +void p2(); + +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/commonizeHierarchicallyMultiModule/p2/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt new file mode 100644 index 00000000000..2ee087ed360 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt @@ -0,0 +1,21 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosixOther.getMyStructPointer +import withPosixOther.getStructFromPosix +import withPosixOther.getStructPointerFromPosix + +object AppleAndLinuxMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/appleMain/kotlin/AppleMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/appleMain/kotlin/AppleMain.kt new file mode 100644 index 00000000000..9a46c0d44ec --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/appleMain/kotlin/AppleMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosixOther.getMyStructPointer +import withPosixOther.getStructFromPosix +import withPosixOther.getStructPointerFromPosix + +object AppleMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val appleOnlyProperty: Boolean = struct.appleOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/commonMain/kotlin/CommonMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/commonMain/kotlin/CommonMain.kt new file mode 100644 index 00000000000..654793fae33 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/commonMain/kotlin/CommonMain.kt @@ -0,0 +1,2 @@ +class CommonMain { +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/iosMain/kotlin/IosMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/iosMain/kotlin/IosMain.kt new file mode 100644 index 00000000000..f3c5511f9c5 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/iosMain/kotlin/IosMain.kt @@ -0,0 +1,23 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosixOther.getMyStructPointer +import withPosixOther.getStructFromPosix +import withPosixOther.getStructPointerFromPosix + +object IosMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val appleOnly: Boolean = struct.appleOnlyProperty + val iosOnly: Boolean = struct.iosOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxArm64Main/kotlin/LinuxArm64Main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxArm64Main/kotlin/LinuxArm64Main.kt new file mode 100644 index 00000000000..05f25aea817 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxArm64Main/kotlin/LinuxArm64Main.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosixOther.getMyStructPointer +import withPosixOther.getStructFromPosix +import withPosixOther.getStructPointerFromPosix + +object LinuxArm64Main { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val linuxOnlyProperty: Boolean = struct.linuxOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxMain/kotlin/LinuxMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxMain/kotlin/LinuxMain.kt new file mode 100644 index 00000000000..449a2cae9a6 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxMain/kotlin/LinuxMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosixOther.getMyStructPointer +import withPosixOther.getStructFromPosix +import withPosixOther.getStructPointerFromPosix + +object LinuxMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val linuxOnlyProperty: Boolean = struct.linuxOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxX64Main/kotlin/LinuxX64Main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxX64Main/kotlin/LinuxX64Main.kt new file mode 100644 index 00000000000..261ba68a279 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/linuxX64Main/kotlin/LinuxX64Main.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosixOther.getMyStructPointer +import withPosixOther.getStructFromPosix +import withPosixOther.getStructPointerFromPosix + +object LinuxX64Main { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val linuxOnlyProperty: Boolean = struct.linuxOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/macosMain/kotlin/MacosMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/macosMain/kotlin/MacosMain.kt new file mode 100644 index 00000000000..6dcbe11d950 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/macosMain/kotlin/MacosMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosixOther.getMyStructPointer +import withPosixOther.getStructFromPosix +import withPosixOther.getStructPointerFromPosix + +object MacosMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val appleOnlyProperty: Boolean = struct.appleOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/nativeInterop/cinterop/withPosixOther.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/nativeInterop/cinterop/withPosixOther.def new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/nativeMain/kotlin/NativeMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/nativeMain/kotlin/NativeMain.kt new file mode 100644 index 00000000000..9ea1ec4b00a --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/nativeMain/kotlin/NativeMain.kt @@ -0,0 +1,19 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosixOther.getMyStructPointer +import withPosixOther.getStructFromPosix +import withPosixOther.getStructPointerFromPosix + +object NativeMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/windowsMain/kotlin/WindowsMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/windowsMain/kotlin/WindowsMain.kt new file mode 100644 index 00000000000..d1296035368 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p2/src/windowsMain/kotlin/WindowsMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosixOther.getMyStructPointer +import withPosixOther.getStructFromPosix +import withPosixOther.getStructPointerFromPosix + +object WindowsMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val windowsOnly: Boolean = struct.windowsOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/build.gradle.kts new file mode 100644 index 00000000000..3553dae2270 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/build.gradle.kts @@ -0,0 +1,78 @@ +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget + +operator fun KotlinSourceSet.invoke(builder: SourceSetHierarchyBuilder.() -> Unit): KotlinSourceSet { + SourceSetHierarchyBuilder(this).builder() + return this +} + +class SourceSetHierarchyBuilder(private val node: KotlinSourceSet) { + operator fun KotlinSourceSet.unaryMinus() = this.dependsOn(node) +} + +plugins { + kotlin("multiplatform") +} + +kotlin { + js() + jvm() + + linuxX64() + linuxArm64() + + macosX64("macos") + ios() + + mingwX64("windowsX64") + mingwX86("windowsX86") + + val commonMain by sourceSets.getting + val concurrentMain by sourceSets.creating + val jvmMain by sourceSets.getting + val jsMain by sourceSets.getting + val nativeMain by sourceSets.creating + val appleAndLinuxMain by sourceSets.creating + val linuxMain by sourceSets.creating + val linuxX64Main by sourceSets.getting + val linuxArm64Main by sourceSets.getting + val appleMain by sourceSets.creating + val macosMain by sourceSets.getting + val iosMain by sourceSets.getting + val windowsMain by sourceSets.creating + val windowsX64Main by sourceSets.getting + val windowsX86Main by sourceSets.getting + + commonMain { + -jsMain + -concurrentMain { + -jvmMain + -nativeMain { + -appleAndLinuxMain { + -appleMain { + -iosMain + -macosMain + } + -linuxMain { + -linuxArm64Main + -linuxX64Main + } + } + -windowsMain { + -windowsX64Main + -windowsX86Main + } + } + } + } + + sourceSets.all { + languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn") + } + + targets.withType().forEach { target -> + target.compilations.getByName("main").cinterops.create("withPosix") { + header(file("libs/withPosix.h")) + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/libs/withPosix.h b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/libs/withPosix.h new file mode 100644 index 00000000000..d71048f7049 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/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/commonizeHierarchicallyMultiModule/p3/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt new file mode 100644 index 00000000000..d6b2954179d --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/appleAndLinuxMain/kotlin/AppleAndLinuxMain.kt @@ -0,0 +1,21 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object AppleAndLinuxMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/appleMain/kotlin/AppleMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/appleMain/kotlin/AppleMain.kt new file mode 100644 index 00000000000..b2119df24b4 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/appleMain/kotlin/AppleMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object AppleMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val appleOnlyProperty: Boolean = struct.appleOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/commonMain/kotlin/CommonMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/commonMain/kotlin/CommonMain.kt new file mode 100644 index 00000000000..654793fae33 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/commonMain/kotlin/CommonMain.kt @@ -0,0 +1,2 @@ +class CommonMain { +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/iosMain/kotlin/IosMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/iosMain/kotlin/IosMain.kt new file mode 100644 index 00000000000..e4afdb6e07f --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/iosMain/kotlin/IosMain.kt @@ -0,0 +1,23 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object IosMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val appleOnly: Boolean = struct.appleOnlyProperty + val iosOnly: Boolean = struct.iosOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxArm64Main/kotlin/LinuxArm64Main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxArm64Main/kotlin/LinuxArm64Main.kt new file mode 100644 index 00000000000..f88f2b7e01c --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxArm64Main/kotlin/LinuxArm64Main.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object LinuxArm64Main { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val linuxOnlyProperty: Boolean = struct.linuxOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxMain/kotlin/LinuxMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxMain/kotlin/LinuxMain.kt new file mode 100644 index 00000000000..693a14477b6 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxMain/kotlin/LinuxMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object LinuxMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val linuxOnlyProperty: Boolean = struct.linuxOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxX64Main/kotlin/LinuxX64Main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxX64Main/kotlin/LinuxX64Main.kt new file mode 100644 index 00000000000..0bf119cfe88 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/linuxX64Main/kotlin/LinuxX64Main.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object LinuxX64Main { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val linuxOnlyProperty: Boolean = struct.linuxOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/macosMain/kotlin/MacosMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/macosMain/kotlin/MacosMain.kt new file mode 100644 index 00000000000..84d01735d9a --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/macosMain/kotlin/MacosMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object MacosMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val appleOnlyProperty: Boolean = struct.appleOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/nativeInterop/cinterop/withPosix.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/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/commonizeHierarchicallyMultiModule/p3/src/nativeMain/kotlin/NativeMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/nativeMain/kotlin/NativeMain.kt new file mode 100644 index 00000000000..148942f4698 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/nativeMain/kotlin/NativeMain.kt @@ -0,0 +1,19 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object NativeMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/windowsMain/kotlin/WindowsMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/windowsMain/kotlin/WindowsMain.kt new file mode 100644 index 00000000000..2c442617931 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/p3/src/windowsMain/kotlin/WindowsMain.kt @@ -0,0 +1,22 @@ +@file:Suppress("unused") + +import kotlinx.cinterop.pointed +import platform.posix.stat +import withPosix.getMyStructPointer +import withPosix.getStructFromPosix +import withPosix.getStructPointerFromPosix + +object WindowsMain { + val structFromPosix = getStructFromPosix() + val structPointerFromPosix = getStructPointerFromPosix() + + object MyStruct { + val struct = getMyStructPointer()?.pointed ?: error("Missing my struct") + val posixProperty: stat = struct.posixProperty + val longProperty: Long = struct.longProperty + val doubleProperty: Double = struct.doubleProperty + val int32tProperty: Int = struct.int32tProperty + val int64TProperty: Long = struct.int64tProperty + val windowsOnly: Boolean = struct.windowsOnlyProperty + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/settings.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/settings.gradle.kts new file mode 100644 index 00000000000..006882d6c91 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyMultiModule/settings.gradle.kts @@ -0,0 +1,14 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + } + val kotlin_version: String by settings + plugins { + kotlin("multiplatform").version(kotlin_version) + } +} + +include(":p1") +include(":p2") +include(":p3")