Escape resolving same library several times in K/N (#3880)

This commit is contained in:
LepilkinaElena
2020-11-03 15:57:48 +03:00
committed by GitHub
parent 1376fed1d4
commit ee8db2f760
@@ -132,7 +132,12 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
} }
} }
// Default libraries could be resolved several times during findLibraries and resolveDependencies.
// Store already resolved libraries.
private val resolvedLibraries = HashMap<UnresolvedLibrary, L>()
override fun resolve(unresolved: UnresolvedLibrary, isDefaultLink: Boolean): L { override fun resolve(unresolved: UnresolvedLibrary, isDefaultLink: Boolean): L {
return resolvedLibraries.getOrPut(unresolved) {
val givenPath = unresolved.path val givenPath = unresolved.path
try { try {
val fileSequence = resolutionSequence(givenPath) val fileSequence = resolutionSequence(givenPath)
@@ -142,7 +147,7 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
.map { it.takeIf { libraryMatch(it, unresolved) } } .map { it.takeIf { libraryMatch(it, unresolved) } }
.filterNotNull() .filterNotNull()
return matching.firstOrNull() ?: run { matching.firstOrNull() ?: run {
logger.fatal("Could not find \"$givenPath\" in ${searchRoots.map { it.absolutePath }}.") logger.fatal("Could not find \"$givenPath\" in ${searchRoots.map { it.absolutePath }}.")
} }
} catch (e: Throwable) { } catch (e: Throwable) {
@@ -150,6 +155,7 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
throw e throw e
} }
} }
}
override fun libraryMatch(candidate: L, unresolved: UnresolvedLibrary) = true override fun libraryMatch(candidate: L, unresolved: UnresolvedLibrary) = true