MPP: Import library dependencies of transitive dependee source sets
#KT-26369 Fixed
This commit is contained in:
+21
-22
@@ -332,7 +332,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
sourceSetMap,
|
sourceSetMap,
|
||||||
artifactsMap,
|
artifactsMap,
|
||||||
dataNode,
|
dataNode,
|
||||||
preprocessDependencies(compilation, ideProject),
|
preprocessDependencies(compilation.dependencies, ideProject),
|
||||||
ideProject
|
ideProject
|
||||||
)
|
)
|
||||||
for (sourceSet in compilation.sourceSets) {
|
for (sourceSet in compilation.sourceSets) {
|
||||||
@@ -344,50 +344,49 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
}
|
}
|
||||||
val sourceSetGraph = GraphBuilder.directed().build<KotlinModule>()
|
val sourceSetGraph = GraphBuilder.directed().build<KotlinModule>()
|
||||||
processSourceSets(gradleModule, mppModel, ideModule, resolverCtx) { dataNode, sourceSet ->
|
processSourceSets(gradleModule, mppModel, ideModule, resolverCtx) { dataNode, sourceSet ->
|
||||||
|
sourceSetGraph.addNode(sourceSet)
|
||||||
val productionSourceSet = dataNode.data.productionModuleId
|
val productionSourceSet = dataNode.data.productionModuleId
|
||||||
?.let { ideModule.findChildModuleByInternalName(it) }
|
?.let { ideModule.findChildModuleByInternalName(it) }
|
||||||
?.kotlinSourceSet
|
?.kotlinSourceSet
|
||||||
?.kotlinModule
|
?.kotlinModule
|
||||||
if (productionSourceSet != null) {
|
if (productionSourceSet != null) {
|
||||||
sourceSetGraph.putEdge(sourceSet, productionSourceSet!!)
|
sourceSetGraph.putEdge(sourceSet, productionSourceSet)
|
||||||
}
|
}
|
||||||
for (targetSourceSetName in sourceSet.dependsOnSourceSets) {
|
for (targetSourceSetName in sourceSet.dependsOnSourceSets) {
|
||||||
val targetSourceSet = mppModel.sourceSets[targetSourceSetName] ?: continue
|
val targetSourceSet = mppModel.sourceSets[targetSourceSetName] ?: continue
|
||||||
sourceSetGraph.putEdge(sourceSet, targetSourceSet)
|
sourceSetGraph.putEdge(sourceSet, targetSourceSet)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
val closedSourceSetGraph = Graphs.transitiveClosure(sourceSetGraph)
|
||||||
|
for (sourceSet in closedSourceSetGraph.nodes()) {
|
||||||
|
val fromDataNode = getSiblingKotlinModuleData(sourceSet, gradleModule, ideModule, resolverCtx) ?: continue
|
||||||
|
val dependeeSourceSets = closedSourceSetGraph.successors(sourceSet)
|
||||||
|
for (dependeeSourceSet in dependeeSourceSets) {
|
||||||
|
val toDataNode = getSiblingKotlinModuleData(dependeeSourceSet, gradleModule, ideModule, resolverCtx) ?: continue
|
||||||
|
addDependency(fromDataNode, toDataNode)
|
||||||
|
}
|
||||||
if (processedModuleIds.add(getKotlinModuleId(gradleModule, sourceSet, resolverCtx))) {
|
if (processedModuleIds.add(getKotlinModuleId(gradleModule, sourceSet, resolverCtx))) {
|
||||||
|
val mergedDependencies = LinkedHashSet<KotlinDependency>().apply {
|
||||||
|
addAll(sourceSet.dependencies)
|
||||||
|
dependeeSourceSets.flatMapTo(this) { it.dependencies }
|
||||||
|
}
|
||||||
buildDependencies(
|
buildDependencies(
|
||||||
resolverCtx,
|
resolverCtx,
|
||||||
sourceSetMap,
|
sourceSetMap,
|
||||||
artifactsMap,
|
artifactsMap,
|
||||||
dataNode,
|
fromDataNode,
|
||||||
preprocessDependencies(sourceSet, ideProject),
|
preprocessDependencies(mergedDependencies, ideProject),
|
||||||
ideProject
|
ideProject
|
||||||
)
|
)
|
||||||
if (productionSourceSet != null) {
|
|
||||||
buildDependencies(
|
|
||||||
resolverCtx,
|
|
||||||
sourceSetMap,
|
|
||||||
artifactsMap,
|
|
||||||
dataNode,
|
|
||||||
preprocessDependencies(productionSourceSet, ideProject),
|
|
||||||
ideProject
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (edge in Graphs.transitiveClosure(sourceSetGraph).edges()) {
|
|
||||||
val fromDataNode = getSiblingKotlinModuleData(edge.source(), gradleModule, ideModule, resolverCtx) ?: continue
|
|
||||||
val toDataNode = getSiblingKotlinModuleData(edge.target(), gradleModule, ideModule, resolverCtx) ?: continue
|
|
||||||
addDependency(fromDataNode, toDataNode)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun preprocessDependencies(
|
private fun preprocessDependencies(
|
||||||
kotlinModule: KotlinModule,
|
dependencies: Set<KotlinDependency>,
|
||||||
ideProject: DataNode<ProjectData>
|
ideProject: DataNode<ProjectData>
|
||||||
): List<ExternalDependency> {
|
): List<ExternalDependency> {
|
||||||
return kotlinModule.dependencies
|
return dependencies
|
||||||
.groupBy { it.id }
|
.groupBy { it.id }
|
||||||
.mapValues { it.value.firstOrNull { it.scope == "COMPILE" } ?: it.value.lastOrNull() }
|
.mapValues { it.value.firstOrNull { it.scope == "COMPILE" } ?: it.value.lastOrNull() }
|
||||||
.values
|
.values
|
||||||
@@ -433,7 +432,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
gradleModule: IdeaModule,
|
gradleModule: IdeaModule,
|
||||||
ideModule: DataNode<ModuleData>,
|
ideModule: DataNode<ModuleData>,
|
||||||
resolverCtx: ProjectResolverContext
|
resolverCtx: ProjectResolverContext
|
||||||
): DataNode<*>? {
|
): DataNode<out ModuleData>? {
|
||||||
val usedModuleId = getKotlinModuleId(gradleModule, kotlinModule, resolverCtx)
|
val usedModuleId = getKotlinModuleId(gradleModule, kotlinModule, resolverCtx)
|
||||||
return ideModule.findChildModuleById(usedModuleId)
|
return ideModule.findChildModuleById(usedModuleId)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user