Warn on duplicate library inclusion.

This commit is contained in:
Alexander Gorshenev
2017-07-05 15:34:12 +03:00
committed by alexander-gorshenev
parent 99316263d5
commit cd9d0ab768
2 changed files with 17 additions and 3 deletions
@@ -72,8 +72,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
}
if (arguments.freeArgs.isEmpty() && !arguments.isUsefulWithoutFreeArgs) {
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
messageCollector.report(ERROR, "You have not specified any compilation arguments. No output has been produced.")
configuration.report(ERROR, "You have not specified any compilation arguments. No output has been produced.")
}
// TODO: catch Errors and IllegalStateException.
@@ -24,6 +24,9 @@ import org.jetbrains.kotlin.backend.konan.util.File
import org.jetbrains.kotlin.backend.konan.util.profile
import org.jetbrains.kotlin.backend.konan.util.removeSuffixIfPresent
import org.jetbrains.kotlin.backend.konan.util.suffixIfNot
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
@@ -69,7 +72,9 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
private val repositories = configuration.getList(KonanConfigKeys.REPOSITORIES) ?: emptyList()
private val resolver = KonanLibrarySearchPathResolver(repositories, distribution.klib, distribution.localKonanDir)
private val librariesFound: List<File> by lazy {
libraryNames.map{it -> resolver.resolve(it)}
val resolvedLibraries = libraryNames.map{it -> resolver.resolve(it)}
checkLibraryDuplicates(resolvedLibraries)
resolvedLibraries
}
internal val libraries: List<KonanLibraryReader> by lazy {
@@ -106,4 +111,14 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
loadedDescriptors
}
private fun checkLibraryDuplicates(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)
= this.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(priority, message)