[Gradle][MPP] Replace KotlinSourceSet closure extensions w/ InternalKotlinSourceSet API
KT-52726
This commit is contained in:
committed by
Space
parent
d19aea36e5
commit
c6e9216663
+3
-3
@@ -21,8 +21,8 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.android.kotlinAndroidSourceSetLayout
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.defaultSourceSetLanguageSettingsChecker
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.dependsOnClosure
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.getVisibleSourceSetsFromAssociateCompilations
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.kpm.FragmentMappedKotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.withDependsOnClosure
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
@@ -267,7 +267,7 @@ open class DefaultCompilationDetails<T : KotlinCommonOptions>(
|
||||
override fun source(sourceSet: KotlinSourceSet) {
|
||||
if (directlyIncludedKotlinSourceSets.add(sourceSet)) {
|
||||
target.project.whenEvaluated {
|
||||
addExactSourceSetsEagerly(sourceSet.withDependsOnClosure)
|
||||
addExactSourceSetsEagerly(sourceSet.internal.withDependsOnClosure)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -388,7 +388,7 @@ internal open class SharedNativeCompilationDetails(
|
||||
val friendSourceSets = getVisibleSourceSetsFromAssociateCompilations(project, defaultSourceSet).toMutableSet().apply {
|
||||
// TODO: implement proper dependsOn/refines compiler args for Kotlin/Native and pass the dependsOn klibs separately;
|
||||
// But for now, those dependencies don't have any special semantics, so passing all them as friends works, too
|
||||
addAll(defaultSourceSet.dependsOnClosure)
|
||||
addAll(defaultSourceSet.internal.dependsOnClosure)
|
||||
}
|
||||
project.files(friendSourceSets.mapNotNull { project.getMetadataCompilationForSourceSet(it)?.output?.classesDirs })
|
||||
})
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.withDependsOnClosure
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.ALL_COMPILE_METADATA_CONFIGURATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.KotlinMetadataTargetConfigurator
|
||||
@@ -49,7 +50,7 @@ open class TransformKotlinGranularMetadata
|
||||
}
|
||||
|
||||
private val participatingSourceSets: Set<KotlinSourceSet>
|
||||
get() = transformation.kotlinSourceSet.withDependsOnClosure.toMutableSet().apply {
|
||||
get() = transformation.kotlinSourceSet.internal.withDependsOnClosure.toMutableSet().apply {
|
||||
if (any { it.name == KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME })
|
||||
add(project.kotlinExtension.sourceSets.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME))
|
||||
}
|
||||
|
||||
+6
-2
@@ -222,12 +222,16 @@ internal fun KotlinSourceSet.disambiguateName(simpleName: String): String {
|
||||
internal fun createDefaultSourceDirectorySet(project: Project, name: String?): SourceDirectorySet =
|
||||
project.objects.sourceDirectorySet(name!!, name)
|
||||
|
||||
@Deprecated("Use InternalKotlinSourceSet.dependsOnClosure instead")
|
||||
@Suppress("Unused") // Still part of public API
|
||||
@Deprecated("Use InternalKotlinSourceSet.dependsOnClosure instead. Will be removed in Kotlin 1.9")
|
||||
val KotlinSourceSet.dependsOnClosure: Set<KotlinSourceSet> get() = this.internal.dependsOnClosure
|
||||
|
||||
@Deprecated("Use InternalKotlinSourceSet.withDependsOnClosure instead")
|
||||
@Suppress("Unused") // Still part of public API
|
||||
@Deprecated("Use InternalKotlinSourceSet.withDependsOnClosure instead. Will be removed in Kotlin 1.9")
|
||||
val KotlinSourceSet.withDependsOnClosure: Set<KotlinSourceSet> get() = this.internal.withDependsOnClosure
|
||||
|
||||
@Suppress("Unused") // Still part of public API
|
||||
@Deprecated("Use InternalKotlinSourceSet.withDependsOnClosure instead. Will be removed in Kotlin 1.9")
|
||||
val Iterable<KotlinSourceSet>.dependsOnClosure: Set<KotlinSourceSet>
|
||||
get() = flatMap { it.internal.dependsOnClosure }.toSet() - this.toSet()
|
||||
|
||||
|
||||
+1
-1
@@ -140,7 +140,7 @@ internal fun checkSourceSetVisibilityRequirements(
|
||||
val inferredVisibility =
|
||||
getVisibleSourceSetsFromAssociateCompilations(compilationsBySourceSet[sourceSet].orEmpty())
|
||||
|
||||
val requiredButNotVisible = requiredVisibility - inferredVisibility - sourceSet.withDependsOnClosure
|
||||
val requiredButNotVisible = requiredVisibility - inferredVisibility - sourceSet.internal.withDependsOnClosure
|
||||
|
||||
if (requiredButNotVisible.isNotEmpty()) {
|
||||
val compilations = compilationsBySourceSet.getValue(sourceSet)
|
||||
|
||||
+3
-3
@@ -263,7 +263,7 @@ class KotlinMetadataTargetConfigurator :
|
||||
* See also: [buildKotlinProjectStructureMetadata], where these dependencies must be included into the source set exported deps.
|
||||
*/
|
||||
if (isSharedNativeCompilation) {
|
||||
sourceSet.withDependsOnClosure.forEach { hierarchySourceSet ->
|
||||
sourceSet.internal.withDependsOnClosure.forEach { hierarchySourceSet ->
|
||||
apiElementsConfiguration.extendsFrom(
|
||||
configurations.sourceSetDependencyConfigurationByScope(
|
||||
hierarchySourceSet,
|
||||
@@ -447,7 +447,7 @@ class KotlinMetadataTargetConfigurator :
|
||||
val sourceSet = compilation.defaultSourceSet
|
||||
|
||||
val dependsOnCompilationOutputs = lazy {
|
||||
sourceSet.withDependsOnClosure.mapNotNull { hierarchySourceSet ->
|
||||
sourceSet.internal.withDependsOnClosure.mapNotNull { hierarchySourceSet ->
|
||||
val dependencyCompilation = project.getMetadataCompilationForSourceSet(hierarchySourceSet)
|
||||
dependencyCompilation?.output?.classesDirs.takeIf { hierarchySourceSet != sourceSet }
|
||||
}
|
||||
@@ -574,7 +574,7 @@ internal fun isSharedNativeSourceSet(project: Project, sourceSet: KotlinSourceSe
|
||||
}
|
||||
|
||||
internal fun dependsOnClosureWithInterCompilationDependencies(project: Project, sourceSet: KotlinSourceSet): Set<KotlinSourceSet> =
|
||||
sourceSet.dependsOnClosure.toMutableSet().apply {
|
||||
sourceSet.internal.dependsOnClosure.toMutableSet().apply {
|
||||
addAll(getVisibleSourceSetsFromAssociateCompilations(project, sourceSet))
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.Choos
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.toKpmModuleIdentifiers
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.SourceSetMetadataStorageForIde
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.dependsOnClosure
|
||||
import org.jetbrains.kotlin.gradle.tasks.dependsOn
|
||||
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.AbstractKotlinFragmentMetadataCompilationData
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinCompilationData
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinMetadataCompilationData
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.dependsOnClosure
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon
|
||||
import java.io.File
|
||||
|
||||
@@ -38,7 +38,7 @@ internal class KotlinCompileCommonConfig(
|
||||
is KotlinCompilation<*> -> {
|
||||
val defaultKotlinSourceSet: KotlinSourceSet = compilation.defaultSourceSet
|
||||
val metadataTarget = compilation.owner as KotlinTarget
|
||||
defaultKotlinSourceSet.dependsOnClosure
|
||||
defaultKotlinSourceSet.internal.dependsOnClosure
|
||||
.mapNotNull { sourceSet -> metadataTarget.compilations.findByName(sourceSet.name)?.output?.classesDirs }
|
||||
.flatten()
|
||||
}
|
||||
|
||||
+5
-5
@@ -11,8 +11,8 @@ package org.jetbrains.kotlin.gradle
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.testfixtures.ProjectBuilder
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.dependsOnClosure
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.findSourceSetsDependingOn
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
import org.junit.Test
|
||||
import kotlin.test.BeforeTest
|
||||
import kotlin.test.assertEquals
|
||||
@@ -72,19 +72,19 @@ class ResolveKotlinSourceSetsTest {
|
||||
macosMain.dependsOn(nativeMain)
|
||||
|
||||
assertEquals(
|
||||
setOf(nativeMain, commonMain), linuxMain.dependsOnClosure
|
||||
setOf(nativeMain, commonMain), linuxMain.internal.dependsOnClosure
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
setOf(commonMain), nativeMain.dependsOnClosure
|
||||
setOf(commonMain), nativeMain.internal.dependsOnClosure
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
emptySet(), commonMain.dependsOnClosure
|
||||
emptySet(), commonMain.internal.dependsOnClosure
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
setOf(commonMain), jvmMain.dependsOnClosure
|
||||
setOf(commonMain), jvmMain.internal.dependsOnClosure
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user