[JS IR] Fix transitive dependency resolve

This commit is contained in:
Roman Artemev
2020-12-24 12:57:30 +03:00
parent 75016bf54d
commit b0adcffed9
3 changed files with 18 additions and 24 deletions
@@ -52,7 +52,6 @@ import org.jetbrains.kotlin.library.*
import org.jetbrains.kotlin.library.impl.BuiltInsPlatform
import org.jetbrains.kotlin.library.impl.buildKotlinLibrary
import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult
import org.jetbrains.kotlin.library.resolver.TopologicalLibraryOrder
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.progress.IncrementalNextRoundException
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
@@ -380,15 +379,10 @@ private class ModulesStructure(
private val friendDependencies: List<KotlinLibrary>
) {
val moduleDependencies: Map<KotlinLibrary, List<KotlinLibrary>> = run {
val result = mutableMapOf<KotlinLibrary, List<KotlinLibrary>>()
allDependencies.forEach { klib, _ ->
val dependencies = allDependencies.filterRoots {
it.library == klib
}.getFullList(TopologicalLibraryOrder)
result.put(klib, dependencies.minus(klib))
}
result
val transitives = allDependencies.getFullResolvedList()
transitives.associate { klib ->
klib.library to klib.resolvedDependencies.map { d -> d.library }
}.toMap()
}
val builtInsDep = allDependencies.getFullList().find { it.isBuiltIns }
@@ -23,7 +23,8 @@ interface KotlinLibraryResolveResult {
fun filterRoots(predicate: (KotlinResolvedLibrary) -> Boolean): KotlinLibraryResolveResult
fun getFullList(order: LibraryOrder? = null): List<KotlinLibrary>
fun getFullList(order: LibraryOrder? = null): List<KotlinLibrary> = getFullResolvedList(order).map { it.library }
fun getFullResolvedList(order: LibraryOrder? = null): List<KotlinResolvedLibrary>
fun forEach(action: (KotlinLibrary, PackageAccessHandler) -> Unit)
}
@@ -143,30 +143,29 @@ class KotlinLibraryResolverResultImpl(
private val roots: List<KotlinResolvedLibrary>
): KotlinLibraryResolveResult {
private val all: List<KotlinResolvedLibrary> by lazy {
val result = mutableSetOf<KotlinResolvedLibrary>().also { it.addAll(roots) }
private val all: List<KotlinResolvedLibrary>
by lazy {
val result = mutableSetOf<KotlinResolvedLibrary>().also { it.addAll(roots) }
var newDependencies = result.toList()
do {
newDependencies = newDependencies
.map { it -> it.resolvedDependencies }.flatten()
var newDependencies = result.toList()
do {
newDependencies = newDependencies
.map { it.resolvedDependencies }.flatten()
.filter { it !in result }
result.addAll(newDependencies)
} while (newDependencies.isNotEmpty())
result.addAll(newDependencies)
} while (newDependencies.isNotEmpty())
result.toList()
}
result.toList()
}
override fun filterRoots(predicate: (KotlinResolvedLibrary) -> Boolean) =
KotlinLibraryResolverResultImpl(roots.filter(predicate))
override fun getFullList(order: LibraryOrder?) = (order?.invoke(all) ?: all).asPlain()
override fun getFullResolvedList(order: LibraryOrder?) = (order?.invoke(all) ?: all)
override fun forEach(action: (KotlinLibrary, PackageAccessHandler) -> Unit) {
all.forEach { action(it.library, it) }
}
private fun List<KotlinResolvedLibrary>.asPlain() = map { it.library }
override fun toString() = "roots=$roots, all=$all"
}