Index: tools/clang/plugins/ChromeClassTester.cpp |
diff --git a/tools/clang/plugins/ChromeClassTester.cpp b/tools/clang/plugins/ChromeClassTester.cpp |
index 931da02f3ff54e352a1cbec4337433abb38e449f..6a4233a659a5e3fc4f8ad57da936be93097e85c7 100644 |
--- a/tools/clang/plugins/ChromeClassTester.cpp |
+++ b/tools/clang/plugins/ChromeClassTester.cpp |
@@ -18,6 +18,7 @@ |
#endif |
using namespace clang; |
+using chrome_checker::Options; |
namespace { |
@@ -30,8 +31,10 @@ bool ends_with(const std::string& one, const std::string& two) { |
} // namespace |
-ChromeClassTester::ChromeClassTester(CompilerInstance& instance) |
- : instance_(instance), |
+ChromeClassTester::ChromeClassTester(CompilerInstance& instance, |
+ const Options& options) |
+ : options_(options), |
+ instance_(instance), |
diagnostic_(instance.getDiagnostics()) { |
BuildBannedLists(); |
} |
@@ -95,16 +98,13 @@ void ChromeClassTester::emitWarning(SourceLocation loc, |
std::string err; |
err = "[chromium-style] "; |
err += raw_error; |
- // TODO(dcheng): Re-enable -Werror for these diagnostics on Windows once all |
- // the pre-existing warnings are cleaned up. https://crbug.com/467287 |
- DiagnosticIDs::Level level = |
-#if !defined(LLVM_ON_WIN32) |
- diagnostic().getWarningsAsErrors() ? |
- DiagnosticIDs::Error : |
-#endif |
- DiagnosticIDs::Warning; |
+ |
+ DiagnosticIDs::Level level = getErrorLevel() == DiagnosticsEngine::Error |
+ ? DiagnosticIDs::Error : DiagnosticIDs::Warning; |
+ |
unsigned id = diagnostic().getDiagnosticIDs()->getCustomDiagID(level, err); |
DiagnosticBuilder builder = diagnostic().Report(full, id); |
+ |
} |
bool ChromeClassTester::InBannedDirectory(SourceLocation loc) { |
@@ -130,9 +130,7 @@ bool ChromeClassTester::InBannedDirectory(SourceLocation loc) { |
} |
#if defined(LLVM_ON_UNIX) |
- // We need to munge the paths so that they are relative to the repository |
- // srcroot. We first resolve the symlinktastic relative path and then |
- // remove our known srcroot from it if needed. |
+ // Resolve the symlinktastic relative path and make it absolute. |
char resolvedPath[MAXPATHLEN]; |
if (realpath(filename.c_str(), resolvedPath)) { |
filename = resolvedPath; |
@@ -141,6 +139,15 @@ bool ChromeClassTester::InBannedDirectory(SourceLocation loc) { |
#if defined(LLVM_ON_WIN32) |
std::replace(filename.begin(), filename.end(), '\\', '/'); |
+ |
+ // On Posix, realpath() has made the path absolute. On Windows, this isn't |
+ // necessarily true, so prepend a '/' to the path to make sure the |
+ // banned_directories_ loop below works correctly. |
+ // This turns e.g. "gen/dir/file.cc" to "/gen/dir/file.cc" which lets the |
+ // "/gen/" banned_dir work. |
+ // This seems simpler than converting to utf16, calling GetFullPathNameW(), |
+ // and converting back to utf8. |
+ filename.insert(filename.begin(), '/'); |
#endif |
for (const std::string& banned_dir : banned_directories_) { |
@@ -304,3 +311,11 @@ bool ChromeClassTester::GetFilename(SourceLocation loc, |
*filename = ploc.getFilename(); |
return true; |
} |
+ |
+DiagnosticsEngine::Level ChromeClassTester::getErrorLevel() { |
+ if (options_.warn_only) |
+ return DiagnosticsEngine::Warning; |
+ |
+ return diagnostic().getWarningsAsErrors() ? DiagnosticsEngine::Error |
+ : DiagnosticsEngine::Warning; |
+} |