diff --git a/compiler/util-klib/src/org/jetbrains/kotlin/library/SearchPathResolver.kt b/compiler/util-klib/src/org/jetbrains/kotlin/library/SearchPathResolver.kt index 244afda4296..55ba0a44ee3 100644 --- a/compiler/util-klib/src/org/jetbrains/kotlin/library/SearchPathResolver.kt +++ b/compiler/util-klib/src/org/jetbrains/kotlin/library/SearchPathResolver.kt @@ -132,22 +132,28 @@ abstract class KotlinLibrarySearchPathResolver( } } - override fun resolve(unresolved: UnresolvedLibrary, isDefaultLink: Boolean): L { - val givenPath = unresolved.path - try { - val fileSequence = resolutionSequence(givenPath) - val matching = fileSequence - .filterOutPre_1_4_libraries() - .flatMap { libraryComponentBuilder(it, isDefaultLink).asSequence() } - .map { it.takeIf { libraryMatch(it, unresolved) } } - .filterNotNull() + // Default libraries could be resolved several times during findLibraries and resolveDependencies. + // Store already resolved libraries. + private val resolvedLibraries = HashMap() - return matching.firstOrNull() ?: run { - logger.fatal("Could not find \"$givenPath\" in ${searchRoots.map { it.absolutePath }}.") + override fun resolve(unresolved: UnresolvedLibrary, isDefaultLink: Boolean): L { + return resolvedLibraries.getOrPut(unresolved) { + val givenPath = unresolved.path + try { + val fileSequence = resolutionSequence(givenPath) + val matching = fileSequence + .filterOutPre_1_4_libraries() + .flatMap { libraryComponentBuilder(it, isDefaultLink).asSequence() } + .map { it.takeIf { libraryMatch(it, unresolved) } } + .filterNotNull() + + matching.firstOrNull() ?: run { + logger.fatal("Could not find \"$givenPath\" in ${searchRoots.map { it.absolutePath }}.") + } + } catch (e: Throwable) { + logger.error("Failed to resolve Kotlin library: $givenPath") + throw e } - } catch (e: Throwable) { - logger.error("Failed to resolve Kotlin library: $givenPath") - throw e } }