[KLIB Resolver] Prettier KLIB resolver messages
- Make the messages that are reported by KLIB resolver prettier - For those messages that affect the resolve process add prefix "KLIB resolver: " - Don't log warning on duplicated libraries on the classpath. This does not make any sense. ^KT-63573
This commit is contained in:
committed by
Space Team
parent
3ab35cd417
commit
1c285de55e
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
error: could not find "not/existing/path" in [$USER_DIR$]
|
error: KLIB resolver: Could not find "not/existing/path" in [$USER_DIR$]
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
error: could not find "compiler/testData/integration/ant/js/simpleWithJsFileAsAnotherLib" in [$USER_DIR$]
|
error: KLIB resolver: Could not find "compiler/testData/integration/ant/js/simpleWithJsFileAsAnotherLib" in [$USER_DIR$]
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
+21
-20
@@ -65,33 +65,34 @@ class KotlinLibraryResolverImpl<L : KotlinLibrary> internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Leaves only distinct libraries (by absolute path), warns on duplicated paths.
|
* Leaves only distinct libraries (by absolute path).
|
||||||
*/
|
*/
|
||||||
private fun List<KotlinLibrary>.leaveDistinct() =
|
private fun List<KotlinLibrary>.leaveDistinct(): List<KotlinLibrary> {
|
||||||
this.groupBy { it.libraryFile.absolutePath }.let { groupedByAbsolutePath ->
|
if (size <= 1) return this
|
||||||
warnOnLibraryDuplicates(groupedByAbsolutePath.filter { it.value.size > 1 }.keys)
|
|
||||||
groupedByAbsolutePath.map { it.value.first() }
|
val deduplicatedLibraries: Map<String, List<KotlinLibrary>> = groupByTo(linkedMapOf()) { it.libraryFile.absolutePath }
|
||||||
}
|
return deduplicatedLibraries.values.map { it.first() }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Having two libraries with the same uniqName we only keep the first one.
|
* Having two libraries with the same `unique_name` we only keep the first one.
|
||||||
* TODO: The old JS plugin passes libraries with the same uniqName twice,
|
*
|
||||||
* so make it a warning for now.
|
* TODO: This is actually undesirable behavior.
|
||||||
|
* - In certain situations it harms, e.g. KT-63573
|
||||||
|
* - But sometimes it is really necessary, e.g. KT-64115
|
||||||
|
* - Overall, we should not do any resolve inside the compiler (such as skipping KLIBs that happen to have repeated `unique_name`).
|
||||||
|
* This is an opaque process which better should be performed by the build system (e.g. Gradle). To be fixed in KT-64169
|
||||||
*/
|
*/
|
||||||
private fun List<KotlinLibrary>.omitDuplicateNames() =
|
private fun List<KotlinLibrary>.omitDuplicateNames() =
|
||||||
this.groupBy { it.uniqueName }.let { groupedByUniqName ->
|
groupBy { it.uniqueName }.let { groupedByUniqName ->
|
||||||
warnOnLibraryDuplicateNames(groupedByUniqName.filter { it.value.size > 1 }.keys)
|
val librariesWithDuplicatedUniqueNames = groupedByUniqName.filterValues { it.size > 1 }
|
||||||
groupedByUniqName.map { it.value.first() }
|
librariesWithDuplicatedUniqueNames.entries.sortedBy { it.key }.forEach { (uniqueName, libraries) ->
|
||||||
|
val libraryPaths = libraries.map { it.libraryFile.absolutePath }.sorted().joinToString()
|
||||||
|
logger.warning("KLIB resolver: The same 'unique_name=$uniqueName' found in more than one library: $libraryPaths")
|
||||||
|
}
|
||||||
|
groupedByUniqName.map { it.value.first() } // This line is the reason of such issues as KT-63573.
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun warnOnLibraryDuplicates(duplicatedPaths: Iterable<String>) {
|
|
||||||
duplicatedPaths.forEach { logger.warning("library included more than once: $it") }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun warnOnLibraryDuplicateNames(duplicatedPaths: Iterable<String>) {
|
|
||||||
duplicatedPaths.forEach { logger.warning("duplicate library name: $it") }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given the list of root libraries does the following:
|
* Given the list of root libraries does the following:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ interface SearchPathResolver<L : KotlinLibrary> : WithLogger {
|
|||||||
return if (isDeprecated)
|
return if (isDeprecated)
|
||||||
LookupResult.FoundWithWarning(
|
LookupResult.FoundWithWarning(
|
||||||
library = resolvedLibrary,
|
library = resolvedLibrary,
|
||||||
warningText = "Library '${libraryPath.path}' was found in a custom library repository '${searchRootPath.path}'. " +
|
warningText = "KLIB resolver: Library '${libraryPath.path}' was found in a custom library repository '${searchRootPath.path}'. " +
|
||||||
"Note, that custom library repositories are deprecated and will be removed in one of the future Kotlin releases. " +
|
"Note, that custom library repositories are deprecated and will be removed in one of the future Kotlin releases. " +
|
||||||
"Please, avoid using '-repo' ('-r') compiler option and specify full paths to libraries in compiler CLI arguments."
|
"Please, avoid using '-repo' ('-r') compiler option and specify full paths to libraries in compiler CLI arguments."
|
||||||
)
|
)
|
||||||
@@ -231,7 +231,7 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
|
|||||||
|
|
||||||
private fun Sequence<File>.filterOutPre_1_4_libraries(): Sequence<File> = this.filter {
|
private fun Sequence<File>.filterOutPre_1_4_libraries(): Sequence<File> = this.filter {
|
||||||
if (it.isPre_1_4_Library) {
|
if (it.isPre_1_4_Library) {
|
||||||
logger.warning("Skipping \"$it\" as it is a pre 1.4 library")
|
logger.warning("KLIB resolver: Skipping '$it'. This is a pre 1.4 library.")
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
@@ -256,7 +256,7 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
|
|||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
.let(::ResolvedLibrary)
|
.let(::ResolvedLibrary)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
logger.error("Failed to resolve Kotlin library: $givenPath")
|
logger.error("KLIB resolver: Failed to resolve Kotlin library: $givenPath")
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}.library
|
}.library
|
||||||
@@ -268,7 +268,7 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
|
|||||||
|
|
||||||
override fun resolve(unresolved: RequiredUnresolvedLibrary, isDefaultLink: Boolean): L {
|
override fun resolve(unresolved: RequiredUnresolvedLibrary, isDefaultLink: Boolean): L {
|
||||||
return resolveOrNull(unresolved, isDefaultLink)
|
return resolveOrNull(unresolved, isDefaultLink)
|
||||||
?: logger.fatal("Could not find \"${unresolved.path}\" in ${searchRoots.map { it.searchRootPath.absolutePath }}")
|
?: logger.fatal("KLIB resolver: Could not find \"${unresolved.path}\" in ${searchRoots.map { it.searchRootPath.absolutePath }}")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun libraryMatch(candidate: L, unresolved: UnresolvedLibrary): Boolean = true
|
override fun libraryMatch(candidate: L, unresolved: UnresolvedLibrary): Boolean = true
|
||||||
@@ -342,7 +342,7 @@ abstract class KotlinLibraryProperResolverWithAttributes<L : KotlinLibrary>(
|
|||||||
// Please, don't add checks for other versions here. For example, check for the metadata version should be
|
// Please, don't add checks for other versions here. For example, check for the metadata version should be
|
||||||
// implemented in KlibDeserializedContainerSource.incompatibility
|
// implemented in KlibDeserializedContainerSource.incompatibility
|
||||||
if (candidateAbiVersion?.isCompatible() != true) {
|
if (candidateAbiVersion?.isCompatible() != true) {
|
||||||
logger.warning("skipping $candidatePath. Incompatible abi version. The current default is '${KotlinAbiVersion.CURRENT}', found '${candidateAbiVersion}'. The library produced by ${candidateCompilerVersion} compiler")
|
logger.warning("KLIB resolver: Skipping '$candidatePath'. Incompatible ABI version. The current default is '${KotlinAbiVersion.CURRENT}', found '${candidateAbiVersion}'. The library was produced by '$candidateCompilerVersion' compiler.")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,13 +350,13 @@ abstract class KotlinLibraryProperResolverWithAttributes<L : KotlinLibrary>(
|
|||||||
candidateLibraryVersion != null &&
|
candidateLibraryVersion != null &&
|
||||||
unresolved.libraryVersion != null
|
unresolved.libraryVersion != null
|
||||||
) {
|
) {
|
||||||
logger.warning("skipping $candidatePath. The library versions don't match. Expected '${unresolved.libraryVersion}', found '${candidateLibraryVersion}'")
|
logger.warning("KLIB resolver: Skipping '$candidatePath'. Library versions don't match. Expected '${unresolved.libraryVersion}', found '${candidateLibraryVersion}'.")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
candidate.irProviderName?.let {
|
candidate.irProviderName?.let {
|
||||||
if (it !in knownIrProviders) {
|
if (it !in knownIrProviders) {
|
||||||
logger.warning("skipping $candidatePath. The library requires unknown IR provider $it.")
|
logger.warning("KLIB resolver: Skipping '$candidatePath'. The library requires unknown IR provider: $it")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,9 +45,10 @@ object ToolingSingleFileKlibResolveStrategy : SingleFileKlibResolveStrategy {
|
|||||||
}
|
}
|
||||||
else -> { // TODO: choose the best fit among all available candidates
|
else -> { // TODO: choose the best fit among all available candidates
|
||||||
// mimic as old style library and warn
|
// mimic as old style library and warn
|
||||||
logger.warning("Library $libraryFile can not be read. Multiple components found: ${components.map {
|
logger.warning(
|
||||||
it.path.substringAfter(localRoot.path)
|
"KLIB resolver: Library '$libraryFile' can not be read." +
|
||||||
}}")
|
" Multiple components found: ${components.map { it.path.substringAfter(localRoot.path) }}"
|
||||||
|
)
|
||||||
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3937,7 +3937,7 @@ standaloneTest("library_ir_provider_mismatch") {
|
|||||||
String exceptionText = t.message
|
String exceptionText = t.message
|
||||||
exceptionText = PlatformInfo.isWindows() ? exceptionText.replace("\\", "/") : exceptionText
|
exceptionText = PlatformInfo.isWindows() ? exceptionText.replace("\\", "/") : exceptionText
|
||||||
|
|
||||||
String expectedText = "warning: skipping $outputDir/unsupported_ir_provider/empty.klib. The library requires unknown IR provider UNSUPPORTED."
|
String expectedText = "warning: KLIB resolver: Skipping '$outputDir/unsupported_ir_provider/empty.klib'. The library requires unknown IR provider: UNSUPPORTED"
|
||||||
expectedText = PlatformInfo.isWindows() ? expectedText.replace("\\", "/") : expectedText
|
expectedText = PlatformInfo.isWindows() ? expectedText.replace("\\", "/") : expectedText
|
||||||
|
|
||||||
if (t instanceof GradleException && exceptionText.contains(expectedText)) {
|
if (t instanceof GradleException && exceptionText.contains(expectedText)) {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ internal class KonanLibraryProperResolver(
|
|||||||
val candidatePath = candidate.libraryFile.absolutePath
|
val candidatePath = candidate.libraryFile.absolutePath
|
||||||
|
|
||||||
if (!candidate.targetList.contains(resolverTarget.visibleName)) {
|
if (!candidate.targetList.contains(resolverTarget.visibleName)) {
|
||||||
logger.warning("skipping $candidatePath. The target doesn't match. Expected '$resolverTarget', found ${candidate.targetList}")
|
logger.warning("KLIB resolver: Skipping '$candidatePath'. The target doesn't match. Expected '$resolverTarget', found ${candidate.targetList}.")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user