mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
[Gradle] Implement CommonizerHierarchicalIT integration test
This commit is contained in:
3
.idea/dictionaries/sebastiansellmair.xml
generated
3
.idea/dictionaries/sebastiansellmair.xml
generated
@@ -3,6 +3,7 @@
|
||||
<words>
|
||||
<w>cinterops</w>
|
||||
<w>interops</w>
|
||||
<w>klibrary</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
</component>
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
import org.junit.Test
|
||||
|
||||
class CommonizerHierarchicalIT : BaseGradleIT() {
|
||||
override val defaultGradleVersion: GradleVersionRequired = GradleVersionRequired.FOR_MPP_SUPPORT
|
||||
|
||||
@Test
|
||||
fun `test commonizeHierarchically metadata compilations`() {
|
||||
with(Project("commonizeHierarchically")) {
|
||||
if (Os.canCompileApple) {
|
||||
build(":p1:compileIosMainKotlinMetadata") {
|
||||
assertSuccessful()
|
||||
assertFileExists("p1/build/classes/kotlin/metadata/iosMain/klib/p1_iosMain.klib")
|
||||
}
|
||||
|
||||
build(":p1:compileAppleMainKotlinMetadata") {
|
||||
assertSuccessful()
|
||||
assertFileExists("p1/build/classes/kotlin/metadata/appleMain/klib/p1_appleMain.klib")
|
||||
}
|
||||
}
|
||||
|
||||
if (Os.canCompileLinux) {
|
||||
build(":p1:compileLinuxMainKotlinMetadata") {
|
||||
assertSuccessful()
|
||||
assertFileExists("p1/build/classes/kotlin/metadata/linuxMain/klib/p1_linuxMain.klib")
|
||||
}
|
||||
}
|
||||
|
||||
if (Os.canCompileWindows) {
|
||||
build(":p1:compileWindowsMainKotlinMetadata") {
|
||||
assertSuccessful()
|
||||
assertFileExists("p1/build/classes/kotlin/metadata/windowsMain/klib/p1_windowsMain.klib")
|
||||
}
|
||||
}
|
||||
|
||||
if (Os.canCompileApple || Os.canCompileLinux) {
|
||||
build(":p1:compileAppleAndLinuxMainKotlinMetadata") {
|
||||
assertSuccessful()
|
||||
assertFileExists("p1/build/classes/kotlin/metadata/appleAndLinuxMain/klib/p1_appleAndLinuxMain.klib")
|
||||
}
|
||||
}
|
||||
|
||||
if (Os.canCompileApple || Os.canCompileLinux || Os.canCompileWindows) {
|
||||
build(":p1:compileNativeMainKotlinMetadata") {
|
||||
assertSuccessful()
|
||||
assertFileExists("p1/build/classes/kotlin/metadata/nativeMain/klib/p1_nativeMain.klib")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test commonizeHierarchically Klibrary compilations`() {
|
||||
with(Project("commonizeHierarchically")) {
|
||||
if (Os.canCompileApple) {
|
||||
build(":p1:iosArm64MainKlibrary", ":p1:iosX64MainKlibrary", ":p1:macosMainKlibrary") {
|
||||
assertSuccessful()
|
||||
assertFileExists("p1/build/classes/kotlin/iosArm64/main/klib/p1.klib")
|
||||
assertFileExists("p1/build/classes/kotlin/iosX64/main/klib/p1.klib")
|
||||
assertFileExists("p1/build/classes/kotlin/macos/main/klib/p1.klib")
|
||||
}
|
||||
}
|
||||
|
||||
if (Os.canCompileLinux) {
|
||||
build(":p1:linuxX64MainKlibrary", ":p1:linuxArm64MainKlibrary") {
|
||||
assertSuccessful()
|
||||
assertFileExists("p1/build/classes/kotlin/linuxX64/main/klib/p1.klib")
|
||||
assertFileExists("p1/build/classes/kotlin/linuxArm64/main/klib/p1.klib")
|
||||
}
|
||||
}
|
||||
|
||||
if (Os.canCompileWindows) {
|
||||
build(":p1:windowsX64MainKlibrary", ":p1:windowsX86MainKlibrary") {
|
||||
assertSuccessful()
|
||||
assertFileExists("p1/build/classes/kotlin/windowsX64/main/klib/p1.klib")
|
||||
assertFileExists("p1/build/classes/kotlin/windowsX86/main/klib/p1.klib")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object Os {
|
||||
private val os = OperatingSystem.current()
|
||||
val canCompileApple get() = os.isMacOsX
|
||||
val canCompileLinux get() = os.isLinux || os.isMacOsX
|
||||
val canCompileWindows get() = os.isWindows
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
kotlin.code.style=official
|
||||
org.gradle.debug=false
|
||||
|
||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.native.enableDependencyPropagation=false
|
||||
kotlin.mpp.enableCInteropCommonization=true
|
||||
kotlin.mpp.enableHierarchicalCommonization=true
|
||||
@@ -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<KotlinNativeTarget>().forEach { target ->
|
||||
target.compilations.getByName("main").cinterops.create("withPosix") {
|
||||
header(file("libs/withPosix.h"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
class CommonMain {
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
val kotlin_version: String by settings
|
||||
plugins {
|
||||
kotlin("multiplatform").version(kotlin_version)
|
||||
}
|
||||
}
|
||||
|
||||
include(":p1")
|
||||
Reference in New Issue
Block a user