Moved library resolver with attributes to Kotlin.
Introduced a hierarchy of resolvers.
This commit is contained in:
committed by
alexander-gorshenev
parent
064d95baa3
commit
c59896b6d1
+26
-47
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.util.Logger
|
|||||||
|
|
||||||
const val KONAN_STDLIB_NAME = "stdlib"
|
const val KONAN_STDLIB_NAME = "stdlib"
|
||||||
|
|
||||||
interface SearchPathResolverWithTarget<out L: KotlinLibrary>: SearchPathResolverWithAttributes<L> {
|
interface SearchPathResolverWithTarget<L: KotlinLibrary>: SearchPathResolverWithAttributes<L> {
|
||||||
val target: KonanTarget
|
val target: KonanTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ fun defaultResolver(
|
|||||||
target: KonanTarget,
|
target: KonanTarget,
|
||||||
distribution: Distribution = Distribution(),
|
distribution: Distribution = Distribution(),
|
||||||
compatibleCompilerVersions: List<KonanVersion> = emptyList()
|
compatibleCompilerVersions: List<KonanVersion> = emptyList()
|
||||||
): SearchPathResolverWithTarget<KonanLibraryImpl> = defaultResolver(repositories, emptyList(), target, distribution, compatibleCompilerVersions)
|
): SearchPathResolverWithTarget<KonanLibrary> = defaultResolver(repositories, emptyList(), target, distribution, compatibleCompilerVersions)
|
||||||
|
|
||||||
fun defaultResolver(
|
fun defaultResolver(
|
||||||
repositories: List<String>,
|
repositories: List<String>,
|
||||||
@@ -31,7 +31,7 @@ fun defaultResolver(
|
|||||||
compatibleCompilerVersions: List<KonanVersion> = emptyList(),
|
compatibleCompilerVersions: List<KonanVersion> = emptyList(),
|
||||||
logger: Logger = DummyLogger,
|
logger: Logger = DummyLogger,
|
||||||
skipCurrentDir: Boolean = false
|
skipCurrentDir: Boolean = false
|
||||||
): SearchPathResolverWithTarget<KonanLibraryImpl> = KonanLibraryProperResolver(
|
): SearchPathResolverWithTarget<KonanLibrary> = KonanLibraryProperResolver(
|
||||||
repositories,
|
repositories,
|
||||||
directLibs,
|
directLibs,
|
||||||
target,
|
target,
|
||||||
@@ -40,20 +40,29 @@ fun defaultResolver(
|
|||||||
distribution.klib,
|
distribution.klib,
|
||||||
distribution.localKonanDir.absolutePath,
|
distribution.localKonanDir.absolutePath,
|
||||||
skipCurrentDir,
|
skipCurrentDir,
|
||||||
logger)
|
logger
|
||||||
|
)
|
||||||
|
|
||||||
internal class KonanLibraryProperResolver(
|
internal class KonanLibraryProperResolver(
|
||||||
repositories: List<String>,
|
repositories: List<String>,
|
||||||
directLibs: List<String>,
|
directLibs: List<String>,
|
||||||
override val target: KonanTarget,
|
override val target: KonanTarget,
|
||||||
override val knownAbiVersions: List<KotlinAbiVersion>?,
|
knownAbiVersions: List<KotlinAbiVersion>?,
|
||||||
override val knownCompilerVersions: List<KonanVersion>?,
|
knownCompilerVersions: List<KonanVersion>?,
|
||||||
distributionKlib: String?,
|
distributionKlib: String?,
|
||||||
localKonanDir: String?,
|
localKonanDir: String?,
|
||||||
skipCurrentDir: Boolean,
|
skipCurrentDir: Boolean,
|
||||||
override val logger: Logger = DummyLogger
|
override val logger: Logger
|
||||||
) : KotlinLibrarySearchPathResolver<KonanLibraryImpl>(repositories, directLibs, distributionKlib, localKonanDir, skipCurrentDir, logger),
|
) : KotlinLibraryProperResolverWithAttributes<KonanLibrary>(
|
||||||
SearchPathResolverWithTarget<KonanLibraryImpl>
|
repositories, directLibs,
|
||||||
|
knownAbiVersions,
|
||||||
|
knownCompilerVersions,
|
||||||
|
distributionKlib,
|
||||||
|
localKonanDir,
|
||||||
|
skipCurrentDir,
|
||||||
|
logger,
|
||||||
|
{file: File, isDefaultLink: Boolean -> createKonanLibrary(file, target, isDefaultLink)}
|
||||||
|
), SearchPathResolverWithTarget<KonanLibrary>
|
||||||
{
|
{
|
||||||
override val distPlatformHead: File?
|
override val distPlatformHead: File?
|
||||||
get() = distributionKlib?.File()?.child("platform")?.child(target.visibleName)
|
get() = distributionKlib?.File()?.child("platform")?.child(target.visibleName)
|
||||||
@@ -69,47 +78,17 @@ internal class KonanLibraryProperResolver(
|
|||||||
logger.fatal("Could not find \"$givenPath\" in ${searchRoots.map { it.absolutePath }}.")
|
logger.fatal("Could not find \"$givenPath\" in ${searchRoots.map { it.absolutePath }}.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal fun SearchPathResolverWithTarget<KonanLibraryImpl>.libraryMatch(candidate: KonanLibraryImpl, unresolved: UnresolvedLibrary): Boolean {
|
override fun libraryMatch(candidate: KonanLibrary, unresolved: UnresolvedLibrary): Boolean {
|
||||||
val resolverTarget = this.target
|
val resolverTarget = this.target
|
||||||
val candidatePath = candidate.libraryFile.absolutePath
|
val candidatePath = candidate.libraryFile.absolutePath
|
||||||
|
|
||||||
val candidateCompilerVersion = candidate.versions.compilerVersion
|
if (!candidate.targetList.contains(resolverTarget.visibleName)) {
|
||||||
val candidateAbiVersion = candidate.versions.abiVersion
|
logger.warning("skipping $candidatePath. The target doesn't match. Expected '$resolverTarget', found ${candidate.targetList}")
|
||||||
val candidateLibraryVersion = candidate.versions.libraryVersion
|
return false
|
||||||
|
|
||||||
if (!candidate.targetList.contains(resolverTarget.visibleName)) {
|
|
||||||
logger.warning("skipping $candidatePath. The target doesn't match. Expected '$resolverTarget', found ${candidate.targetList}")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
val abiVersionMatch = candidateAbiVersion != null &&
|
|
||||||
knownAbiVersions != null &&
|
|
||||||
knownAbiVersions!!.contains(candidateAbiVersion)
|
|
||||||
|
|
||||||
val compilerVersionMatch = candidateCompilerVersion != null &&
|
|
||||||
knownCompilerVersions != null &&
|
|
||||||
knownCompilerVersions!!.any { it.compatible(candidateCompilerVersion) }
|
|
||||||
|
|
||||||
if (!abiVersionMatch && !compilerVersionMatch) {
|
|
||||||
logger.warning("skipping $candidatePath. The abi versions don't match. Expected '${knownAbiVersions}', found '${candidateAbiVersion}'")
|
|
||||||
|
|
||||||
if (knownCompilerVersions != null) {
|
|
||||||
val expected = knownCompilerVersions?.map { it.toString(false, false) }
|
|
||||||
val found = candidateCompilerVersion?.toString(true, true)
|
|
||||||
logger.warning("The compiler versions don't match either. Expected '${expected}', found '${found}'")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return super.libraryMatch(candidate, unresolved)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (candidateLibraryVersion != unresolved.libraryVersion &&
|
|
||||||
candidateLibraryVersion != null &&
|
|
||||||
unresolved.libraryVersion != null) {
|
|
||||||
logger.warning("skipping $candidatePath. The library versions don't match. Expected '${unresolved.libraryVersion}', found '${candidateLibraryVersion}'")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -153,7 +153,7 @@ open class KonanLibrariesSpec(val task: KonanArtifactWithLibrariesTask, val proj
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
fun asFiles(resolver: SearchPathResolver<KonanLibraryImpl>): List<File> = mutableListOf<File>().apply {
|
fun asFiles(resolver: SearchPathResolver<*>): List<File> = mutableListOf<File>().apply {
|
||||||
files.flatMapTo(this) { it.files }
|
files.flatMapTo(this) { it.files }
|
||||||
addAll(artifactFiles)
|
addAll(artifactFiles)
|
||||||
addAll(task.platformConfiguration.files)
|
addAll(task.platformConfiguration.files)
|
||||||
|
|||||||
Reference in New Issue
Block a user