summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-pdbutil/DiffPrinter.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-07-10 19:16:49 +0000
committerZachary Turner <zturner@google.com>2017-07-10 19:16:49 +0000
commita9d944fd6fd19ac377b5ebea9272676642b7ceaa (patch)
tree74bbfc37da4607edae0da87f20762349031d8d76 /llvm/tools/llvm-pdbutil/DiffPrinter.cpp
parentfd7b1c0a56c0804583ddb43189041fd1ba27afe1 (diff)
downloadbcm5719-llvm-a9d944fd6fd19ac377b5ebea9272676642b7ceaa.tar.gz
bcm5719-llvm-a9d944fd6fd19ac377b5ebea9272676642b7ceaa.zip
Resubmit "Add pdb-diff test."
This was originally reverted because of two issues. 1) Printing ANSI color escape codes even when outputting to a file 2) Module name comparisons were failing when comparing a PDB generated on one machine to a PDB generated on another machine. I attempted to fix #2 by adding command line options which let you specify prefixes to strip from the beginning of embedded paths, which effectively lets us specify a path to "base" each PDB from and only compare the parts under the base. But this is tricky because PDB paths always use Windows path syntax, even when they are created on non-Windows hosts. A problem still existed when constructing the prefix to strip, where we were accidentally using a host-specific path separator instead of a Windows path separator. This resubmission fixes the issue on Linux (and I have verified that the test now passes on Linux). llvm-svn: 307571
Diffstat (limited to 'llvm/tools/llvm-pdbutil/DiffPrinter.cpp')
-rw-r--r--llvm/tools/llvm-pdbutil/DiffPrinter.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/llvm/tools/llvm-pdbutil/DiffPrinter.cpp b/llvm/tools/llvm-pdbutil/DiffPrinter.cpp
index 45641e2e4b0..dd61cc18259 100644
--- a/llvm/tools/llvm-pdbutil/DiffPrinter.cpp
+++ b/llvm/tools/llvm-pdbutil/DiffPrinter.cpp
@@ -6,18 +6,31 @@
using namespace llvm;
using namespace llvm::pdb;
-static void setColor(llvm::raw_ostream &OS, DiffResult Result) {
- switch (Result) {
- case DiffResult::IDENTICAL:
- OS.changeColor(raw_ostream::Colors::GREEN, false);
- break;
- case DiffResult::EQUIVALENT:
- OS.changeColor(raw_ostream::Colors::YELLOW, true);
- break;
- default:
- OS.changeColor(raw_ostream::Colors::RED, false);
- break;
+namespace {
+struct Colorize {
+ Colorize(raw_ostream &OS, DiffResult Result) : OS(OS) {
+ if (!OS.has_colors())
+ return;
+ switch (Result) {
+ case DiffResult::IDENTICAL:
+ OS.changeColor(raw_ostream::Colors::GREEN, false);
+ break;
+ case DiffResult::EQUIVALENT:
+ OS.changeColor(raw_ostream::Colors::YELLOW, true);
+ break;
+ default:
+ OS.changeColor(raw_ostream::Colors::RED, false);
+ break;
+ }
+ }
+
+ ~Colorize() {
+ if (OS.has_colors())
+ OS.resetColor();
}
+
+ raw_ostream &OS;
+};
}
DiffPrinter::DiffPrinter(uint32_t Indent, StringRef Header,
@@ -124,9 +137,8 @@ void DiffPrinter::printValue(StringRef Value, DiffResult C, AlignStyle Style,
std::string FormattedItem =
formatv("{0}", fmt_align(Value, Style, Width)).str();
if (C != DiffResult::UNSPECIFIED) {
- setColor(OS, C);
+ Colorize Color(OS, C);
OS << FormattedItem;
- OS.resetColor();
} else
OS << FormattedItem;
if (Style == AlignStyle::Right)
OpenPOWER on IntegriCloud