From 5a5b8ad2959c025dd6314c3b5b84559fc9a45785 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Thu, 8 Aug 2019 17:23:35 +0700 Subject: [PATCH] Coverage: Use featured libraries resolution for libraries to cover --- .../kotlin/backend/konan/FeaturedLibraries.kt | 21 ++++++++++++++++++- .../kotlin/backend/konan/KonanConfig.kt | 4 ++++ .../konan/llvm/coverage/CoverageManager.kt | 4 +--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FeaturedLibraries.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FeaturedLibraries.kt index de5c9196e72..d04c2344484 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FeaturedLibraries.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FeaturedLibraries.kt @@ -53,6 +53,17 @@ internal fun getSourceLibraries( FeaturedLibrariesReporter.forSourceLibraries(configuration) ) +internal fun getCoveredLibraries( + configuration: CompilerConfiguration, + resolvedLibraries: KonanLibraryResolveResult, + resolver: SearchPathResolver +): List = getFeaturedLibraries( + configuration.getList(KonanConfigKeys.LIBRARIES_TO_COVER), + resolvedLibraries, + resolver, + FeaturedLibrariesReporter.forCoveredLibraries(configuration) +) + private sealed class FeaturedLibrariesReporter { abstract fun reportIllegalKind(library: KonanLibrary) @@ -94,7 +105,6 @@ private sealed class FeaturedLibrariesReporter { "Following libraries are specified to be exported with -Xexport-library, but not included to the build:" } - // TODO: Reformulate? private class SourceLibrariesReporter(configuration: CompilerConfiguration) : BaseReporter(configuration) { override fun illegalKindMessage(kind: String, libraryName: String): String = "$kind library $libraryName can't be used as a source library" @@ -103,9 +113,18 @@ private sealed class FeaturedLibrariesReporter { "Following libraries are declared as source libraries with -Xsource-library, but not included to the build:" } + private class CoveredLibraryReporter(configuration: CompilerConfiguration): BaseReporter(configuration) { + override fun illegalKindMessage(kind: String, libraryName: String): String = + "$kind library $libraryName can't be covered" + + override fun notIncludedLibraryMessageTitle(): String = + "Following libraries are specified to be covered with -Xlibrary-to-cover, but not included to the build:" + } + companion object { fun forExportedLibraries(configuration: CompilerConfiguration): FeaturedLibrariesReporter = ExportedLibrariesReporter(configuration) fun forSourceLibraries(configuration: CompilerConfiguration): FeaturedLibrariesReporter = SourceLibrariesReporter(configuration) + fun forCoveredLibraries(configuration: CompilerConfiguration): FeaturedLibrariesReporter = CoveredLibraryReporter(configuration) } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt index 8bf150886fb..21aa50417f5 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt @@ -130,6 +130,10 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration getSourceLibraries(configuration, resolvedLibraries, resolver.searchPathResolver) } + internal val coveredLibraries by lazy { + getCoveredLibraries(configuration, resolvedLibraries, resolver.searchPathResolver) + } + fun librariesWithDependencies(moduleDescriptor: ModuleDescriptor?): List { if (moduleDescriptor == null) error("purgeUnneeded() only works correctly after resolve is over, and we have successfully marked package files as needed or not needed.") diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/coverage/CoverageManager.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/coverage/CoverageManager.kt index 44ccf5d5e82..7cd2ed532c8 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/coverage/CoverageManager.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/coverage/CoverageManager.kt @@ -27,9 +27,7 @@ internal class CoverageManager(val context: Context) { context.config.configuration.getBoolean(KonanConfigKeys.COVERAGE) private val librariesToCover: Set = - context.config.configuration.getList(KonanConfigKeys.LIBRARIES_TO_COVER) - .map { File(it).absolutePath.removeSuffixIfPresent(".klib") } - .toSet() + context.config.coveredLibraries.map { it.libraryName }.toSet() private val llvmProfileFilenameGlobal = "__llvm_profile_filename"