diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-02 19:06:11 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-02 19:06:11 +0000 |
commit | c1519b6bf6c32ee7ef28f818629a0f0351a61fd8 (patch) | |
tree | 6a844ecd86a92df947eaeb58312eb7ae9393cf8c /tools/clang/plugins | |
parent | 63b128f1831324934db6124d76bad1757aa89b9a (diff) | |
download | chromium_src-c1519b6bf6c32ee7ef28f818629a0f0351a61fd8.zip chromium_src-c1519b6bf6c32ee7ef28f818629a0f0351a61fd8.tar.gz chromium_src-c1519b6bf6c32ee7ef28f818629a0f0351a61fd8.tar.bz2 |
clang style plugin: Don't try to figure out src root.
Instead, just ignore all files that have a banned directory anywhere
in the path. This basically replaces patch set 2 with patch set 1 from
http://codereview.chromium.org/6577011 . The motivation is that
a) build/common.gypi doesn't exist when building in goma
b) there are several build/common.gypi files in the tree.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7824047
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99418 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/clang/plugins')
-rw-r--r-- | tools/clang/plugins/ChromeClassTester.cpp | 81 | ||||
-rw-r--r-- | tools/clang/plugins/ChromeClassTester.h | 3 |
2 files changed, 20 insertions, 64 deletions
diff --git a/tools/clang/plugins/ChromeClassTester.cpp b/tools/clang/plugins/ChromeClassTester.cpp index 303f31d..b92305d 100644 --- a/tools/clang/plugins/ChromeClassTester.cpp +++ b/tools/clang/plugins/ChromeClassTester.cpp @@ -31,76 +31,37 @@ bool ends_with(const std::string& one, const std::string& two) { ChromeClassTester::ChromeClassTester(CompilerInstance& instance) : instance_(instance), diagnostic_(instance.getDiagnostics()) { - FigureOutSrcRoot(); BuildBannedLists(); } -void ChromeClassTester::FigureOutSrcRoot() { - char c_cwd[MAXPATHLEN]; - if (getcwd(c_cwd, MAXPATHLEN) > 0) { - size_t pos = 1; - std::string cwd = c_cwd; - - // Add a trailing '/' because the search below requires it. - if (cwd[cwd.size() - 1] != '/') - cwd += '/'; - - // Search the directory tree downwards until we find a path that contains - // "build/common.gypi" and assume that that is our srcroot. - size_t next_slash = cwd.find('/', pos); - while (next_slash != std::string::npos) { - next_slash++; - std::string candidate = cwd.substr(0, next_slash); - - if (ends_with(candidate, "src/")) { - std::string common = candidate + "build/common.gypi"; - if (access(common.c_str(), F_OK) != -1) { - src_root_ = candidate; - break; - } - } - - pos = next_slash; - next_slash = cwd.find('/', pos); - } - } - - if (src_root_.empty()) { - unsigned id = diagnostic().getCustomDiagID( - Diagnostic::Error, - "WARNING: Can't figure out srcroot!\n"); - diagnostic().Report(id); - } -} - void ChromeClassTester::BuildBannedLists() { banned_namespaces_.push_back("std"); banned_namespaces_.push_back("__gnu_cxx"); - banned_directories_.push_back("third_party"); - banned_directories_.push_back("native_client"); - banned_directories_.push_back("breakpad"); - banned_directories_.push_back("courgette"); - banned_directories_.push_back("ppapi"); - banned_directories_.push_back("testing"); - banned_directories_.push_back("googleurl"); - banned_directories_.push_back("v8"); - banned_directories_.push_back("sdch"); + banned_directories_.push_back("third_party/"); + banned_directories_.push_back("native_client/"); + banned_directories_.push_back("breakpad/"); + banned_directories_.push_back("courgette/"); + banned_directories_.push_back("ppapi/"); + banned_directories_.push_back("usr/"); + banned_directories_.push_back("testing/"); + banned_directories_.push_back("googleurl/"); + banned_directories_.push_back("v8/"); + banned_directories_.push_back("sdch/"); // Don't check autogenerated headers. - banned_directories_.push_back("out"); - banned_directories_.push_back("llvm"); - banned_directories_.push_back("ninja"); - banned_directories_.push_back("xcodebuild"); - banned_directories_.push_back("clang"); + banned_directories_.push_back("out/"); + banned_directories_.push_back("llvm/"); + banned_directories_.push_back("ninja/"); + banned_directories_.push_back("xcodebuild/"); + banned_directories_.push_back("clang/"); // You are standing in a mazy of twisty dependencies, all resolved by // putting everything in the header. - banned_directories_.push_back("chrome/test/automation"); + banned_directories_.push_back("automation/"); // Don't check system headers. - banned_directories_.push_back("/usr"); - banned_directories_.push_back("/Developer"); + banned_directories_.push_back("/Developer/"); // Used in really low level threading code that probably shouldn't be out of // lined. @@ -265,17 +226,15 @@ bool ChromeClassTester::InBannedDirectory(SourceLocation loc) { char resolvedPath[MAXPATHLEN]; if (realpath(b.c_str(), resolvedPath)) { std::string resolved = resolvedPath; - if (starts_with(resolved, src_root_)) { - b = resolved.substr(src_root_.size()); - } } for (std::vector<std::string>::const_iterator it = banned_directories_.begin(); it != banned_directories_.end(); ++it) { - if (starts_with(b, *it)) { + // If we can find any of the banned path components in this path, then + // this file is rejected. + if (b.find(*it) != std::string::npos) return true; - } } } diff --git a/tools/clang/plugins/ChromeClassTester.h b/tools/clang/plugins/ChromeClassTester.h index f00bb6a..6552a2a 100644 --- a/tools/clang/plugins/ChromeClassTester.h +++ b/tools/clang/plugins/ChromeClassTester.h @@ -21,7 +21,6 @@ class ChromeClassTester : public clang::ASTConsumer { explicit ChromeClassTester(clang::CompilerInstance& instance); virtual ~ChromeClassTester(); - void FigureOutSrcRoot(); void BuildBannedLists(); // ASTConsumer: @@ -58,8 +57,6 @@ class ChromeClassTester : public clang::ASTConsumer { clang::CompilerInstance& instance_; clang::Diagnostic& diagnostic_; - std::string src_root_; - // List of banned namespaces. std::vector<std::string> banned_namespaces_; |