[KLIB Resolver] Minor. Formatted
This commit is contained in:
committed by
Space Team
parent
69459b056e
commit
8430be39c9
+3
-3
@@ -5,7 +5,7 @@ import org.jetbrains.kotlin.library.SearchPathResolver
|
|||||||
import org.jetbrains.kotlin.library.UnresolvedLibrary
|
import org.jetbrains.kotlin.library.UnresolvedLibrary
|
||||||
import org.jetbrains.kotlin.library.metadata.PackageAccessHandler
|
import org.jetbrains.kotlin.library.metadata.PackageAccessHandler
|
||||||
|
|
||||||
interface KotlinLibraryResolver<L: KotlinLibrary> {
|
interface KotlinLibraryResolver<L : KotlinLibrary> {
|
||||||
|
|
||||||
val searchPathResolver: SearchPathResolver<L>
|
val searchPathResolver: SearchPathResolver<L>
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ interface KotlinLibraryResolver<L: KotlinLibrary> {
|
|||||||
unresolvedLibraries: List<UnresolvedLibrary>,
|
unresolvedLibraries: List<UnresolvedLibrary>,
|
||||||
noStdLib: Boolean = false,
|
noStdLib: Boolean = false,
|
||||||
noDefaultLibs: Boolean = false,
|
noDefaultLibs: Boolean = false,
|
||||||
noEndorsedLibs: Boolean = false
|
noEndorsedLibs: Boolean = false,
|
||||||
): KotlinLibraryResolveResult =
|
): KotlinLibraryResolveResult =
|
||||||
resolveWithoutDependencies(
|
resolveWithoutDependencies(
|
||||||
unresolvedLibraries,
|
unresolvedLibraries,
|
||||||
@@ -30,7 +30,7 @@ interface KotlinLibraryResolver<L: KotlinLibrary> {
|
|||||||
unresolvedLibraries: List<UnresolvedLibrary>,
|
unresolvedLibraries: List<UnresolvedLibrary>,
|
||||||
noStdLib: Boolean = false,
|
noStdLib: Boolean = false,
|
||||||
noDefaultLibs: Boolean = false,
|
noDefaultLibs: Boolean = false,
|
||||||
noEndorsedLibs: Boolean = false
|
noEndorsedLibs: Boolean = false,
|
||||||
): List<KotlinLibrary>
|
): List<KotlinLibrary>
|
||||||
|
|
||||||
fun List<KotlinLibrary>.resolveDependencies(): KotlinLibraryResolveResult
|
fun List<KotlinLibrary>.resolveDependencies(): KotlinLibraryResolveResult
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ import org.jetbrains.kotlin.library.metadata.PackageAccessHandler
|
|||||||
/**
|
/**
|
||||||
* A [KotlinLibrary] wrapper that is used for resolving library's dependencies.
|
* A [KotlinLibrary] wrapper that is used for resolving library's dependencies.
|
||||||
*/
|
*/
|
||||||
interface KotlinResolvedLibrary: PackageAccessHandler {
|
interface KotlinResolvedLibrary : PackageAccessHandler {
|
||||||
|
|
||||||
// The library itself.
|
// The library itself.
|
||||||
val library: KotlinLibrary
|
val library: KotlinLibrary
|
||||||
|
|||||||
+49
-50
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.library.metadata.resolver.impl
|
package org.jetbrains.kotlin.library.metadata.resolver.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.konan.file.File
|
|
||||||
import org.jetbrains.kotlin.library.*
|
import org.jetbrains.kotlin.library.*
|
||||||
import org.jetbrains.kotlin.library.metadata.PackageAccessHandler
|
import org.jetbrains.kotlin.library.metadata.PackageAccessHandler
|
||||||
import org.jetbrains.kotlin.library.metadata.resolver.KotlinLibraryResolveResult
|
import org.jetbrains.kotlin.library.metadata.resolver.KotlinLibraryResolveResult
|
||||||
@@ -25,18 +24,18 @@ import org.jetbrains.kotlin.library.metadata.resolver.KotlinResolvedLibrary
|
|||||||
import org.jetbrains.kotlin.library.metadata.resolver.LibraryOrder
|
import org.jetbrains.kotlin.library.metadata.resolver.LibraryOrder
|
||||||
import org.jetbrains.kotlin.util.WithLogger
|
import org.jetbrains.kotlin.util.WithLogger
|
||||||
|
|
||||||
fun <L: KotlinLibrary> SearchPathResolver<L>.libraryResolver(resolveManifestDependenciesLenient: Boolean = false)
|
fun <L : KotlinLibrary> SearchPathResolver<L>.libraryResolver(resolveManifestDependenciesLenient: Boolean = false) =
|
||||||
= KotlinLibraryResolverImpl<L>(this, resolveManifestDependenciesLenient)
|
KotlinLibraryResolverImpl<L>(this, resolveManifestDependenciesLenient)
|
||||||
|
|
||||||
class KotlinLibraryResolverImpl<L: KotlinLibrary> internal constructor(
|
class KotlinLibraryResolverImpl<L : KotlinLibrary> internal constructor(
|
||||||
override val searchPathResolver: SearchPathResolver<L>,
|
override val searchPathResolver: SearchPathResolver<L>,
|
||||||
val resolveManifestDependenciesLenient: Boolean
|
val resolveManifestDependenciesLenient: Boolean,
|
||||||
): KotlinLibraryResolver<L>, WithLogger by searchPathResolver {
|
) : KotlinLibraryResolver<L>, WithLogger by searchPathResolver {
|
||||||
override fun resolveWithoutDependencies(
|
override fun resolveWithoutDependencies(
|
||||||
unresolvedLibraries: List<UnresolvedLibrary>,
|
unresolvedLibraries: List<UnresolvedLibrary>,
|
||||||
noStdLib: Boolean,
|
noStdLib: Boolean,
|
||||||
noDefaultLibs: Boolean,
|
noDefaultLibs: Boolean,
|
||||||
noEndorsedLibs: Boolean
|
noEndorsedLibs: Boolean,
|
||||||
) = findLibraries(unresolvedLibraries, noStdLib, noDefaultLibs, noEndorsedLibs)
|
) = findLibraries(unresolvedLibraries, noStdLib, noDefaultLibs, noEndorsedLibs)
|
||||||
.leaveDistinct()
|
.leaveDistinct()
|
||||||
.omitDuplicateNames()
|
.omitDuplicateNames()
|
||||||
@@ -48,15 +47,15 @@ class KotlinLibraryResolverImpl<L: KotlinLibrary> internal constructor(
|
|||||||
* from the original library set (root set).
|
* from the original library set (root set).
|
||||||
*/
|
*/
|
||||||
private fun findLibraries(
|
private fun findLibraries(
|
||||||
unresolvedLibraries: List<UnresolvedLibrary>,
|
unresolvedLibraries: List<UnresolvedLibrary>,
|
||||||
noStdLib: Boolean,
|
noStdLib: Boolean,
|
||||||
noDefaultLibs: Boolean,
|
noDefaultLibs: Boolean,
|
||||||
noEndorsedLibs: Boolean
|
noEndorsedLibs: Boolean,
|
||||||
): List<KotlinLibrary> {
|
): List<KotlinLibrary> {
|
||||||
|
|
||||||
val userProvidedLibraries = unresolvedLibraries.asSequence()
|
val userProvidedLibraries = unresolvedLibraries.asSequence()
|
||||||
.mapNotNull { searchPathResolver.resolve(it) }
|
.mapNotNull { searchPathResolver.resolve(it) }
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
val defaultLibraries = searchPathResolver.defaultLinks(noStdLib, noDefaultLibs, noEndorsedLibs)
|
val defaultLibraries = searchPathResolver.defaultLinks(noStdLib, noDefaultLibs, noEndorsedLibs)
|
||||||
|
|
||||||
@@ -69,10 +68,10 @@ class KotlinLibraryResolverImpl<L: KotlinLibrary> internal constructor(
|
|||||||
* Leaves only distinct libraries (by absolute path), warns on duplicated paths.
|
* Leaves only distinct libraries (by absolute path), warns on duplicated paths.
|
||||||
*/
|
*/
|
||||||
private fun List<KotlinLibrary>.leaveDistinct() =
|
private fun List<KotlinLibrary>.leaveDistinct() =
|
||||||
this.groupBy { it.libraryFile.absolutePath }.let { groupedByAbsolutePath ->
|
this.groupBy { it.libraryFile.absolutePath }.let { groupedByAbsolutePath ->
|
||||||
warnOnLibraryDuplicates(groupedByAbsolutePath.filter { it.value.size > 1 }.keys)
|
warnOnLibraryDuplicates(groupedByAbsolutePath.filter { it.value.size > 1 }.keys)
|
||||||
groupedByAbsolutePath.map { it.value.first() }
|
groupedByAbsolutePath.map { it.value.first() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Having two libraries with the same uniqName we only keep the first one.
|
* Having two libraries with the same uniqName we only keep the first one.
|
||||||
@@ -80,10 +79,10 @@ class KotlinLibraryResolverImpl<L: KotlinLibrary> internal constructor(
|
|||||||
* so make it a warning for now.
|
* so make it a warning for now.
|
||||||
*/
|
*/
|
||||||
private fun List<KotlinLibrary>.omitDuplicateNames() =
|
private fun List<KotlinLibrary>.omitDuplicateNames() =
|
||||||
this.groupBy { it.uniqueName }.let { groupedByUniqName ->
|
this.groupBy { it.uniqueName }.let { groupedByUniqName ->
|
||||||
warnOnLibraryDuplicateNames(groupedByUniqName.filter { it.value.size > 1 }.keys)
|
warnOnLibraryDuplicateNames(groupedByUniqName.filter { it.value.size > 1 }.keys)
|
||||||
groupedByUniqName.map { it.value.first() }
|
groupedByUniqName.map { it.value.first() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun warnOnLibraryDuplicates(duplicatedPaths: Iterable<String>) {
|
private fun warnOnLibraryDuplicates(duplicatedPaths: Iterable<String>) {
|
||||||
duplicatedPaths.forEach { logger.warning("library included more than once: $it") }
|
duplicatedPaths.forEach { logger.warning("library included more than once: $it") }
|
||||||
@@ -115,21 +114,21 @@ class KotlinLibraryResolverImpl<L: KotlinLibrary> internal constructor(
|
|||||||
newDependencies = newDependencies.map { library: KotlinResolvedLibraryImpl ->
|
newDependencies = newDependencies.map { library: KotlinResolvedLibraryImpl ->
|
||||||
library.library.unresolvedDependencies(resolveManifestDependenciesLenient).asSequence()
|
library.library.unresolvedDependencies(resolveManifestDependenciesLenient).asSequence()
|
||||||
|
|
||||||
.filterNot { searchPathResolver.isProvidedByDefault(it) }
|
.filterNot { searchPathResolver.isProvidedByDefault(it) }
|
||||||
.mapNotNull { searchPathResolver.resolve(it)?.let(::KotlinResolvedLibraryImpl) }
|
.mapNotNull { searchPathResolver.resolve(it)?.let(::KotlinResolvedLibraryImpl) }
|
||||||
.map { resolved ->
|
.map { resolved ->
|
||||||
val fileKey = resolved.library.libraryFile.fileKey
|
val fileKey = resolved.library.libraryFile.fileKey
|
||||||
if (fileKey in cache) {
|
if (fileKey in cache) {
|
||||||
library.addDependency(cache[fileKey]!!)
|
library.addDependency(cache[fileKey]!!)
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
cache.put(fileKey, resolved)
|
cache.put(fileKey, resolved)
|
||||||
library.addDependency(resolved)
|
library.addDependency(resolved)
|
||||||
resolved
|
resolved
|
||||||
}
|
}
|
||||||
|
|
||||||
}.filterNotNull()
|
}.filterNotNull()
|
||||||
.toList()
|
.toList()
|
||||||
}.flatten()
|
}.flatten()
|
||||||
} while (newDependencies.isNotEmpty())
|
} while (newDependencies.isNotEmpty())
|
||||||
return result
|
return result
|
||||||
@@ -137,26 +136,26 @@ class KotlinLibraryResolverImpl<L: KotlinLibrary> internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class KotlinLibraryResolverResultImpl(
|
class KotlinLibraryResolverResultImpl(
|
||||||
private val roots: List<KotlinResolvedLibrary>
|
private val roots: List<KotlinResolvedLibrary>,
|
||||||
): KotlinLibraryResolveResult {
|
) : KotlinLibraryResolveResult {
|
||||||
|
|
||||||
private val all: List<KotlinResolvedLibrary>
|
private val all: List<KotlinResolvedLibrary>
|
||||||
by lazy {
|
by lazy {
|
||||||
val result = mutableSetOf<KotlinResolvedLibrary>().also { it.addAll(roots) }
|
val result = mutableSetOf<KotlinResolvedLibrary>().also { it.addAll(roots) }
|
||||||
|
|
||||||
var newDependencies = result.toList()
|
var newDependencies = result.toList()
|
||||||
do {
|
do {
|
||||||
newDependencies = newDependencies
|
newDependencies = newDependencies
|
||||||
.map { it.resolvedDependencies }.flatten()
|
.map { it.resolvedDependencies }.flatten()
|
||||||
.filter { it !in result }
|
.filter { it !in result }
|
||||||
result.addAll(newDependencies)
|
result.addAll(newDependencies)
|
||||||
} while (newDependencies.isNotEmpty())
|
} while (newDependencies.isNotEmpty())
|
||||||
|
|
||||||
result.toList()
|
result.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun filterRoots(predicate: (KotlinResolvedLibrary) -> Boolean) =
|
override fun filterRoots(predicate: (KotlinResolvedLibrary) -> Boolean) =
|
||||||
KotlinLibraryResolverResultImpl(roots.filter(predicate))
|
KotlinLibraryResolverResultImpl(roots.filter(predicate))
|
||||||
|
|
||||||
override fun getFullResolvedList(order: LibraryOrder?) = (order?.invoke(all) ?: all)
|
override fun getFullResolvedList(order: LibraryOrder?) = (order?.invoke(all) ?: all)
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -4,7 +4,7 @@ import org.jetbrains.kotlin.library.KotlinLibrary
|
|||||||
import org.jetbrains.kotlin.library.metadata.parseModuleHeader
|
import org.jetbrains.kotlin.library.metadata.parseModuleHeader
|
||||||
import org.jetbrains.kotlin.library.metadata.resolver.KotlinResolvedLibrary
|
import org.jetbrains.kotlin.library.metadata.resolver.KotlinResolvedLibrary
|
||||||
|
|
||||||
class KotlinResolvedLibraryImpl(override val library: KotlinLibrary): KotlinResolvedLibrary {
|
class KotlinResolvedLibraryImpl(override val library: KotlinLibrary) : KotlinResolvedLibrary {
|
||||||
|
|
||||||
private val _resolvedDependencies = mutableListOf<KotlinResolvedLibrary>()
|
private val _resolvedDependencies = mutableListOf<KotlinResolvedLibrary>()
|
||||||
private val _emptyPackages by lazy { parseModuleHeader(library.moduleHeaderData).emptyPackageList }
|
private val _emptyPackages by lazy { parseModuleHeader(library.moduleHeaderData).emptyPackageList }
|
||||||
@@ -22,10 +22,11 @@ class KotlinResolvedLibraryImpl(override val library: KotlinLibrary): KotlinReso
|
|||||||
|
|
||||||
override fun markNeededForLink(
|
override fun markNeededForLink(
|
||||||
library: KotlinLibrary,
|
library: KotlinLibrary,
|
||||||
fqName: String
|
fqName: String,
|
||||||
) {
|
) {
|
||||||
if (!isNeededForLink // fast path
|
if (!isNeededForLink // fast path
|
||||||
&& !_emptyPackages.contains(fqName)) {
|
&& !_emptyPackages.contains(fqName)
|
||||||
|
) {
|
||||||
isNeededForLink = true
|
isNeededForLink = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user