llvm.org GIT mirror llvm / ef76be0
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282202 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 3 years ago
2 changed file(s) with 66 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
0 RUN: mkdir -p %t/a/b/
1 RUN: echo "" > %t/a/b/c.tmp
2 RUN: echo "" > %t/a/d.tmp
3
4 RUN: llvm-cov show /dev/null -instr-profile /dev/null -dump-collected-paths %t | FileCheck %s
5 RUN: llvm-cov show /dev/null -instr-profile /dev/null -dump-collected-paths %t/a/b/c.tmp %t/a/d.tmp | FileCheck %s
6
7 CHECK-DAG: {{.*}}c.tmp
8 CHECK-DAG: {{.*}}d.tmp
6363 /// \brief Copy \p Path into the list of input source files.
6464 void addCollectedPath(const std::string &Path);
6565
66 /// \brief If \p Path is a regular file, collect the path. If it's a
67 /// directory, recursively collect all of the paths within the directory.
68 void collectPaths(const std::string &Path);
69
6670 /// \brief Return a memory buffer for the given source file.
6771 ErrorOr getSourceFile(StringRef SourceFile);
6872
151155 }
152156
153157 void CodeCoverageTool::addCollectedPath(const std::string &Path) {
154 CollectedPaths.push_back(Path);
158 if (CompareFilenamesOnly) {
159 CollectedPaths.push_back(Path);
160 } else {
161 SmallString<128> EffectivePath(Path);
162 if (std::error_code EC = sys::fs::make_absolute(EffectivePath)) {
163 error(EC.message(), Path);
164 return;
165 }
166 sys::path::remove_dots(EffectivePath, /*remove_dot_dots=*/true);
167 CollectedPaths.push_back(EffectivePath.str());
168 }
169
155170 SourceFiles.emplace_back(CollectedPaths.back());
171 }
172
173 void CodeCoverageTool::collectPaths(const std::string &Path) {
174 llvm::sys::fs::file_status Status;
175 llvm::sys::fs::status(Path, Status);
176 if (!llvm::sys::fs::exists(Status)) {
177 if (CompareFilenamesOnly)
178 addCollectedPath(Path);
179 else
180 error("Missing source file", Path);
181 return;
182 }
183
184 if (llvm::sys::fs::is_regular_file(Status)) {
185 addCollectedPath(Path);
186 return;
187 }
188
189 if (llvm::sys::fs::is_directory(Status)) {
190 std::error_code EC;
191 for (llvm::sys::fs::recursive_directory_iterator F(Path, EC), E;
192 F != E && !EC; F.increment(EC)) {
193 if (llvm::sys::fs::is_regular_file(F->path()))
194 addCollectedPath(F->path());
195 }
196 if (EC)
197 warning(EC.message(), Path);
198 }
156199 }
157200
158201 ErrorOr
389432
390433 cl::list InputSourceFiles(
391434 cl::Positional, cl::desc(""), cl::ZeroOrMore);
435
436 cl::opt DebugDumpCollectedPaths(
437 "dump-collected-paths", cl::Optional, cl::Hidden,
438 cl::desc("Show the collected paths to source files"));
392439
393440 cl::opt PGOFilename(
394441 "instr-profile", cl::Required, cl::location(this->PGOFilename),
534581 }
535582 CoverageArch = Arch;
536583
537 for (const auto &File : InputSourceFiles) {
538 SmallString<128> Path(File);
539 if (!CompareFilenamesOnly) {
540 if (std::error_code EC = sys::fs::make_absolute(Path)) {
541 error(EC.message(), File);
542 return 1;
543 }
544 }
545 addCollectedPath(Path.str());
546 }
584 for (const std::string &File : InputSourceFiles)
585 collectPaths(File);
586
587 if (DebugDumpCollectedPaths) {
588 for (StringRef SF : SourceFiles)
589 outs() << SF << '\n';
590 ::exit(0);
591 }
592
547593 return 0;
548594 };
549595