[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
This commit is contained in:
Anton Lakotka
2023-01-26 08:48:45 +01:00
committed by Space Team
parent 23f10a1d38
commit 3c343543e9
3 changed files with 56 additions and 1 deletions
@@ -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()
@@ -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)
}
}
@@ -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
}
}
fun Project.enableCompatibilityMetadataVariant(enabled: Boolean = true) {
propertiesExtension.set(KOTLIN_MPP_ENABLE_COMPATIBILITY_METADATA_VARIANT, enabled.toString())
}