Skip to content

Commit d378d97

Browse files
committed
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274173 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent eb2c1eb commit d378d97

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

test/tools/llvm-cov/double_dots.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
// CHECK-NOT: coverage{{.*}}dots{{.*}}..{{.*}}dots
1010

1111
int main() {}
12+
13+
// Re-purpose this file to test that we use relative paths when creating
14+
// report indices:
15+
16+
// RUN: FileCheck -check-prefix=REL-INDEX -input-file %t.dir/index.txt %s
17+
// REL-INDEX-NOT: %t.dir

tools/llvm-cov/SourceCoverageView.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ void CoveragePrinter::StreamDestructor::operator()(raw_ostream *OS) const {
2828
}
2929

3030
std::string CoveragePrinter::getOutputPath(StringRef Path, StringRef Extension,
31-
bool InToplevel) {
31+
bool InToplevel, bool Relative) {
3232
assert(Extension.size() && "The file extension may not be empty");
3333

34-
SmallString<256> FullPath(Opts.ShowOutputDirectory);
34+
SmallString<256> FullPath;
35+
36+
if (!Relative)
37+
FullPath.append(Opts.ShowOutputDirectory);
38+
3539
if (!InToplevel)
3640
sys::path::append(FullPath, getCoverageDir());
3741

@@ -51,7 +55,7 @@ CoveragePrinter::createOutputStream(StringRef Path, StringRef Extension,
5155
if (!Opts.hasOutputDirectory())
5256
return OwnedStream(&outs());
5357

54-
std::string FullPath = getOutputPath(Path, Extension, InToplevel);
58+
std::string FullPath = getOutputPath(Path, Extension, InToplevel, false);
5559

5660
auto ParentDir = sys::path::parent_path(FullPath);
5761
if (auto E = sys::fs::create_directories(ParentDir))

tools/llvm-cov/SourceCoverageView.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ class CoveragePrinter {
111111
protected:
112112
CoveragePrinter(const CoverageViewOptions &Opts) : Opts(Opts) {}
113113

114-
/// \brief Return `OutputDir/ToplevelDir/Path.Extension`.
114+
/// \brief Return `OutputDir/ToplevelDir/Path.Extension`. If \p InToplevel is
115+
/// false, skip the ToplevelDir component. If \p Relative is false, skip the
116+
/// OutputDir component.
115117
std::string getOutputPath(StringRef Path, StringRef Extension,
116-
bool InToplevel);
118+
bool InToplevel, bool Relative = true);
117119

118120
/// \brief If directory output is enabled, create a file in that directory
119121
/// at the path given by getOutputPath(). Otherwise, return stdout.

0 commit comments

Comments
 (0)