Index: tools/llvm-cov/CodeCoverage.cpp =================================================================== --- tools/llvm-cov/CodeCoverage.cpp +++ tools/llvm-cov/CodeCoverage.cpp @@ -32,7 +32,10 @@ #include "llvm/Support/Process.h" #include "llvm/Support/Signals.h" #include +#include #include +#include +#include using namespace llvm; using namespace coverage; @@ -70,6 +73,8 @@ /// \brief Load the coverage mapping data. Return true if an error occured. std::unique_ptr load(); + void walk(SmallString<128> Path); + int run(Command Cmd, int argc, const char **argv); typedef std::function CommandLineParserType; @@ -239,6 +244,30 @@ return Coverage; } +void CodeCoverageTool::walk(SmallString<128> Path) { + struct stat info; + if (stat(std::string(Path.str()).c_str(), &info) != 0) + errs() << "cannot access " << Path << "\n"; + else if (info.st_mode & S_IFDIR) { + std::error_code EC; + struct stat StatBuf; + // Walk all of the files within this directory. + for (llvm::sys::fs::directory_iterator File(Path, EC), FileEnd; + File != FileEnd && !EC; File.increment(EC)) { + if (stat(File->path().c_str(), &StatBuf)) + continue; + // If we have a directory, look inside. + if (llvm::sys::fs::is_directory(File->path())) { + walk((SmallString<128>)File->path()); + continue; + } + SourceFiles.push_back(File->path().c_str()); + } + } else + SourceFiles.push_back(Path.str()); + return; +} + int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { // Print a stack trace if we signal out. sys::PrintStackTraceOnErrorSignal(); @@ -362,7 +391,7 @@ errs() << "error: " << File << ": " << EC.message(); return 1; } - SourceFiles.push_back(Path.str()); + walk(Path); } return 0; };