[llvm] r274173 - [llvm-cov] Use relative paths to file reports in -output-dir mode

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 29 14:55:47 PDT 2016


Author: vedantk
Date: Wed Jun 29 16:55:46 2016
New Revision: 274173

URL: http://llvm.org/viewvc/llvm-project?rev=274173&view=rev
Log:
[llvm-cov] Use relative paths to file reports in -output-dir mode

This makes it possible to e.g copy a report to another filesystem.

Modified:
    llvm/trunk/test/tools/llvm-cov/double_dots.c
    llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageView.h

Modified: llvm/trunk/test/tools/llvm-cov/double_dots.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/double_dots.c?rev=274173&r1=274172&r2=274173&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/double_dots.c (original)
+++ llvm/trunk/test/tools/llvm-cov/double_dots.c Wed Jun 29 16:55:46 2016
@@ -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

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp?rev=274173&r1=274172&r2=274173&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp Wed Jun 29 16:55:46 2016
@@ -28,10 +28,14 @@ void CoveragePrinter::StreamDestructor::
 }
 
 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(Stri
   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))

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.h?rev=274173&r1=274172&r2=274173&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.h Wed Jun 29 16:55:46 2016
@@ -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.




More information about the llvm-commits mailing list