Skip to content

Commit 4e3c0bb

Browse files
authored
llvm-cov: Introduce -show-created-time to suppress timestamps (#120417)
This shouldn't affect anything since `-show-created-time=true` by default. Timestamps sometimes prevent reproducible build.
1 parent 7666c40 commit 4e3c0bb

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@ HTML-HEADER: <td><pre>Line</pre></td>
1313
HTML-HEADER: <td><pre>Count</pre></td>
1414
HTML-HEADER: <td><pre>Source</pre></td>
1515
HTML-FOOTER: <h5>Generated by llvm-cov{{.*}}</h5>
16+
17+
HTMF-TITLE: <h1>Test Suite</h1>
18+
HTMF: <h2>Coverage Report</h2>
19+
HTMF-NOT: <h4>Created:
20+
HTMF-FILE: <pre>{{.*}}showProjectSummary.cpp</pre>
21+
HTMF-NOT: <h4>Created:
22+
HTMF-FUNCTION: <pre>main</pre>
23+
HTMF-NOT: <h4>Created:
24+
HTMF-HEADER: <td><pre>Line</pre></td>
25+
HTMF-HEADER: <td><pre>Count</pre></td>
26+
HTMF-HEADER: <td><pre>Source</pre></td>
27+
HTMF-NOT: <h4>Created:
28+
HTMF-FOOTER: <h5>Generated by llvm-cov{{.*}}</h5>

llvm/test/tools/llvm-cov/showProjectSummary.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ int main(int argc, char ** argv) {
1111
return x;
1212
}
1313

14+
// RUN: rm -rf %t.dir
15+
1416
// Test console output.
1517
// 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
1618
// 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
@@ -27,3 +29,12 @@ int main(int argc, char ** argv) {
2729
// RUN: FileCheck -check-prefixes=HTML-TITLE,HTML,HTML-FOOTER -input-file %t.dir/index.html %S/Inputs/showProjectSummary.test
2830
// 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
2931
// RUN: FileCheck -check-prefixes=HTML-TITLE,HTML,HTML-FOOTER -input-file %t.filtered.dir/index.html %S/Inputs/showProjectSummary.test
32+
33+
// Test html output. (w/o ctime)
34+
// 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
35+
// RUN: FileCheck -check-prefixes=HTMF,HTMF-FILE,HTMF-HEADER -input-file %t.dir/coverage/tmp/showProjectSummary.cpp.html %S/Inputs/showProjectSummary.test
36+
// 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
37+
// RUN: FileCheck -check-prefixes=HTMF-TITLE,HTMF,HTMF-FILE,HTMF-HEADER -input-file %t.dir/coverage/tmp/showProjectSummary.cpp.html %S/Inputs/showProjectSummary.test
38+
// RUN: FileCheck -check-prefixes=HTMF-TITLE,HTMF,HTMF-FOOTER -input-file %t.dir/index.html %S/Inputs/showProjectSummary.test
39+
// 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
40+
// RUN: FileCheck -check-prefixes=HTMF-TITLE,HTMF,HTMF-FOOTER -input-file %t.filtered.dir/index.html %S/Inputs/showProjectSummary.test

llvm/tools/llvm-cov/CodeCoverage.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,10 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
10131013
cl::desc("Show directory coverage"),
10141014
cl::cat(ViewCategory));
10151015

1016+
cl::opt<bool> ShowCreatedTime("show-created-time", cl::Optional,
1017+
cl::desc("Show created time for each page."),
1018+
cl::init(true), cl::cat(ViewCategory));
1019+
10161020
cl::opt<std::string> ShowOutputDirectory(
10171021
"output-dir", cl::init(""),
10181022
cl::desc("Directory in which coverage information is written out"));
@@ -1112,12 +1116,15 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
11121116
return 1;
11131117
}
11141118

1115-
auto ModifiedTime = Status.getLastModificationTime();
1116-
std::string ModifiedTimeStr = to_string(ModifiedTime);
1117-
size_t found = ModifiedTimeStr.rfind(':');
1118-
ViewOpts.CreatedTimeStr = (found != std::string::npos)
1119-
? "Created: " + ModifiedTimeStr.substr(0, found)
1120-
: "Created: " + ModifiedTimeStr;
1119+
if (ShowCreatedTime) {
1120+
auto ModifiedTime = Status.getLastModificationTime();
1121+
std::string ModifiedTimeStr = to_string(ModifiedTime);
1122+
size_t found = ModifiedTimeStr.rfind(':');
1123+
ViewOpts.CreatedTimeStr =
1124+
(found != std::string::npos)
1125+
? "Created: " + ModifiedTimeStr.substr(0, found)
1126+
: "Created: " + ModifiedTimeStr;
1127+
}
11211128

11221129
auto Coverage = load();
11231130
if (!Coverage)

0 commit comments

Comments
 (0)