diff options
Diffstat (limited to 'llvm/tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 7151cfb032f..79c58450f0d 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -126,7 +126,7 @@ private: std::vector<StringRef> ObjectFilenames; CoverageViewOptions ViewOpts; CoverageFiltersMatchAll Filters; - CoverageFilters IgnoreFilenameFilters; + FilenameCoverageFilters FilenameFilters; /// The path to the indexed profile. std::string PGOFilename; @@ -190,7 +190,7 @@ void CodeCoverageTool::addCollectedPath(const std::string &Path) { return; } sys::path::remove_dots(EffectivePath, /*remove_dot_dots=*/true); - if (!IgnoreFilenameFilters.matchesFilename(EffectivePath)) + if (FilenameFilters.matchesFilename(EffectivePath)) SourceFiles.emplace_back(EffectivePath.str()); } @@ -595,6 +595,12 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { "regular expression"), cl::ZeroOrMore, cl::cat(FilteringCategory)); + cl::list<std::string> WhitelistFilenameRegexFilters( + "whitelist-filename-regex", cl::Optional, + cl::desc("Show code coverage only for file paths that match the given " + "regular expression"), + cl::ZeroOrMore, cl::cat(FilteringCategory)); + cl::list<std::string> IgnoreFilenameRegexFilters( "ignore-filename-regex", cl::Optional, cl::desc("Skip source code files with file paths that match the given " @@ -744,10 +750,11 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { Filters.push_back(std::move(StatFilterer)); } - // Create the ignore filename filters. + // Create the filename filters. for (const auto &RE : IgnoreFilenameRegexFilters) - IgnoreFilenameFilters.push_back( - std::make_unique<NameRegexCoverageFilter>(RE)); + FilenameFilters.blacklist(std::make_unique<NameRegexCoverageFilter>(RE)); + for (const auto &RE : WhitelistFilenameRegexFilters) + FilenameFilters.whitelist(std::make_unique<NameRegexCoverageFilter>(RE)); if (!Arches.empty()) { for (const std::string &Arch : Arches) { @@ -763,7 +770,7 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { } } - // IgnoreFilenameFilters are applied even when InputSourceFiles specified. + // FilenameFilters are applied even when InputSourceFiles specified. for (const std::string &File : InputSourceFiles) collectPaths(File); @@ -884,7 +891,7 @@ int CodeCoverageTool::doShow(int argc, const char **argv, if (SourceFiles.empty()) // Get the source files from the function coverage mapping. for (StringRef Filename : Coverage->getUniqueSourceFiles()) { - if (!IgnoreFilenameFilters.matchesFilename(Filename)) + if (FilenameFilters.matchesFilename(Filename)) SourceFiles.push_back(Filename); } @@ -988,7 +995,7 @@ int CodeCoverageTool::doReport(int argc, const char **argv, CoverageReport Report(ViewOpts, *Coverage.get()); if (!ShowFunctionSummaries) { if (SourceFiles.empty()) - Report.renderFileReports(llvm::outs(), IgnoreFilenameFilters); + Report.renderFileReports(llvm::outs(), FilenameFilters); else Report.renderFileReports(llvm::outs(), SourceFiles); } else { @@ -1054,7 +1061,7 @@ int CodeCoverageTool::doExport(int argc, const char **argv, } if (SourceFiles.empty()) - Exporter->renderRoot(IgnoreFilenameFilters); + Exporter->renderRoot(FilenameFilters); else Exporter->renderRoot(SourceFiles); |