RUN: echo "" > %t/a/b/c.tmp
RUN: echo "" > %t/a/d.tmp
-RUN: llvm-cov show /dev/null -instr-profile /dev/null -dump-collected-paths %t | FileCheck %s
-RUN: llvm-cov show /dev/null -instr-profile /dev/null -dump-collected-paths %t/a/b/c.tmp %t/a/d.tmp | FileCheck %s
+RUN: llvm-cov show /dev/null -instr-profile /dev/null -dump-collected-paths %t | FileCheck %s --check-prefix=REAL
+RUN: llvm-cov show /dev/null -instr-profile /dev/null -dump-collected-paths %t/a/b/c.tmp %t/a/d.tmp | FileCheck %s --check-prefix=REAL
-CHECK-DAG: {{.*}}c.tmp
-CHECK-DAG: {{.*}}d.tmp
+REAL-DAG: {{.*}}c.tmp
+REAL-DAG: {{.*}}d.tmp
+
+RUN: llvm-cov show /dev/null -instr-profile /dev/null -dump-collected-paths -filename-equivalence %t a b c d e f | FileCheck %s --check-prefix=EQUIV
+EQUIV-DAG: {{.*}}c.tmp
+EQUIV-DAG: {{.*}}d.tmp
+EQUIV-DAG: a
+EQUIV-DAG: b
+EQUIV-DAG: c
+EQUIV-DAG: d
+EQUIV-DAG: e
+EQUIV-DAG: f
/// \brief Print the warning message to the error output stream.
void warning(const Twine &Message, StringRef Whence = "");
- /// \brief Copy \p Path into the list of input source files.
+ /// \brief Convert \p Path into an absolute path and append it to the list
+ /// of collected paths.
void addCollectedPath(const std::string &Path);
/// \brief If \p Path is a regular file, collect the path. If it's a
std::string PGOFilename;
/// A list of input source files.
- std::vector<StringRef> SourceFiles;
+ std::vector<std::string> SourceFiles;
/// Whether or not we're in -filename-equivalence mode.
bool CompareFilenamesOnly;
/// A cache for demangled symbol names.
StringMap<std::string> DemangledNames;
- /// File paths (absolute, or otherwise) to input source files.
- std::vector<std::string> CollectedPaths;
-
/// Errors and warnings which have not been printed.
std::mutex ErrsLock;
void CodeCoverageTool::addCollectedPath(const std::string &Path) {
if (CompareFilenamesOnly) {
- CollectedPaths.push_back(Path);
+ SourceFiles.emplace_back(Path);
} else {
SmallString<128> EffectivePath(Path);
if (std::error_code EC = sys::fs::make_absolute(EffectivePath)) {
return;
}
sys::path::remove_dots(EffectivePath, /*remove_dot_dots=*/true);
- CollectedPaths.push_back(EffectivePath.str());
+ SourceFiles.emplace_back(EffectivePath.str());
}
-
- SourceFiles.emplace_back(CollectedPaths.back());
}
void CodeCoverageTool::collectPaths(const std::string &Path) {
collectPaths(File);
if (DebugDumpCollectedPaths) {
- for (StringRef SF : SourceFiles)
+ for (const std::string &SF : SourceFiles)
outs() << SF << '\n';
::exit(0);
}
ThreadCount = std::thread::hardware_concurrency();
ThreadPool Pool(ThreadCount);
- for (StringRef SourceFile : SourceFiles) {
- Pool.async([this, SourceFile, &Coverage, &Printer, ShowFilenames] {
+ for (const std::string &SourceFile : SourceFiles) {
+ Pool.async([this, &SourceFile, &Coverage, &Printer, ShowFilenames] {
auto View = createSourceFileView(SourceFile, *Coverage);
if (!View) {
- warning("The file '" + SourceFile.str() + "' isn't covered.");
+ warning("The file '" + SourceFile + "' isn't covered.");
return;
}
emitDictKey("files");
FileCoverageSummary Totals = FileCoverageSummary("Totals");
- std::vector<StringRef> SourceFiles = Coverage.getUniqueSourceFiles();
+ std::vector<std::string> SourceFiles;
+ for (StringRef SF : Coverage.getUniqueSourceFiles())
+ SourceFiles.emplace_back(SF);
auto FileReports =
CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles);
renderFiles(SourceFiles, FileReports);
}
/// \brief Render an array of all the source files, also pass back a Summary.
- void renderFiles(ArrayRef<StringRef> SourceFiles,
+ void renderFiles(ArrayRef<std::string> SourceFiles,
ArrayRef<FileCoverageSummary> FileReports) {
// Start List of Files.
emitArrayStart();
/// \brief Determine the length of the longest common prefix of the strings in
/// \p Strings.
-unsigned getLongestCommonPrefixLen(ArrayRef<StringRef> Strings) {
+unsigned getLongestCommonPrefixLen(ArrayRef<std::string> Strings) {
unsigned LCP = Strings[0].size();
for (unsigned I = 1, E = Strings.size(); LCP > 0 && I < E; ++I) {
auto Mismatch =
OS << "\n";
}
-void CoverageReport::renderFunctionReports(ArrayRef<StringRef> Files,
+void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
raw_ostream &OS) {
bool isFirst = true;
for (StringRef Filename : Files) {
std::vector<FileCoverageSummary>
CoverageReport::prepareFileReports(const coverage::CoverageMapping &Coverage,
FileCoverageSummary &Totals,
- ArrayRef<StringRef> Files) {
+ ArrayRef<std::string> Files) {
std::vector<FileCoverageSummary> FileReports;
unsigned LCP = 0;
if (Files.size() > 1)
}
void CoverageReport::renderFileReports(raw_ostream &OS) const {
- std::vector<StringRef> UniqueSourceFiles = Coverage.getUniqueSourceFiles();
+ std::vector<std::string> UniqueSourceFiles;
+ for (StringRef SF : Coverage.getUniqueSourceFiles())
+ UniqueSourceFiles.emplace_back(SF.str());
renderFileReports(OS, UniqueSourceFiles);
}
void CoverageReport::renderFileReports(raw_ostream &OS,
- ArrayRef<StringRef> Files) const {
+ ArrayRef<std::string> Files) const {
FileCoverageSummary Totals("TOTAL");
auto FileReports = prepareFileReports(Coverage, Totals, Files);
const coverage::CoverageMapping &Coverage)
: Options(Options), Coverage(Coverage) {}
- void renderFunctionReports(ArrayRef<StringRef> Files, raw_ostream &OS);
+ void renderFunctionReports(ArrayRef<std::string> Files, raw_ostream &OS);
/// Prepare file reports for the files specified in \p Files.
static std::vector<FileCoverageSummary>
prepareFileReports(const coverage::CoverageMapping &Coverage,
- FileCoverageSummary &Totals, ArrayRef<StringRef> Files);
+ FileCoverageSummary &Totals, ArrayRef<std::string> Files);
/// Render file reports for every unique file in the coverage mapping.
void renderFileReports(raw_ostream &OS) const;
/// Render file reports for the files specified in \p Files.
- void renderFileReports(raw_ostream &OS, ArrayRef<StringRef> Files) const;
+ void renderFileReports(raw_ostream &OS, ArrayRef<std::string> Files) const;
};
} // end namespace llvm
virtual void closeViewFile(OwnedStream OS) = 0;
/// \brief Create an index which lists reports for the given source files.
- virtual Error createIndexFile(ArrayRef<StringRef> SourceFiles,
+ virtual Error createIndexFile(ArrayRef<std::string> SourceFiles,
const coverage::CoverageMapping &Coverage) = 0;
/// @}
}
Error CoveragePrinterHTML::createIndexFile(
- ArrayRef<StringRef> SourceFiles,
+ ArrayRef<std::string> SourceFiles,
const coverage::CoverageMapping &Coverage) {
// Emit the default stylesheet.
auto CSSOrErr = createOutputStream("style", "css", /*InToplevel=*/true);
void closeViewFile(OwnedStream OS) override;
- Error createIndexFile(ArrayRef<StringRef> SourceFiles,
+ Error createIndexFile(ArrayRef<std::string> SourceFiles,
const coverage::CoverageMapping &Coverage) override;
CoveragePrinterHTML(const CoverageViewOptions &Opts)
}
Error CoveragePrinterText::createIndexFile(
- ArrayRef<StringRef> SourceFiles,
+ ArrayRef<std::string> SourceFiles,
const coverage::CoverageMapping &Coverage) {
auto OSOrErr = createOutputStream("index", "txt", /*InToplevel=*/true);
if (Error E = OSOrErr.takeError())
raw_ostream &OSRef = *OS.get();
CoverageReport Report(Opts, Coverage);
- Report.renderFileReports(OSRef);
+ Report.renderFileReports(OSRef, SourceFiles);
Opts.colored_ostream(OSRef, raw_ostream::CYAN) << "\n"
<< Opts.getLLVMVersionString();
void closeViewFile(OwnedStream OS) override;
- Error createIndexFile(ArrayRef<StringRef> SourceFiles,
+ Error createIndexFile(ArrayRef<std::string> SourceFiles,
const coverage::CoverageMapping &Coverage) override;
CoveragePrinterText(const CoverageViewOptions &Opts)