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-util-klib-metadata Show documentation
Show all versions of kotlin-util-klib-metadata Show documentation
Common klib metadata reader and writer
package org.jetbrains.kotlin.library.metadata.resolver
import org.jetbrains.kotlin.config.DuplicatedUniqueNameStrategy
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,
duplicatedUniqueNameStrategy: DuplicatedUniqueNameStrategy = DuplicatedUniqueNameStrategy.DENY,
): KotlinLibraryResolveResult =
resolveWithoutDependencies(
unresolvedLibraries,
noStdLib,
noDefaultLibs,
noEndorsedLibs,
duplicatedUniqueNameStrategy,
).resolveDependencies()
@Deprecated("Restored to keep ABI compatibility with kotlinx-benchmark Gradle plugin (KT-71414)", level = DeprecationLevel.HIDDEN)
fun resolveWithDependencies(
unresolvedLibraries: List,
noStdLib: Boolean = false,
noDefaultLibs: Boolean = false,
noEndorsedLibs: Boolean = false,
): KotlinLibraryResolveResult =
resolveWithDependencies(
unresolvedLibraries,
noStdLib,
noDefaultLibs,
noEndorsedLibs,
DuplicatedUniqueNameStrategy.DENY
)
fun resolveWithoutDependencies(
unresolvedLibraries: List,
noStdLib: Boolean = false,
noDefaultLibs: Boolean = false,
noEndorsedLibs: Boolean = false,
duplicatedUniqueNameStrategy: DuplicatedUniqueNameStrategy,
): 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
}