mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-24 12:19:53 +00:00
[LLVM-COV]Replace tabs to the space indentations in the HTML coverage report.
When using orbis-llvm-cov.exe to generate the HTML report, the HTML report can look quite different to the source file if it includes tabs.The default tab size is 2 spaces instead of 8 spaces. A command line switch is be added to set the tab size. Differential Revision: https://reviews.llvm.org/D23087 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277715 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1d5ec2171f
commit
65787e2459
BIN
test/tools/llvm-cov/Inputs/showTabsHTML.covmapping
Normal file
BIN
test/tools/llvm-cov/Inputs/showTabsHTML.covmapping
Normal file
Binary file not shown.
8
test/tools/llvm-cov/Inputs/showTabsHTML.proftext
Normal file
8
test/tools/llvm-cov/Inputs/showTabsHTML.proftext
Normal file
@ -0,0 +1,8 @@
|
||||
main
|
||||
# Func Hash:
|
||||
0
|
||||
# Num Counters:
|
||||
1
|
||||
# Counter Values:
|
||||
1
|
||||
|
16
test/tools/llvm-cov/showTabsHTML.cpp
Normal file
16
test/tools/llvm-cov/showTabsHTML.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/showTabsHTML.proftext
|
||||
// RUN: llvm-cov show %S/Inputs/showTabsHTML.covmapping -format html -instr-profile %t.profdata -filename-equivalence %s | FileCheck -check-prefix=CHECK %s
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
(void) "This tab starts at column 0"; // CHECK: (void) "This tab starts at column 0";
|
||||
(void) " This tab starts at column 10"; // CHECK: (void) " This tab starts at column 10";
|
||||
(void) "This tab starts at column 15"; // CHECK: (void) "This tab starts at column 15";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// RUN: llvm-cov show %S/Inputs/showTabsHTML.covmapping -format html -tab-size=3 -instr-profile %t.profdata -filename-equivalence %s | FileCheck -check-prefix=CHECK-TABSIZE %s
|
||||
|
||||
// CHECK-TABSIZE: (void) "This tab starts at column 0";
|
||||
// CHECK-TABSIZE: (void) " This tab starts at column 10";
|
||||
// CHECK-TABSIZE: (void) "This tab starts at column 15";
|
@ -584,6 +584,10 @@ int CodeCoverageTool::show(int argc, const char **argv,
|
||||
cl::alias ShowOutputDirectoryA("o", cl::desc("Alias for --output-dir"),
|
||||
cl::aliasopt(ShowOutputDirectory));
|
||||
|
||||
cl::opt<uint32_t> TabSize(
|
||||
"tab-size", cl::Hidden, cl::init(2),
|
||||
cl::desc("Set tab size for the HTML coverage report (default = 2)"));
|
||||
|
||||
auto Err = commandLineParser(argc, argv);
|
||||
if (Err)
|
||||
return Err;
|
||||
@ -596,6 +600,7 @@ int CodeCoverageTool::show(int argc, const char **argv,
|
||||
ViewOpts.ShowExpandedRegions = ShowExpansions;
|
||||
ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
|
||||
ViewOpts.ShowOutputDirectory = ShowOutputDirectory;
|
||||
ViewOpts.TabSize = TabSize;
|
||||
|
||||
if (ViewOpts.hasOutputDirectory()) {
|
||||
if (auto E = sys::fs::create_directories(ViewOpts.ShowOutputDirectory)) {
|
||||
|
@ -34,6 +34,7 @@ struct CoverageViewOptions {
|
||||
OutputFormat Format;
|
||||
std::string ShowOutputDirectory;
|
||||
std::vector<std::string> DemanglerOpts;
|
||||
uint32_t TabSize;
|
||||
|
||||
/// \brief Change the output's stream color if the colors are enabled.
|
||||
ColoredRawOstream colored_ostream(raw_ostream &OS,
|
||||
|
@ -22,9 +22,11 @@ using namespace llvm;
|
||||
namespace {
|
||||
|
||||
// Return a string with the special characters in \p Str escaped.
|
||||
std::string escape(StringRef Str) {
|
||||
std::string escape(StringRef Str, const CoverageViewOptions &Opts) {
|
||||
std::string Result;
|
||||
unsigned ColNum = 0; // Record the column number.
|
||||
for (char C : Str) {
|
||||
++ColNum;
|
||||
if (C == '&')
|
||||
Result += "&";
|
||||
else if (C == '<')
|
||||
@ -33,7 +35,16 @@ std::string escape(StringRef Str) {
|
||||
Result += ">";
|
||||
else if (C == '\"')
|
||||
Result += """;
|
||||
else
|
||||
else if (C == '\n' || C == '\r') {
|
||||
Result += C;
|
||||
ColNum = 0;
|
||||
} else if (C == '\t') {
|
||||
// Replace '\t' with TabSize spaces.
|
||||
unsigned NumSpaces = Opts.TabSize - (--ColNum % Opts.TabSize);
|
||||
for (unsigned I = 0; I < NumSpaces; ++I)
|
||||
Result += " ";
|
||||
ColNum += NumSpaces;
|
||||
} else
|
||||
Result += C;
|
||||
}
|
||||
return Result;
|
||||
@ -195,7 +206,8 @@ std::string getPathToStyle(StringRef ViewPath) {
|
||||
return PathToStyle + "style.css";
|
||||
}
|
||||
|
||||
void emitPrelude(raw_ostream &OS, const std::string &PathToStyle = "") {
|
||||
void emitPrelude(raw_ostream &OS, const CoverageViewOptions &Opts,
|
||||
const std::string &PathToStyle = "") {
|
||||
OS << "<!doctype html>"
|
||||
"<html>"
|
||||
<< BeginHeader;
|
||||
@ -204,8 +216,8 @@ void emitPrelude(raw_ostream &OS, const std::string &PathToStyle = "") {
|
||||
if (PathToStyle.empty())
|
||||
OS << "<style>" << CSSForCoverage << "</style>";
|
||||
else
|
||||
OS << "<link rel='stylesheet' type='text/css' href='" << escape(PathToStyle)
|
||||
<< "'>";
|
||||
OS << "<link rel='stylesheet' type='text/css' href='"
|
||||
<< escape(PathToStyle, Opts) << "'>";
|
||||
|
||||
OS << EndHeader << "<body>" << BeginCenteredDiv;
|
||||
}
|
||||
@ -226,10 +238,10 @@ CoveragePrinterHTML::createViewFile(StringRef Path, bool InToplevel) {
|
||||
OwnedStream OS = std::move(OSOrErr.get());
|
||||
|
||||
if (!Opts.hasOutputDirectory()) {
|
||||
emitPrelude(*OS.get());
|
||||
emitPrelude(*OS.get(), Opts);
|
||||
} else {
|
||||
std::string ViewPath = getOutputPath(Path, "html", InToplevel);
|
||||
emitPrelude(*OS.get(), getPathToStyle(ViewPath));
|
||||
emitPrelude(*OS.get(), Opts, getPathToStyle(ViewPath));
|
||||
}
|
||||
|
||||
return std::move(OS);
|
||||
@ -248,13 +260,13 @@ Error CoveragePrinterHTML::createIndexFile(ArrayRef<StringRef> SourceFiles) {
|
||||
|
||||
// Emit a table containing links to reports for each file in the covmapping.
|
||||
assert(Opts.hasOutputDirectory() && "No output directory for index file");
|
||||
emitPrelude(OSRef, getPathToStyle(""));
|
||||
emitPrelude(OSRef, Opts, getPathToStyle(""));
|
||||
OSRef << BeginSourceNameDiv << "Index" << EndSourceNameDiv;
|
||||
OSRef << BeginTable;
|
||||
for (StringRef SF : SourceFiles) {
|
||||
std::string LinkText = escape(sys::path::relative_path(SF));
|
||||
std::string LinkText = escape(sys::path::relative_path(SF), Opts);
|
||||
std::string LinkTarget =
|
||||
escape(getOutputPath(SF, "html", /*InToplevel=*/false));
|
||||
escape(getOutputPath(SF, "html", /*InToplevel=*/false), Opts);
|
||||
OSRef << tag("tr", tag("td", tag("pre", a(LinkTarget, LinkText), "code")));
|
||||
}
|
||||
OSRef << EndTable;
|
||||
@ -280,7 +292,7 @@ void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS) {
|
||||
}
|
||||
|
||||
void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS) {
|
||||
OS << BeginSourceNameDiv << tag("pre", escape(getSourceName()))
|
||||
OS << BeginSourceNameDiv << tag("pre", escape(getSourceName(), getOptions()))
|
||||
<< EndSourceNameDiv;
|
||||
}
|
||||
|
||||
@ -336,7 +348,7 @@ void SourceCoverageViewHTML::renderLine(
|
||||
// 2. Escape all of the snippets.
|
||||
|
||||
for (unsigned I = 0, E = Snippets.size(); I < E; ++I)
|
||||
Snippets[I] = escape(Snippets[I]);
|
||||
Snippets[I] = escape(Snippets[I], getOptions());
|
||||
|
||||
// 3. Use \p WrappedSegment to set the highlight for snippet 0. Use segment
|
||||
// 1 to set the highlight for snippet 2, segment 2 to set the highlight for
|
||||
|
Loading…
Reference in New Issue
Block a user