Make user provided libraries have precedence over default libraries.
Simplified duplicate elimination.
This commit is contained in:
committed by
alexander-gorshenev
parent
19fe0168ad
commit
a8c1851534
+5
-15
@@ -80,19 +80,16 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
||||
private val resolver = defaultResolver(repositories, distribution)
|
||||
|
||||
private val immediateLibraries: List<LibraryReaderImpl> by lazy {
|
||||
resolver.resolveImmediateLibraries(
|
||||
val result = resolver.resolveImmediateLibraries(
|
||||
libraryNames,
|
||||
targetManager.target,
|
||||
currentAbiVersion,
|
||||
configuration.getBoolean(KonanConfigKeys.NOSTDLIB),
|
||||
configuration.getBoolean(KonanConfigKeys.NODEFAULTLIBS),
|
||||
false
|
||||
).let {
|
||||
warnOnLibraryDuplicates(it.map { it.libraryFile })
|
||||
val result = it.distinctBy { it.libraryFile.absolutePath }
|
||||
resolver.resolveLibrariesRecursive(result, targetManager.target, currentAbiVersion)
|
||||
result
|
||||
}
|
||||
{ msg -> configuration.report(STRONG_WARNING, msg) }
|
||||
)
|
||||
resolver.resolveLibrariesRecursive(result, targetManager.target, currentAbiVersion)
|
||||
result
|
||||
}
|
||||
|
||||
fun librariesWithDependencies(moduleDescriptor: ModuleDescriptor?): List<KonanLibraryReader> {
|
||||
@@ -148,13 +145,6 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
||||
|
||||
loadedDescriptors
|
||||
}
|
||||
|
||||
private fun warnOnLibraryDuplicates(resolvedLibraries: List<File>) {
|
||||
val duplicates = resolvedLibraries.groupBy { it.absolutePath } .values.filter { it.size > 1 }
|
||||
duplicates.forEach {
|
||||
configuration.report(STRONG_WARNING, "library included more than once: ${it.first().absolutePath}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun CompilerConfiguration.report(priority: CompilerMessageSeverity, message: String)
|
||||
|
||||
+21
-8
@@ -46,20 +46,33 @@ fun SearchPathResolver.resolveImmediateLibraries(libraryNames: List<String>,
|
||||
abiVersion: Int = 1,
|
||||
noStdLib: Boolean = false,
|
||||
noDefaultLibs: Boolean = false,
|
||||
removeDuplicates: Boolean = true): List<LibraryReaderImpl> {
|
||||
logger: ((String) -> Unit)?): List<LibraryReaderImpl> {
|
||||
val userProvidedLibraries = libraryNames
|
||||
.map { resolve(it) }
|
||||
.map{ LibraryReaderImpl(it, abiVersion, target) }
|
||||
|
||||
val defaultLibraries = defaultLinks(nostdlib = noStdLib, noDefaultLibs = noDefaultLibs).map {
|
||||
LibraryReaderImpl(it, abiVersion, target, isDefaultLink = true)
|
||||
}
|
||||
|
||||
val userProvidedLibraries = libraryNames
|
||||
.map { resolve(it) }
|
||||
.map{ LibraryReaderImpl(it, abiVersion, target) }
|
||||
// Make sure the user provided ones appear first, so that
|
||||
// they have precedence over defaults when duplicates are eliminated.
|
||||
val resolvedLibraries = userProvidedLibraries + defaultLibraries
|
||||
|
||||
val resolvedLibraries = defaultLibraries + userProvidedLibraries
|
||||
warnOnLibraryDuplicates(resolvedLibraries.map { it.libraryFile }, logger)
|
||||
|
||||
return resolvedLibraries.let {
|
||||
if (removeDuplicates) it.distinctBy { it.libraryFile.absolutePath } else it
|
||||
return resolvedLibraries.distinctBy { it.libraryFile.absolutePath }
|
||||
}
|
||||
|
||||
private fun warnOnLibraryDuplicates(resolvedLibraries: List<File>,
|
||||
logger: ((String) -> Unit)? ) {
|
||||
|
||||
if (logger == null) return
|
||||
|
||||
val duplicates = resolvedLibraries.groupBy { it.absolutePath } .values.filter { it.size > 1 }
|
||||
|
||||
duplicates.forEach {
|
||||
logger("library included more than once: ${it.first().absolutePath}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +125,7 @@ fun SearchPathResolver.resolveLibrariesRecursive(libraryNames: List<String>,
|
||||
abiVersion = abiVersion,
|
||||
noStdLib = noStdLib,
|
||||
noDefaultLibs = noDefaultLibs,
|
||||
removeDuplicates = true
|
||||
logger = null
|
||||
)
|
||||
resolveLibrariesRecursive(immediateLibraries, target, abiVersion)
|
||||
return immediateLibraries.withResolvedDependencies()
|
||||
|
||||
Reference in New Issue
Block a user