summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/test/tools/llvm-cov/double_dots.c6
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.cpp10
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.h6
3 files changed, 17 insertions, 5 deletions
diff --git a/llvm/test/tools/llvm-cov/double_dots.c b/llvm/test/tools/llvm-cov/double_dots.c
index a9c47a4aac8..47224bf9ade 100644
--- a/llvm/test/tools/llvm-cov/double_dots.c
+++ b/llvm/test/tools/llvm-cov/double_dots.c
@@ -9,3 +9,9 @@
// CHECK-NOT: coverage{{.*}}dots{{.*}}..{{.*}}dots
int main() {}
+
+// Re-purpose this file to test that we use relative paths when creating
+// report indices:
+
+// RUN: FileCheck -check-prefix=REL-INDEX -input-file %t.dir/index.txt %s
+// REL-INDEX-NOT: %t.dir
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp
index a4e9c43d066..08eb545a29c 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp
@@ -28,10 +28,14 @@ void CoveragePrinter::StreamDestructor::operator()(raw_ostream *OS) const {
}
std::string CoveragePrinter::getOutputPath(StringRef Path, StringRef Extension,
- bool InToplevel) {
+ bool InToplevel, bool Relative) {
assert(Extension.size() && "The file extension may not be empty");
- SmallString<256> FullPath(Opts.ShowOutputDirectory);
+ SmallString<256> FullPath;
+
+ if (!Relative)
+ FullPath.append(Opts.ShowOutputDirectory);
+
if (!InToplevel)
sys::path::append(FullPath, getCoverageDir());
@@ -51,7 +55,7 @@ CoveragePrinter::createOutputStream(StringRef Path, StringRef Extension,
if (!Opts.hasOutputDirectory())
return OwnedStream(&outs());
- std::string FullPath = getOutputPath(Path, Extension, InToplevel);
+ std::string FullPath = getOutputPath(Path, Extension, InToplevel, false);
auto ParentDir = sys::path::parent_path(FullPath);
if (auto E = sys::fs::create_directories(ParentDir))
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.h b/llvm/tools/llvm-cov/SourceCoverageView.h
index 98e68b6772d..feef959f86b 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.h
+++ b/llvm/tools/llvm-cov/SourceCoverageView.h
@@ -111,9 +111,11 @@ public:
protected:
CoveragePrinter(const CoverageViewOptions &Opts) : Opts(Opts) {}
- /// \brief Return `OutputDir/ToplevelDir/Path.Extension`.
+ /// \brief Return `OutputDir/ToplevelDir/Path.Extension`. If \p InToplevel is
+ /// false, skip the ToplevelDir component. If \p Relative is false, skip the
+ /// OutputDir component.
std::string getOutputPath(StringRef Path, StringRef Extension,
- bool InToplevel);
+ bool InToplevel, bool Relative = true);
/// \brief If directory output is enabled, create a file in that directory
/// at the path given by getOutputPath(). Otherwise, return stdout.
OpenPOWER on IntegriCloud