org.jetbrains.kotlin.library.metadata.resolver.KotlinLibraryResolver.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-embeddable Show documentation
Show all versions of kotlin-compiler-embeddable Show documentation
the Kotlin compiler embeddable
package org.jetbrains.kotlin.library.metadata.resolver
import org.jetbrains.kotlin.library.KotlinLibrary
import org.jetbrains.kotlin.library.SearchPathResolver
import org.jetbrains.kotlin.library.UnresolvedLibrary
import org.jetbrains.kotlin.library.metadata.PackageAccessHandler
interface KotlinLibraryResolver {
val searchPathResolver: SearchPathResolver
/**
* Given the list of Kotlin/Native library names, ABI version and other parameters
* resolves libraries and evaluates dependencies between them.
*/
fun resolveWithDependencies(
unresolvedLibraries: List,
noStdLib: Boolean = false,
noDefaultLibs: Boolean = false,
noEndorsedLibs: Boolean = false,
): KotlinLibraryResolveResult =
resolveWithoutDependencies(
unresolvedLibraries,
noStdLib,
noDefaultLibs,
noEndorsedLibs
).resolveDependencies()
fun resolveWithoutDependencies(
unresolvedLibraries: List,
noStdLib: Boolean = false,
noDefaultLibs: Boolean = false,
noEndorsedLibs: Boolean = false,
): List
fun List.resolveDependencies(): KotlinLibraryResolveResult
}
interface KotlinLibraryResolveResult {
fun filterRoots(predicate: (KotlinResolvedLibrary) -> Boolean): KotlinLibraryResolveResult
fun getFullList(order: LibraryOrder? = null): List = getFullResolvedList(order).map { it.library }
fun getFullResolvedList(order: LibraryOrder? = null): List
fun forEach(action: (KotlinLibrary, PackageAccessHandler) -> Unit)
}
typealias LibraryOrder = (Iterable) -> List
val TopologicalLibraryOrder: LibraryOrder = { input ->
val sorted = mutableListOf()
val visited = mutableSetOf()
val tempMarks = mutableSetOf()
fun visit(node: KotlinResolvedLibrary, result: MutableList) {
if (visited.contains(node)) return
if (tempMarks.contains(node)) error("Cyclic dependency in library graph for: ${node.library.libraryName}")
tempMarks.add(node)
node.resolvedDependencies.forEach {
visit(it, result)
}
visited.add(node)
result += node
}
input.forEach next@{
if (visited.contains(it)) return@next
visit(it, sorted)
}
sorted
}