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

org.jetbrains.kotlin.konan.library.SearchPathResolver.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
package org.jetbrains.kotlin.konan.library

import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.library.impl.createKonanLibraryComponents
import org.jetbrains.kotlin.konan.target.Distribution
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.library.*
import org.jetbrains.kotlin.util.DummyLogger
import org.jetbrains.kotlin.util.Logger

interface SearchPathResolverWithTarget: SearchPathResolver {
    val target: KonanTarget
}

fun defaultResolver(
    repositories: List,
    directLibs: List,
    target: KonanTarget,
    distribution: Distribution,
    logger: Logger = DummyLogger,
    skipCurrentDir: Boolean = false
): SearchPathResolverWithTarget = KonanLibraryProperResolver(
        repositories,
        directLibs,
        target,
        distribution.klib,
        distribution.localKonanDir.absolutePath,
        skipCurrentDir,
        logger
)

fun resolverByName(
    repositories: List,
    directLibs: List = emptyList(),
    distributionKlib: String? = null,
    localKotlinDir: String? = null,
    skipCurrentDir: Boolean = false,
    logger: Logger
): SearchPathResolver =
    object : KotlinLibrarySearchPathResolver(
        repositories,
        directLibs,
        distributionKlib,
        localKotlinDir,
        skipCurrentDir,
        logger
    ) {
        override fun libraryComponentBuilder(file: File, isDefault: Boolean) = createKonanLibraryComponents(file, null, isDefault)
    }

internal class KonanLibraryProperResolver(
    repositories: List,
    directLibs: List,
    override val target: KonanTarget,
    distributionKlib: String?,
    localKonanDir: String?,
    skipCurrentDir: Boolean,
    override val logger: Logger
) : KotlinLibraryProperResolverWithAttributes(
    repositories, directLibs,
    distributionKlib,
    localKonanDir,
    skipCurrentDir,
    logger,
    listOf(KLIB_INTEROP_IR_PROVIDER_IDENTIFIER)
),  SearchPathResolverWithTarget
{
    override fun libraryComponentBuilder(file: File, isDefault: Boolean) = createKonanLibraryComponents(file, target, isDefault)

    override val distPlatformHead: File?
        get() = distributionKlib?.File()?.child("platform")?.child(target.visibleName)

    override fun libraryMatch(candidate: KonanLibrary, unresolved: UnresolvedLibrary): Boolean {
        val resolverTarget = this.target
        val candidatePath = candidate.libraryFile.absolutePath

        if (!candidate.targetList.contains(resolverTarget.visibleName)) {
            logger.warning("KLIB resolver: Skipping '$candidatePath'. The target doesn't match. Expected '$resolverTarget', found ${candidate.targetList}.")
            return false
        }

        return super.libraryMatch(candidate, unresolved)
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy