From 3ab35cd417b477d9223c513c855134335d80e168 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Thu, 7 Dec 2023 16:28:15 +0100 Subject: [PATCH] [KLIB Resolver] Don't log any messages in `isKotlinLibrary(File)` fun This function is only used for probing if a library at the given path exists. Any errors or warnings logged by this function could only bring a user to a confusion. So, it's better to avoid any logging here. ^KT-63573 --- .../kotlin/library/impl/KotlinLibraryImpl.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/compiler/util-klib/src/org/jetbrains/kotlin/library/impl/KotlinLibraryImpl.kt b/compiler/util-klib/src/org/jetbrains/kotlin/library/impl/KotlinLibraryImpl.kt index e9f98ea89dd..c7aec4f5b2f 100644 --- a/compiler/util-klib/src/org/jetbrains/kotlin/library/impl/KotlinLibraryImpl.kt +++ b/compiler/util-klib/src/org/jetbrains/kotlin/library/impl/KotlinLibraryImpl.kt @@ -21,6 +21,8 @@ import org.jetbrains.kotlin.konan.file.ZipFileSystemAccessor import org.jetbrains.kotlin.konan.properties.Properties import org.jetbrains.kotlin.konan.properties.loadProperties import org.jetbrains.kotlin.library.* +import org.jetbrains.kotlin.util.DummyLogger +import org.jetbrains.kotlin.util.Logger class BaseKotlinLibraryImpl( val access: BaseLibraryAccess, @@ -356,8 +358,25 @@ fun createKotlinLibraryComponents( } fun isKotlinLibrary(libraryFile: File): Boolean = try { - resolveSingleFileKlib(libraryFile) - true + val libraryPath = libraryFile.absolutePath + + /** + * Important: Try to resolve it as a "lenient" library. This will allow to probe a library + * without logging any errors to [DummyLogger] and without any side effects such as throwing an + * exception from [SingleKlibComponentResolver.resolve] if the library is not found. + */ + SingleKlibComponentResolver( + klibFile = libraryPath, + logger = object : Logger { + override fun log(message: String) = Unit // don't log + override fun error(message: String) = Unit // don't log + override fun warning(message: String) = Unit // don't log + override fun fatal(message: String): Nothing = kotlin.error("This function should not be called") + }, + knownIrProviders = emptyList() + ).resolve( + LenientUnresolvedLibrary(libraryPath, libraryVersion = null) + ) != null } catch (e: Throwable) { false }