From d76bb4571656f793f326de6aa52c3d2d5b5e0b32 Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Mon, 7 Jun 2021 16:12:42 +0300 Subject: [PATCH] [Commonizer] Add CommonizerHierarchicalIT Test platform dependencies on leaf source sets ^KT-46716 Verification pending --- .../kotlin/gradle/CommonizerHierarchicalIT.kt | 17 ++++++ .../build.gradle.kts | 53 +++++++++++++++++++ .../gradle.properties | 4 ++ .../settings.gradle.kts | 10 ++++ 4 files changed, 84 insertions(+) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/gradle.properties create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/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 76e7929c723..52b17203380 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 @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle import org.gradle.api.logging.configuration.WarningMode import org.gradle.internal.os.OperatingSystem +import org.jetbrains.kotlin.konan.file.File import org.junit.Test class CommonizerHierarchicalIT : BaseGradleIT() { @@ -111,6 +112,22 @@ class CommonizerHierarchicalIT : BaseGradleIT() { } } + @Test + fun `test platform dependencies on leaf source sets`() { + with(Project("commonizeHierarchicallyPlatformDependencies")) { + build(":checkPlatformDependencies") { + val klibPlatform = "${File.separator}klib${File.separator}platform${File.separator}".replace("\\", "\\\\") + + assertSuccessful() + assertTasksExecuted(":commonizeNativeDistribution") + assertTasksExecuted(":checkLinuxX64MainPlatformDependencies") + assertTasksExecuted(":checkLinuxArm64MainPlatformDependencies") + assertContainsRegex(Regex(""".*linuxX64Main.*$klibPlatform.*[Pp]osix.*""")) + assertContainsRegex(Regex(""".*linuxArm64Main.*$klibPlatform.*[Pp]osix.*""")) + } + } + } + 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/commonizeHierarchicallyPlatformDependencies/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/build.gradle.kts new file mode 100644 index 00000000000..a3256a22947 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/build.gradle.kts @@ -0,0 +1,53 @@ +import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet + +plugins { + kotlin("multiplatform") +} + +repositories { + mavenLocal() + mavenCentral() +} + +fun createPlatformDependenciesTestTask(sourceSet: DefaultKotlinSourceSet) { + tasks.create("check${sourceSet.name.capitalize()}PlatformDependencies") { + tasks.maybeCreate("checkPlatformDependencies").dependsOn(this) + + // Dependencies forwarded to the IDE will be attached to the intransitiveMetadataConfiguration + val dependenciesConfiguration = configurations.getByName(sourceSet.intransitiveMetadataConfigurationName) + dependsOn("commonize") + + doLast { + val dependencies = dependenciesConfiguration.files + + dependencies.forEach { dependency -> + logger.quiet("${sourceSet.name} dependency: ${dependency.path}") + } + + dependencies.forEach { dependency -> + if ("klib${File.separator}commonized" in dependency.path) { + throw AssertionError( + "${sourceSet.name}: Found unexpected commonized dependency ${dependency.path}" + ) + } + } + + if (dependencies.isEmpty()) { + throw AssertionError("${sourceSet.name}: Expected at least one platform dependency") + } + + val platformKlibPattern = "klib${File.separator}platform" + if (dependencies.none { dependency -> platformKlibPattern in dependency.path }) { + throw AssertionError("${sourceSet.name}: Expected at least one dependency from '$platformKlibPattern'") + } + } + } +} + +kotlin { + linuxX64() + linuxArm64() + + createPlatformDependenciesTestTask(sourceSets.getByName("linuxX64Main") as DefaultKotlinSourceSet) + createPlatformDependenciesTestTask(sourceSets.getByName("linuxArm64Main") as DefaultKotlinSourceSet) +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/gradle.properties b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/gradle.properties new file mode 100644 index 00000000000..e1d0d1e1879 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/gradle.properties @@ -0,0 +1,4 @@ +kotlin.mpp.enableGranularSourceSetsMetadata=true +kotlin.native.enableDependencyPropagation=false +kotlin.mpp.enableHierarchicalCommonization=true +kotlin.mpp.enableIntransitiveMetadataConfiguration=true diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/settings.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/settings.gradle.kts new file mode 100644 index 00000000000..92e9d3068fc --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonizeHierarchicallyPlatformDependencies/settings.gradle.kts @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + } + val kotlin_version: String by settings + plugins { + kotlin("multiplatform").version(kotlin_version) + } +} \ No newline at end of file