Skip to content

Commit

Permalink
llvm-cov: Introduce -show-created-time to suppress timestamps (#120…
Browse files Browse the repository at this point in the history
…417)

This shouldn't affect anything since `-show-created-time=true` by
default.

Timestamps sometimes prevent reproducible build.
  • Loading branch information
chapuni authored Dec 20, 2024
1 parent 7666c40 commit 4e3c0bb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
13 changes: 13 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ HTML-HEADER: <td><pre>Line</pre></td>
HTML-HEADER: <td><pre>Count</pre></td>
HTML-HEADER: <td><pre>Source</pre></td>
HTML-FOOTER: <h5>Generated by llvm-cov{{.*}}</h5>

HTMF-TITLE: <h1>Test Suite</h1>
HTMF: <h2>Coverage Report</h2>
HTMF-NOT: <h4>Created:
HTMF-FILE: <pre>{{.*}}showProjectSummary.cpp</pre>
HTMF-NOT: <h4>Created:
HTMF-FUNCTION: <pre>main</pre>
HTMF-NOT: <h4>Created:
HTMF-HEADER: <td><pre>Line</pre></td>
HTMF-HEADER: <td><pre>Count</pre></td>
HTMF-HEADER: <td><pre>Source</pre></td>
HTMF-NOT: <h4>Created:
HTMF-FOOTER: <h5>Generated by llvm-cov{{.*}}</h5>
11 changes: 11 additions & 0 deletions llvm/test/tools/llvm-cov/showProjectSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ int main(int argc, char ** argv) {
return x;
}

// RUN: rm -rf %t.dir

// Test console output.
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck -check-prefixes=TEXT %S/Inputs/showProjectSummary.test
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -instr-profile %t.profdata -path-equivalence=/tmp,%S -name=main %s | FileCheck -check-prefixes=TEXT %S/Inputs/showProjectSummary.test
Expand All @@ -27,3 +29,12 @@ int main(int argc, char ** argv) {
// RUN: FileCheck -check-prefixes=HTML-TITLE,HTML,HTML-FOOTER -input-file %t.dir/index.html %S/Inputs/showProjectSummary.test
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -format=html -o %t.filtered.dir -instr-profile %t.profdata -project-title "Test Suite" -path-equivalence=/tmp,%S -name=main %s
// RUN: FileCheck -check-prefixes=HTML-TITLE,HTML,HTML-FOOTER -input-file %t.filtered.dir/index.html %S/Inputs/showProjectSummary.test

// Test html output. (w/o ctime)
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -show-created-time=false -format=html -o %t.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S %s
// RUN: FileCheck -check-prefixes=HTMF,HTMF-FILE,HTMF-HEADER -input-file %t.dir/coverage/tmp/showProjectSummary.cpp.html %S/Inputs/showProjectSummary.test
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -show-created-time=false -format=html -o %t.dir -instr-profile %t.profdata -project-title "Test Suite" -path-equivalence=/tmp,%S %s
// RUN: FileCheck -check-prefixes=HTMF-TITLE,HTMF,HTMF-FILE,HTMF-HEADER -input-file %t.dir/coverage/tmp/showProjectSummary.cpp.html %S/Inputs/showProjectSummary.test
// RUN: FileCheck -check-prefixes=HTMF-TITLE,HTMF,HTMF-FOOTER -input-file %t.dir/index.html %S/Inputs/showProjectSummary.test
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -show-created-time=false -format=html -o %t.filtered.dir -instr-profile %t.profdata -project-title "Test Suite" -path-equivalence=/tmp,%S -name=main %s
// RUN: FileCheck -check-prefixes=HTMF-TITLE,HTMF,HTMF-FOOTER -input-file %t.filtered.dir/index.html %S/Inputs/showProjectSummary.test
19 changes: 13 additions & 6 deletions llvm/tools/llvm-cov/CodeCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,10 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
cl::desc("Show directory coverage"),
cl::cat(ViewCategory));

cl::opt<bool> ShowCreatedTime("show-created-time", cl::Optional,
cl::desc("Show created time for each page."),
cl::init(true), cl::cat(ViewCategory));

cl::opt<std::string> ShowOutputDirectory(
"output-dir", cl::init(""),
cl::desc("Directory in which coverage information is written out"));
Expand Down Expand Up @@ -1112,12 +1116,15 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
return 1;
}

auto ModifiedTime = Status.getLastModificationTime();
std::string ModifiedTimeStr = to_string(ModifiedTime);
size_t found = ModifiedTimeStr.rfind(':');
ViewOpts.CreatedTimeStr = (found != std::string::npos)
? "Created: " + ModifiedTimeStr.substr(0, found)
: "Created: " + ModifiedTimeStr;
if (ShowCreatedTime) {
auto ModifiedTime = Status.getLastModificationTime();
std::string ModifiedTimeStr = to_string(ModifiedTime);
size_t found = ModifiedTimeStr.rfind(':');
ViewOpts.CreatedTimeStr =
(found != std::string::npos)
? "Created: " + ModifiedTimeStr.substr(0, found)
: "Created: " + ModifiedTimeStr;
}

auto Coverage = load();
if (!Coverage)
Expand Down

0 comments on commit 4e3c0bb

Please sign in to comment.