From 3c343543e9f0edb3cf8d8c850dd7de3e89a91b30 Mon Sep 17 00:00:00 2001 From: Anton Lakotka Date: Thu, 26 Jan 2023 08:48:45 +0100 Subject: [PATCH] [Gradle] Legacy metadata compilation should contain all source sets from depends on closure of its default source set. With HMPP it is no longer needed, since each source compiles independently and sees its parent declarations via klib dependencies ^KT-55730 Verification Pending --- .../KotlinMetadataTargetConfigurator.kt | 6 +++ ...5730CommonMainDependsOnAnotherSourceSet.kt | 44 +++++++++++++++++++ .../kotlin/gradle/util/buildProject.kt | 7 ++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/KT55730CommonMainDependsOnAnotherSourceSet.kt diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/metadata/KotlinMetadataTargetConfigurator.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/metadata/KotlinMetadataTargetConfigurator.kt index 34a42949895..f1d093dd735 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/metadata/KotlinMetadataTargetConfigurator.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/metadata/KotlinMetadataTargetConfigurator.kt @@ -72,6 +72,12 @@ class KotlinMetadataTargetConfigurator : if (isCompatibilityMetadataVariantEnabled) { // Force the default 'main' compilation to produce *.kotlin_metadata regardless of the klib feature flag. forceCompilationToKotlinMetadata = true + // Add directly dependsOn sources for Legacy Compatibility Metadata variant + // it isn't necessary for KLib compilations + // see [KotlinCompilationSourceSetInclusion.AddSourcesWithoutDependsOnClosure] + defaultSourceSet.internal.dependsOnClosure.forAll { + source(it) + } } else { // Clear the dependencies of the compilation so that they don't take time resolving during task graph construction: compileDependencyFiles = target.project.files() diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/KT55730CommonMainDependsOnAnotherSourceSet.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/KT55730CommonMainDependsOnAnotherSourceSet.kt new file mode 100644 index 00000000000..141e1b76c73 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/KT55730CommonMainDependsOnAnotherSourceSet.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2010-2023 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. + */ + +@file:Suppress("FunctionName") + +package org.jetbrains.kotlin.gradle.regressionTests + +import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension +import org.jetbrains.kotlin.gradle.util.applyMultiplatformPlugin +import org.jetbrains.kotlin.gradle.util.buildProject +import org.jetbrains.kotlin.gradle.util.enableCompatibilityMetadataVariant +import org.jetbrains.kotlin.gradle.util.kotlin +import kotlin.test.Test +import kotlin.test.assertEquals + +class KT55730CommonMainDependsOnAnotherSourceSet { + @Test + fun `legacy metadata compilation should have commonMain with its depends on closure`() { + val project = buildProject { + enableCompatibilityMetadataVariant() + applyMultiplatformPlugin() + kotlin { + val grandCommonMain = sourceSets.create("grandCommonMain") + val commonMain = sourceSets.getByName("commonMain") + commonMain.dependsOn(grandCommonMain) + } + } + + project.evaluate() + + val actualSourceSets = project + .multiplatformExtension + .metadata() + .compilations + .getByName("main") + .kotlinSourceSets + .map { it.name } + .toSet() + + assertEquals(setOf("grandCommonMain", "commonMain"), actualSourceSets) + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/util/buildProject.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/util/buildProject.kt index 8cc31c5f9ea..4ed2de8c564 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/util/buildProject.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/util/buildProject.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.gradle.dsl.kotlinExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformAndroidPlugin import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider +import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_COMPATIBILITY_METADATA_VARIANT import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_INTRANSITIVE_METADATA_CONFIGURATION import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinPm20ProjectExtension import org.jetbrains.kotlin.gradle.unitTests.kpm.applyKpmPlugin @@ -116,4 +117,8 @@ fun Project.setMultiplatformAndroidSourceSetLayoutVersion(version: Int) { fun Project.enableDependencyVerification(enabled: Boolean = true) { gradle.startParameter.dependencyVerificationMode = if (enabled) DependencyVerificationMode.STRICT else DependencyVerificationMode.OFF -} \ No newline at end of file +} + +fun Project.enableCompatibilityMetadataVariant(enabled: Boolean = true) { + propertiesExtension.set(KOTLIN_MPP_ENABLE_COMPATIBILITY_METADATA_VARIANT, enabled.toString()) +}