Skip to content

Commit

Permalink
[Gradle] Legacy metadata compilation should contain all source sets from
Browse files Browse the repository at this point in the history
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
  • Loading branch information
antohaby authored and Space Team committed Jan 31, 2023
1 parent b6cde89 commit e2b4317
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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

import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ fun Project.androidLibrary(code: LibraryExtension.() -> Unit) {
fun Project.projectModel(code: KotlinPm20ProjectExtension.() -> Unit) {
val extension = project.extensions.getByType(KotlinPm20ProjectExtension::class.java)
extension.code()
}
}

fun Project.enableCompatibilityMetadataVariant(enabled: Boolean = true) {
propertiesExtension.set("kotlin.mpp.enableCompatibilityMetadataVariant", enabled.toString())
}

0 comments on commit e2b4317

Please sign in to comment.