diff options
author | Vedant Kumar <vsk@apple.com> | 2016-09-22 21:49:43 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2016-09-22 21:49:43 +0000 |
commit | 1ce90d889a2664dd8dd4cd5e6410a96f3595f33a (patch) | |
tree | 6f984f4a54dc83223c1c1f4e60b59cfb9b9e0437 /llvm/tools/llvm-cov/CodeCoverage.cpp | |
parent | 5f8492e2ce8efb55caad8f7b9c289edd1541dcf0 (diff) | |
download | bcm5719-llvm-1ce90d889a2664dd8dd4cd5e6410a96f3595f33a.tar.gz bcm5719-llvm-1ce90d889a2664dd8dd4cd5e6410a96f3595f33a.zip |
[llvm-cov] Add the ability to specify directories of input source files
We've supported restricting coverage reports to a set of files for a
long time. Add support for being able to restrict by entire directories.
I suppose this supersedes D20803.
llvm-svn: 282202
Diffstat (limited to 'llvm/tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 66 |
1 files changed, 56 insertions, 10 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 8c9da116b96..c16bfcccde0 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -64,6 +64,10 @@ public: /// \brief Copy \p Path into the list of input source files. void addCollectedPath(const std::string &Path); + /// \brief If \p Path is a regular file, collect the path. If it's a + /// directory, recursively collect all of the paths within the directory. + void collectPaths(const std::string &Path); + /// \brief Return a memory buffer for the given source file. ErrorOr<const MemoryBuffer &> getSourceFile(StringRef SourceFile); @@ -152,10 +156,49 @@ void CodeCoverageTool::warning(const Twine &Message, StringRef Whence) { } void CodeCoverageTool::addCollectedPath(const std::string &Path) { - CollectedPaths.push_back(Path); + if (CompareFilenamesOnly) { + CollectedPaths.push_back(Path); + } else { + SmallString<128> EffectivePath(Path); + if (std::error_code EC = sys::fs::make_absolute(EffectivePath)) { + error(EC.message(), Path); + return; + } + sys::path::remove_dots(EffectivePath, /*remove_dot_dots=*/true); + CollectedPaths.push_back(EffectivePath.str()); + } + SourceFiles.emplace_back(CollectedPaths.back()); } +void CodeCoverageTool::collectPaths(const std::string &Path) { + llvm::sys::fs::file_status Status; + llvm::sys::fs::status(Path, Status); + if (!llvm::sys::fs::exists(Status)) { + if (CompareFilenamesOnly) + addCollectedPath(Path); + else + error("Missing source file", Path); + return; + } + + if (llvm::sys::fs::is_regular_file(Status)) { + addCollectedPath(Path); + return; + } + + if (llvm::sys::fs::is_directory(Status)) { + std::error_code EC; + for (llvm::sys::fs::recursive_directory_iterator F(Path, EC), E; + F != E && !EC; F.increment(EC)) { + if (llvm::sys::fs::is_regular_file(F->path())) + addCollectedPath(F->path()); + } + if (EC) + warning(EC.message(), Path); + } +} + ErrorOr<const MemoryBuffer &> CodeCoverageTool::getSourceFile(StringRef SourceFile) { // If we've remapped filenames, look up the real location for this file. @@ -391,6 +434,10 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { cl::list<std::string> InputSourceFiles( cl::Positional, cl::desc("<Source files>"), cl::ZeroOrMore); + cl::opt<bool> DebugDumpCollectedPaths( + "dump-collected-paths", cl::Optional, cl::Hidden, + cl::desc("Show the collected paths to source files")); + cl::opt<std::string, true> PGOFilename( "instr-profile", cl::Required, cl::location(this->PGOFilename), cl::desc( @@ -535,16 +582,15 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { } CoverageArch = Arch; - for (const auto &File : InputSourceFiles) { - SmallString<128> Path(File); - if (!CompareFilenamesOnly) { - if (std::error_code EC = sys::fs::make_absolute(Path)) { - error(EC.message(), File); - return 1; - } - } - addCollectedPath(Path.str()); + for (const std::string &File : InputSourceFiles) + collectPaths(File); + + if (DebugDumpCollectedPaths) { + for (StringRef SF : SourceFiles) + outs() << SF << '\n'; + ::exit(0); } + return 0; }; |