All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.library.metadata.resolver.KotlinLibraryResolver.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
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
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy