[llvm] r263308 - [sancov] using md5 for anchors in attempt to reduce file size.
Mike Aizatsky via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 11 15:28:29 PST 2016
Author: aizatsky
Date: Fri Mar 11 17:28:28 2016
New Revision: 263308
URL: http://llvm.org/viewvc/llvm-project?rev=263308&view=rev
Log:
[sancov] using md5 for anchors in attempt to reduce file size.
Differential Revision: http://reviews.llvm.org/D18102
Modified:
llvm/trunk/test/tools/sancov/html-report.test
llvm/trunk/tools/sancov/sancov.cc
Modified: llvm/trunk/test/tools/sancov/html-report.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/sancov/html-report.test?rev=263308&r1=263307&r2=263308&view=diff
==============================================================================
--- llvm/trunk/test/tools/sancov/html-report.test (original)
+++ llvm/trunk/test/tools/sancov/html-report.test Fri Mar 11 17:28:28 2016
@@ -2,5 +2,5 @@ REQUIRES: x86_64-linux
RUN: sancov -html-report %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.0.sancov | FileCheck %s
// It's very difficult to test html report. Do basic smoke check.
-CHECK: {{<a name=".*/Inputs/test.cpp">}}
+CHECK: {{.*/Inputs/test.cpp}}
Modified: llvm/trunk/tools/sancov/sancov.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/sancov.cc?rev=263308&r1=263307&r2=263308&view=diff
==============================================================================
--- llvm/trunk/tools/sancov/sancov.cc (original)
+++ llvm/trunk/tools/sancov/sancov.cc Fri Mar 11 17:28:28 2016
@@ -33,6 +33,7 @@
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/MD5.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
@@ -487,6 +488,17 @@ static std::string escapeHtml(const std:
return Result;
}
+static std::string anchorName(std::string Anchor) {
+ llvm::MD5 Hasher;
+ llvm::MD5::MD5Result Hash;
+ Hasher.update(Anchor);
+ Hasher.final(Hash);
+
+ SmallString<32> HexString;
+ llvm::MD5::stringifyResult(Hash, HexString);
+ return HexString.str().str();
+}
+
static ErrorOr<bool> isCoverageFile(std::string FileName) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
MemoryBuffer::getFile(FileName);
@@ -826,7 +838,7 @@ public:
}
size_t CovPct = FC.second == 0 ? 100 : 100 * FC.first / FC.second;
- OS << "<tr><td><a href=\"#" << escapeHtml(FileName) << "\">"
+ OS << "<tr><td><a href=\"#" << anchorName(FileName) << "\">"
<< stripPathPrefix(FileName) << "</a></td>"
<< "<td>" << CovPct << "%</td>"
<< "<td>" << FC.first << " (" << FC.second << ")"
@@ -855,7 +867,7 @@ public:
std::pair<size_t, size_t> FC = FileFnCoverage[FileName];
if (FC.first == 0)
continue;
- OS << "<a name=\"" << escapeHtml(FileName) << "\"></a>\n";
+ OS << "<a name=\"" << anchorName(FileName) << "\"></a>\n";
OS << "<h2>" << stripPathPrefix(FileName) << "</h2>\n";
auto NotCoveredFns = NotCoveredFnMap.find(FileName);
@@ -865,7 +877,7 @@ public:
for (auto FileFn : NotCoveredFns->second) {
OS << "<tr><td>";
OS << "<a href=\"#"
- << escapeHtml(FileName + "::" + FileFn.FunctionName) << "\">";
+ << anchorName(FileName + "::" + FileFn.FunctionName) << "\">";
OS << escapeHtml(FileFn.FunctionName) << "</a>";
OS << "</td></tr>\n";
}
@@ -891,7 +903,7 @@ public:
auto It = NotCoveredFnByLoc.find(Loc);
if (It != NotCoveredFnByLoc.end()) {
for (std::string Fn : It->second) {
- OS << "<a name=\"" << escapeHtml(FileName + "::" + Fn)
+ OS << "<a name=\"" << anchorName(FileName + "::" + Fn)
<< "\"></a>";
};
}
@@ -1040,7 +1052,7 @@ public:
// Modules TOC.
if (Coverage.size() > 1) {
for (const auto &CovData : Coverage) {
- OS << "<li><a href=\"#module_" << escapeHtml(CovData->object_file())
+ OS << "<li><a href=\"#module_" << anchorName(CovData->object_file())
<< "\">" << llvm::sys::path::filename(CovData->object_file())
<< "</a></li>\n";
}
@@ -1051,7 +1063,7 @@ public:
OS << "<h2>" << llvm::sys::path::filename(CovData->object_file())
<< "</h2>\n";
}
- OS << "<a name=\"module_" << escapeHtml(CovData->object_file())
+ OS << "<a name=\"module_" << anchorName(CovData->object_file())
<< "\"></a>\n";
CovData->printReport(OS);
}
More information about the llvm-commits
mailing list