Skip to content

Commit e2b4317

Browse files
antohabySpace Team
authored and
Space Team
committed
[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 cherry-picked from 3c34354 ^KT-55730 Verification Pending
1 parent b6cde89 commit e2b4317

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/metadata/KotlinMetadataTargetConfigurator.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ class KotlinMetadataTargetConfigurator :
7474
if (isCompatibilityMetadataVariantEnabled) {
7575
// Force the default 'main' compilation to produce *.kotlin_metadata regardless of the klib feature flag.
7676
forceCompilationToKotlinMetadata = true
77+
// Add directly dependsOn sources for Legacy Compatibility Metadata variant
78+
// it isn't necessary for KLib compilations
79+
// see [KotlinCompilationSourceSetInclusion.AddSourcesWithoutDependsOnClosure]
80+
defaultSourceSet.internal.dependsOnClosure.forAll {
81+
source(it)
82+
}
7783
} else {
7884
// Clear the dependencies of the compilation so that they don't take time resolving during task graph construction:
7985
compileDependencyFiles = target.project.files()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
@file:Suppress("FunctionName")
7+
8+
package org.jetbrains.kotlin.gradle
9+
10+
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
11+
import kotlin.test.Test
12+
import kotlin.test.assertEquals
13+
14+
class KT55730CommonMainDependsOnAnotherSourceSet {
15+
@Test
16+
fun `legacy metadata compilation should have commonMain with its depends on closure`() {
17+
val project = buildProject {
18+
enableCompatibilityMetadataVariant()
19+
applyMultiplatformPlugin()
20+
kotlin {
21+
val grandCommonMain = sourceSets.create("grandCommonMain")
22+
val commonMain = sourceSets.getByName("commonMain")
23+
commonMain.dependsOn(grandCommonMain)
24+
}
25+
}
26+
27+
project.evaluate()
28+
29+
val actualSourceSets = project
30+
.multiplatformExtension
31+
.metadata()
32+
.compilations
33+
.getByName("main")
34+
.kotlinSourceSets
35+
.map { it.name }
36+
.toSet()
37+
38+
assertEquals(setOf("grandCommonMain", "commonMain"), actualSourceSets)
39+
}
40+
}

libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/buildProject.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ fun Project.androidLibrary(code: LibraryExtension.() -> Unit) {
6363
fun Project.projectModel(code: KotlinPm20ProjectExtension.() -> Unit) {
6464
val extension = project.extensions.getByType(KotlinPm20ProjectExtension::class.java)
6565
extension.code()
66-
}
66+
}
67+
68+
fun Project.enableCompatibilityMetadataVariant(enabled: Boolean = true) {
69+
propertiesExtension.set("kotlin.mpp.enableCompatibilityMetadataVariant", enabled.toString())
70+
}

0 commit comments

Comments
 (0)