[klib-resolver] Resolve libraries passed as files by unique name (#2104)
This commit is contained in:
+7
-1
@@ -76,7 +76,13 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
|||||||
private val repositories = configuration.getList(KonanConfigKeys.REPOSITORIES)
|
private val repositories = configuration.getList(KonanConfigKeys.REPOSITORIES)
|
||||||
private fun resolverLogger(msg: String) = configuration.report(STRONG_WARNING, msg)
|
private fun resolverLogger(msg: String) = configuration.report(STRONG_WARNING, msg)
|
||||||
|
|
||||||
private val resolver = defaultResolver(repositories, target, distribution, ::resolverLogger).libraryResolver()
|
private val resolver = defaultResolver(
|
||||||
|
repositories,
|
||||||
|
libraryNames.filter { it.contains(File.separator) },
|
||||||
|
target,
|
||||||
|
distribution,
|
||||||
|
::resolverLogger
|
||||||
|
).libraryResolver()
|
||||||
|
|
||||||
internal val resolvedLibraries by lazy {
|
internal val resolvedLibraries by lazy {
|
||||||
resolver.resolveWithDependencies(
|
resolver.resolveWithDependencies(
|
||||||
|
|||||||
+40
-14
@@ -29,17 +29,20 @@ interface SearchPathResolverWithTarget: SearchPathResolver {
|
|||||||
|
|
||||||
fun defaultResolver(
|
fun defaultResolver(
|
||||||
repositories: List<String>,
|
repositories: List<String>,
|
||||||
target: KonanTarget
|
target: KonanTarget,
|
||||||
): SearchPathResolverWithTarget = defaultResolver(repositories, target, Distribution())
|
distribution: Distribution = Distribution()
|
||||||
|
): SearchPathResolverWithTarget = defaultResolver(repositories, emptyList(), target, distribution)
|
||||||
|
|
||||||
fun defaultResolver(
|
fun defaultResolver(
|
||||||
repositories: List<String>,
|
repositories: List<String>,
|
||||||
|
directLibs: List<String>,
|
||||||
target: KonanTarget,
|
target: KonanTarget,
|
||||||
distribution: Distribution,
|
distribution: Distribution,
|
||||||
logger: Logger = ::dummyLogger,
|
logger: Logger = ::dummyLogger,
|
||||||
skipCurrentDir: Boolean = false
|
skipCurrentDir: Boolean = false
|
||||||
): SearchPathResolverWithTarget = KonanLibraryProperResolver(
|
): SearchPathResolverWithTarget = KonanLibraryProperResolver(
|
||||||
repositories,
|
repositories,
|
||||||
|
directLibs,
|
||||||
target,
|
target,
|
||||||
listOf(KonanAbiVersion.CURRENT),
|
listOf(KonanAbiVersion.CURRENT),
|
||||||
listOf(KonanVersion.CURRENT),
|
listOf(KonanVersion.CURRENT),
|
||||||
@@ -50,13 +53,15 @@ fun defaultResolver(
|
|||||||
|
|
||||||
fun resolverByName(
|
fun resolverByName(
|
||||||
repositories: List<String>,
|
repositories: List<String>,
|
||||||
|
directLibs: List<String> = emptyList(),
|
||||||
distributionKlib: String? = null,
|
distributionKlib: String? = null,
|
||||||
localKonanDir: String? = null,
|
localKonanDir: String? = null,
|
||||||
skipCurrentDir: Boolean = false
|
skipCurrentDir: Boolean = false
|
||||||
): SearchPathResolver = KonanLibrarySearchPathResolver(repositories, distributionKlib, localKonanDir, skipCurrentDir)
|
): SearchPathResolver = KonanLibrarySearchPathResolver(repositories, directLibs, distributionKlib, localKonanDir, skipCurrentDir)
|
||||||
|
|
||||||
internal open class KonanLibrarySearchPathResolver(
|
internal open class KonanLibrarySearchPathResolver(
|
||||||
repositories: List<String>,
|
repositories: List<String>,
|
||||||
|
directLibs: List<String>,
|
||||||
val distributionKlib: String?,
|
val distributionKlib: String?,
|
||||||
val localKonanDir: String?,
|
val localKonanDir: String?,
|
||||||
val skipCurrentDir: Boolean,
|
val skipCurrentDir: Boolean,
|
||||||
@@ -76,6 +81,10 @@ internal open class KonanLibrarySearchPathResolver(
|
|||||||
|
|
||||||
private val repoRoots: List<File> by lazy { repositories.map { File(it) } }
|
private val repoRoots: List<File> by lazy { repositories.map { File(it) } }
|
||||||
|
|
||||||
|
private val directLibraries: List<KonanLibrary> by lazy {
|
||||||
|
directLibs.mapNotNull { found(File(it)) }.map { createKonanLibrary(it, null) }
|
||||||
|
}
|
||||||
|
|
||||||
// This is the place where we specify the order of library search.
|
// This is the place where we specify the order of library search.
|
||||||
override val searchRoots: List<File> by lazy {
|
override val searchRoots: List<File> by lazy {
|
||||||
(listOf(currentDirHead) + repoRoots + listOf(localHead, distHead, distPlatformHead)).filterNotNull()
|
(listOf(currentDirHead) + repoRoots + listOf(localHead, distHead, distPlatformHead)).filterNotNull()
|
||||||
@@ -99,9 +108,24 @@ internal open class KonanLibrarySearchPathResolver(
|
|||||||
val sequence = if (given.isAbsolute) {
|
val sequence = if (given.isAbsolute) {
|
||||||
sequenceOf(found(given))
|
sequenceOf(found(given))
|
||||||
} else {
|
} else {
|
||||||
searchRoots.asSequence().map {
|
// Search among user-provided libraries by unique name.
|
||||||
|
// It's a workaround for maven publication. When a library is published without Gradle metadata,
|
||||||
|
// it has a complex file name (e.g. foo-macos_x64-1.0.klib). But a dependency on this lib in manifests
|
||||||
|
// of other libs uses its unique name written in the manifest (i.e just 'foo'). So we cannot resolve this
|
||||||
|
// library by its filename. But we have this library's file (we've downloaded it using maven dependency
|
||||||
|
// resolution) so we can pass it to the compiler directly. This code takes this into account and looks for
|
||||||
|
// a library dependencies also in libs passed to the compiler as files (passed to the resolver as the
|
||||||
|
// 'directLibraries' property).
|
||||||
|
val directLibs = directLibraries.asSequence().filter {
|
||||||
|
it.uniqueName == givenPath
|
||||||
|
}.map {
|
||||||
|
it.libraryFile
|
||||||
|
}
|
||||||
|
// Search among libraries in repositoreis by library filename.
|
||||||
|
val repoLibs = searchRoots.asSequence().map {
|
||||||
found(File(it, givenPath))
|
found(File(it, givenPath))
|
||||||
}
|
}
|
||||||
|
directLibs + repoLibs
|
||||||
}
|
}
|
||||||
return sequence.filterNotNull()
|
return sequence.filterNotNull()
|
||||||
}
|
}
|
||||||
@@ -144,16 +168,18 @@ internal open class KonanLibrarySearchPathResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class KonanLibraryProperResolver(
|
internal class KonanLibraryProperResolver(
|
||||||
repositories: List<String>,
|
repositories: List<String>,
|
||||||
override val target: KonanTarget,
|
directLibs: List<String>,
|
||||||
override val knownAbiVersions: List<KonanAbiVersion>?,
|
override val target: KonanTarget,
|
||||||
override val knownCompilerVersions: List<KonanVersion>?,
|
override val knownAbiVersions: List<KonanAbiVersion>?,
|
||||||
distributionKlib: String?,
|
override val knownCompilerVersions: List<KonanVersion>?,
|
||||||
localKonanDir: String?,
|
distributionKlib: String?,
|
||||||
skipCurrentDir: Boolean,
|
localKonanDir: String?,
|
||||||
override val logger: Logger = ::dummyLogger
|
skipCurrentDir: Boolean,
|
||||||
): KonanLibrarySearchPathResolver(repositories, distributionKlib, localKonanDir, skipCurrentDir, logger), SearchPathResolverWithTarget {
|
override val logger: Logger = ::dummyLogger
|
||||||
|
) : KonanLibrarySearchPathResolver(repositories, directLibs, distributionKlib, localKonanDir, skipCurrentDir, logger),
|
||||||
|
SearchPathResolverWithTarget
|
||||||
|
{
|
||||||
override val distPlatformHead: File?
|
override val distPlatformHead: File?
|
||||||
get() = distributionKlib?.File()?.child("platform")?.child(target.visibleName)
|
get() = distributionKlib?.File()?.child("platform")?.child(target.visibleName)
|
||||||
|
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ data class File constructor(internal val javaPath: Path) {
|
|||||||
val javaHome
|
val javaHome
|
||||||
get() = File(System.getProperty("java.home"))
|
get() = File(System.getProperty("java.home"))
|
||||||
val pathSeparator = java.io.File.pathSeparator
|
val pathSeparator = java.io.File.pathSeparator
|
||||||
|
val separator = java.io.File.separator
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readStrings() = mutableListOf<String>().also { list -> forEachLine{list.add(it)}}
|
fun readStrings() = mutableListOf<String>().also { list -> forEachLine{list.add(it)}}
|
||||||
|
|||||||
+2
-3
@@ -106,9 +106,8 @@ open class CInteropTask @Inject constructor(val settings: CInteropSettingsImpl):
|
|||||||
addArgs("-copt", allHeadersDirs.map { "-I${it.absolutePath}" })
|
addArgs("-copt", allHeadersDirs.map { "-I${it.absolutePath}" })
|
||||||
addArgs("-headerFilterAdditionalSearchPrefix", headerFilterDirs.map { it.absolutePath })
|
addArgs("-headerFilterAdditionalSearchPrefix", headerFilterDirs.map { it.absolutePath })
|
||||||
|
|
||||||
libraries.files.forEach { library ->
|
libraries.files.forEach {
|
||||||
library.parent?.let { addArg("-r", it) }
|
addArg("-l", it.absolutePath)
|
||||||
addArg("-l", library.nameWithoutExtension)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addAll(extraOpts)
|
addAll(extraOpts)
|
||||||
|
|||||||
+2
-3
@@ -157,9 +157,8 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
|
|||||||
|
|
||||||
addAll(additionalCompilerOptions)
|
addAll(additionalCompilerOptions)
|
||||||
|
|
||||||
libraries.files.forEach {library ->
|
libraries.files.forEach {
|
||||||
library.parent?.let { addArg("-r", it) }
|
addArg("-l", it.absolutePath)
|
||||||
addArg("-l", library.nameWithoutExtension)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addListArg("-linker-options", linkerOpts)
|
addListArg("-linker-options", linkerOpts)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.jetbrains.kotlin.konan.file.File
|
|||||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
import org.jetbrains.kotlin.konan.target.PlatformManager
|
||||||
import org.jetbrains.kotlin.konan.KonanAbiVersion
|
import org.jetbrains.kotlin.konan.KonanAbiVersion
|
||||||
import org.jetbrains.kotlin.konan.library.*
|
import org.jetbrains.kotlin.konan.library.*
|
||||||
|
import org.jetbrains.kotlin.konan.target.Distribution
|
||||||
import org.jetbrains.kotlin.native.interop.gen.jvm.interop
|
import org.jetbrains.kotlin.native.interop.gen.jvm.interop
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
|
||||||
@@ -54,7 +55,12 @@ fun invokeInterop(flavor: String, args: Array<String>): Array<String> {
|
|||||||
val manifest = File(buildDir, "manifest.properties")
|
val manifest = File(buildDir, "manifest.properties")
|
||||||
|
|
||||||
val target = PlatformManager().targetManager(targetRequest).target
|
val target = PlatformManager().targetManager(targetRequest).target
|
||||||
val resolver = defaultResolver(repos, target).libraryResolver()
|
val resolver = defaultResolver(
|
||||||
|
repos,
|
||||||
|
libraries.filter { it.contains(File.separator) },
|
||||||
|
target,
|
||||||
|
Distribution()
|
||||||
|
).libraryResolver()
|
||||||
val allLibraries = resolver.resolveWithDependencies(
|
val allLibraries = resolver.resolveWithDependencies(
|
||||||
libraries.toUnresolvedLibraries, noStdLib = true, noDefaultLibs = noDefaultLibs
|
libraries.toUnresolvedLibraries, noStdLib = true, noDefaultLibs = noDefaultLibs
|
||||||
).getFullList()
|
).getFullList()
|
||||||
|
|||||||
Reference in New Issue
Block a user