Rename 'getSourceSetHierarchy' to 'withAllDependsOnSourceSets' and lift the previous Deprecation
This commit is contained in:
committed by
Space
parent
7da7dd92d6
commit
be84b7b419
+9
-10
@@ -28,9 +28,9 @@ import org.jetbrains.kotlin.gradle.execution.KotlinAggregateExecutionSource
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.CompilationSourceSetUtil
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.getSourceSetHierarchy
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.withAllDependsOnSourceSets
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.resolveAllDependsOnSourceSets
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.sourceSetDependencyConfigurationByScope
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.JvmCompilationsTestRunSource
|
||||
import org.jetbrains.kotlin.gradle.tasks.KOTLIN_MODULE_GROUP
|
||||
@@ -91,11 +91,10 @@ private fun chooseAndAddStdlibDependency(
|
||||
val sourceSetDependencyConfigurations =
|
||||
KotlinDependencyScope.values().map { project.sourceSetDependencyConfigurationByScope(kotlinSourceSet, it) }
|
||||
|
||||
val hierarchySourceSetsDependencyConfigurations = kotlinSourceSet.getSourceSetHierarchy().flatMap { hierarchySourceSet ->
|
||||
if (hierarchySourceSet === kotlinSourceSet) emptyList() else
|
||||
KotlinDependencyScope.values().map { scope ->
|
||||
project.sourceSetDependencyConfigurationByScope(hierarchySourceSet, scope)
|
||||
}
|
||||
val hierarchySourceSetsDependencyConfigurations = kotlinSourceSet.resolveAllDependsOnSourceSets().flatMap { hierarchySourceSet ->
|
||||
KotlinDependencyScope.values().map { scope ->
|
||||
project.sourceSetDependencyConfigurationByScope(hierarchySourceSet, scope)
|
||||
}
|
||||
}
|
||||
|
||||
val compilations = CompilationSourceSetUtil.compilationsBySourceSets(project).getValue(kotlinSourceSet)
|
||||
@@ -216,7 +215,7 @@ internal fun configureKotlinTestDependency(project: Project) {
|
||||
|
||||
project.tryWithDependenciesIfUnresolved(configuration) { dependencies ->
|
||||
val parentOrOwnVersions: List<String?> =
|
||||
kotlinSourceSet.getSourceSetHierarchy().filter(versionOrNullBySourceSet::contains).map(versionOrNullBySourceSet::get)
|
||||
kotlinSourceSet.withAllDependsOnSourceSets().filter(versionOrNullBySourceSet::contains).map(versionOrNullBySourceSet::get)
|
||||
|
||||
finalizingDependencies = true
|
||||
|
||||
@@ -310,7 +309,7 @@ private fun KotlinTargetWithTests<*, *>.findTestRunsByCompilation(byCompilation:
|
||||
//endregion
|
||||
|
||||
private fun Project.kotlinDependency(moduleName: String, versionOrNull: String?) =
|
||||
project.dependencies.create("$KOTLIN_MODULE_GROUP:$moduleName${versionOrNull?.prependIndent(":").orEmpty()}")
|
||||
project.dependencies.create("$KOTLIN_MODULE_GROUP:$moduleName${versionOrNull?.prependIndent(":").orEmpty()}")
|
||||
|
||||
private fun Project.tryWithDependenciesIfUnresolved(configuration: Configuration, action: (DependencySet) -> Unit) {
|
||||
fun reportAlreadyResolved() {
|
||||
@@ -328,4 +327,4 @@ private fun Project.tryWithDependenciesIfUnresolved(configuration: Configuration
|
||||
} catch (e: InvalidUserDataException) {
|
||||
reportAlreadyResolved()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -15,7 +15,7 @@ import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.Nested
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.getSourceSetHierarchy
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.withAllDependsOnSourceSets
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.sourceSetDependencyConfigurationByScope
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.getPublishedPlatformCompilations
|
||||
import org.w3c.dom.Document
|
||||
@@ -116,7 +116,7 @@ internal fun buildKotlinProjectStructureMetadata(project: Project): KotlinProjec
|
||||
*/
|
||||
val isNativeSharedSourceSet = sourceSetsWithMetadataCompilations[sourceSet] is KotlinSharedNativeCompilation
|
||||
val sourceSetExportedDependencies = when {
|
||||
isNativeSharedSourceSet -> sourceSet.getSourceSetHierarchy().flatMap { hierarchySourceSet ->
|
||||
isNativeSharedSourceSet -> sourceSet.withAllDependsOnSourceSets().flatMap { hierarchySourceSet ->
|
||||
listOf(KotlinDependencyScope.API_SCOPE, KotlinDependencyScope.IMPLEMENTATION_SCOPE).flatMap { scope ->
|
||||
project.sourceSetDependencyConfigurationByScope(hierarchySourceSet, scope).allDependencies.toList()
|
||||
}
|
||||
@@ -327,4 +327,4 @@ private const val SOURCE_SET_NODE_NAME = "sourceSet"
|
||||
private const val DEPENDS_ON_NODE_NAME = "dependsOn"
|
||||
private const val MODULE_DEPENDENCY_NODE_NAME = "moduleDependency"
|
||||
private const val BINARY_LAYOUT_NODE_NAME = "binaryLayout"
|
||||
private const val HOST_SPECIFIC_NODE_NAME = "hostSpecific"
|
||||
private const val HOST_SPECIFIC_NODE_NAME = "hostSpecific"
|
||||
|
||||
+3
-3
@@ -12,7 +12,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.getSourceSetHierarchy
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.withAllDependsOnSourceSets
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.ALL_COMPILE_METADATA_CONFIGURATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.KotlinMetadataTargetConfigurator
|
||||
import org.jetbrains.kotlin.gradle.utils.getValue
|
||||
@@ -39,7 +39,7 @@ open class TransformKotlinGranularMetadata
|
||||
}
|
||||
|
||||
private val participatingSourceSets: Set<KotlinSourceSet>
|
||||
get() = transformation.kotlinSourceSet.getSourceSetHierarchy().toMutableSet().apply {
|
||||
get() = transformation.kotlinSourceSet.withAllDependsOnSourceSets().toMutableSet().apply {
|
||||
if (any { it.name == KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME })
|
||||
add(project.kotlinExtension.sourceSets.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME))
|
||||
}
|
||||
@@ -116,4 +116,4 @@ open class TransformKotlinGranularMetadata
|
||||
|
||||
extractableFiles.forEach { it.getMetadataFilesPerSourceSet(doProcessFiles = true) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-4
@@ -6,7 +6,10 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.api.*
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.UnknownTaskException
|
||||
import org.gradle.api.attributes.AttributeContainer
|
||||
import org.gradle.api.execution.TaskExecutionListener
|
||||
import org.gradle.api.file.FileCollection
|
||||
@@ -21,7 +24,8 @@ import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.internal.KotlinCompilationsModuleGroups
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.defaultSourceSetLanguageSettingsChecker
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.getSourceSetHierarchy
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.withAllDependsOnSourceSets
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.resolveAllDependsOnSourceSets
|
||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.locateTask
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
@@ -66,7 +70,7 @@ abstract class AbstractKotlinCompilation<T : KotlinCommonOptions>(
|
||||
override val kotlinSourceSets: MutableSet<KotlinSourceSet> = mutableSetOf()
|
||||
|
||||
override val allKotlinSourceSets: Set<KotlinSourceSet>
|
||||
get() = kotlinSourceSets.flatMapTo(mutableSetOf()) { it.getSourceSetHierarchy() }
|
||||
get() = kotlinSourceSets + kotlinSourceSets.resolveAllDependsOnSourceSets()
|
||||
|
||||
override val defaultSourceSetName: String
|
||||
get() = lowerCamelCaseName(
|
||||
@@ -146,7 +150,7 @@ abstract class AbstractKotlinCompilation<T : KotlinCommonOptions>(
|
||||
final override fun source(sourceSet: KotlinSourceSet) {
|
||||
if (kotlinSourceSets.add(sourceSet)) {
|
||||
target.project.whenEvaluated {
|
||||
addExactSourceSetsEagerly(sourceSet.getSourceSetHierarchy())
|
||||
addExactSourceSetsEagerly(sourceSet.withAllDependsOnSourceSets())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-15
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.collections.HashSet
|
||||
|
||||
const val METADATA_CONFIGURATION_NAME_SUFFIX = "DependenciesMetadata"
|
||||
|
||||
@@ -230,23 +231,18 @@ internal fun KotlinSourceSet.disambiguateName(simpleName: String): String {
|
||||
private fun createDefaultSourceDirectorySet(project: Project, name: String?): SourceDirectorySet =
|
||||
project.objects.sourceDirectorySet(name, name)
|
||||
|
||||
/**
|
||||
* Like [resolveAllDependsOnSourceSets] but will include the receiver source set also!
|
||||
*/
|
||||
internal fun KotlinSourceSet.withAllDependsOnSourceSets(): Set<KotlinSourceSet> {
|
||||
return this + this.resolveAllDependsOnSourceSets()
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
"Use 'getAllDependsOnSourceSets' instead",
|
||||
level = DeprecationLevel.WARNING,
|
||||
replaceWith = ReplaceWith("getAllDependsOnSourceSets")
|
||||
)
|
||||
internal fun KotlinSourceSet.getSourceSetHierarchy(): Set<KotlinSourceSet> {
|
||||
val result = mutableSetOf<KotlinSourceSet>()
|
||||
|
||||
fun processSourceSet(sourceSet: KotlinSourceSet) {
|
||||
if (result.add(sourceSet)) {
|
||||
sourceSet.dependsOn.forEach { processSourceSet(it) }
|
||||
}
|
||||
internal operator fun KotlinSourceSet.plus(sourceSets: Set<KotlinSourceSet>): Set<KotlinSourceSet> {
|
||||
return HashSet<KotlinSourceSet>(sourceSets.size + 1).also { set ->
|
||||
set.add(this)
|
||||
set.addAll(sourceSets)
|
||||
}
|
||||
|
||||
processSourceSet(this)
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun KotlinSourceSet.resolveAllDependsOnSourceSets(): Set<KotlinSourceSet> {
|
||||
|
||||
+2
-2
@@ -140,7 +140,7 @@ internal fun checkSourceSetVisibilityRequirements(
|
||||
val inferredVisibility =
|
||||
getVisibleSourceSetsFromAssociateCompilations(compilationsBySourceSet[sourceSet].orEmpty())
|
||||
|
||||
val requiredButNotVisible = requiredVisibility - inferredVisibility - sourceSet.getSourceSetHierarchy()
|
||||
val requiredButNotVisible = requiredVisibility - inferredVisibility - sourceSet.withAllDependsOnSourceSets()
|
||||
|
||||
if (requiredButNotVisible.isNotEmpty()) {
|
||||
val compilations = compilationsBySourceSet.getValue(sourceSet)
|
||||
@@ -153,4 +153,4 @@ internal fun checkSourceSetVisibilityRequirements(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -260,7 +260,7 @@ class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
|
||||
* See also: [buildKotlinProjectStructureMetadata], where these dependencies must be included into the source set exported deps.
|
||||
*/
|
||||
if (isSharedNativeCompilation) {
|
||||
sourceSet.getSourceSetHierarchy().forEach { hierarchySourceSet ->
|
||||
sourceSet.withAllDependsOnSourceSets().forEach { hierarchySourceSet ->
|
||||
apiElementsConfiguration.extendsFrom(
|
||||
sourceSetDependencyConfigurationByScope(hierarchySourceSet, KotlinDependencyScope.IMPLEMENTATION_SCOPE)
|
||||
)
|
||||
@@ -438,7 +438,7 @@ class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
|
||||
project.provider {
|
||||
val sourceSet = compilation.defaultSourceSet
|
||||
|
||||
val transformationTaskHolders = sourceSet.getSourceSetHierarchy().mapNotNull { hierarchySourceSet ->
|
||||
val transformationTaskHolders = sourceSet.withAllDependsOnSourceSets().mapNotNull { hierarchySourceSet ->
|
||||
project.locateTask<TransformKotlinGranularMetadata>(transformGranularMetadataTaskName(hierarchySourceSet.name))
|
||||
}
|
||||
|
||||
@@ -455,9 +455,9 @@ class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
|
||||
val transformedFilesByResolution: Map<MetadataDependencyResolution, FileCollection> =
|
||||
transformationTaskHolders.flatMap { it.get().filesByResolution.toList() }.toMap()
|
||||
|
||||
val dependsOnCompilationOutputs = sourceSet.getSourceSetHierarchy().mapNotNull { hierarchySourceSet ->
|
||||
val dependsOnCompilationOutputs = sourceSet.resolveAllDependsOnSourceSets().mapNotNull { hierarchySourceSet ->
|
||||
val dependencyCompilation = project.getMetadataCompilationForSourceSet(hierarchySourceSet)
|
||||
dependencyCompilation?.output?.classesDirs.takeIf { hierarchySourceSet != sourceSet }
|
||||
dependencyCompilation?.output?.classesDirs
|
||||
}
|
||||
|
||||
val artifactView = fromFiles.incoming.artifactView { view ->
|
||||
|
||||
+3
-4
@@ -15,8 +15,8 @@ import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.util.ConfigureUtil
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.getSourceSetHierarchy
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.getVisibleSourceSetsFromAssociateCompilations
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.resolveAllDependsOnSourceSets
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.getMetadataCompilationForSourceSet
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
@@ -120,9 +120,8 @@ class KotlinSharedNativeCompilation(override val target: KotlinMetadataTarget, v
|
||||
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.getSourceSetHierarchy())
|
||||
remove(defaultSourceSet)
|
||||
addAll(defaultSourceSet.resolveAllDependsOnSourceSets())
|
||||
}
|
||||
project.files(friendSourceSets.mapNotNull { project.getMetadataCompilationForSourceSet(it)?.output?.classesDirs })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.gradle.logging.GradlePrintingMessageCollector
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
|
||||
import org.jetbrains.kotlin.gradle.utils.getValue
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.getSourceSetHierarchy
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.resolveAllDependsOnSourceSets
|
||||
import org.jetbrains.kotlin.incremental.ChangedFiles
|
||||
import java.io.File
|
||||
|
||||
@@ -90,7 +90,7 @@ open class KotlinCompileCommon : AbstractKotlinCompile<K2MetadataCompilerArgumen
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
@get:InputFiles
|
||||
internal val refinesMetadataPaths by project.provider {
|
||||
outputPathsFromMetadataCompilationsOf(defaultKotlinSourceSet.getSourceSetHierarchy().minus(defaultKotlinSourceSet))
|
||||
outputPathsFromMetadataCompilationsOf(defaultKotlinSourceSet.resolveAllDependsOnSourceSets())
|
||||
}
|
||||
|
||||
override fun callCompilerAsync(args: K2MetadataCompilerArguments, sourceRoots: SourceRoots, changedFiles: ChangedFiles) {
|
||||
|
||||
Reference in New Issue
Block a user