[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
@@ -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"
}