[llvm] 4e3c0bb - llvm-cov: Introduce `-show-created-time` to suppress timestamps (#120417)

via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 19 18:31:05 PST 2024


Author: NAKAMURA Takumi
Date: 2024-12-20T11:31:01+09:00
New Revision: 4e3c0bb7f7b3f4df702d787853d31c53d626fe4c

URL: https://github.com/llvm/llvm-project/commit/4e3c0bb7f7b3f4df702d787853d31c53d626fe4c
DIFF: https://github.com/llvm/llvm-project/commit/4e3c0bb7f7b3f4df702d787853d31c53d626fe4c.diff

LOG: 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.

Added: 
    

Modified: 
    llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test
    llvm/test/tools/llvm-cov/showProjectSummary.cpp
    llvm/tools/llvm-cov/CodeCoverage.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test b/llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test
index 5eb6b4e24d5365..91d22e0e213b8f 100644
--- a/llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test
+++ b/llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test
@@ -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>

diff  --git a/llvm/test/tools/llvm-cov/showProjectSummary.cpp b/llvm/test/tools/llvm-cov/showProjectSummary.cpp
index aa5e30e30d900e..c53e272cfdea27 100644
--- a/llvm/test/tools/llvm-cov/showProjectSummary.cpp
+++ b/llvm/test/tools/llvm-cov/showProjectSummary.cpp
@@ -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
@@ -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

diff  --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index d06fd86fe52afb..5db5c2e0235419 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -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"));
@@ -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)


        


More information about the llvm-commits mailing list