Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Side by Side Diff: tools/clang/plugins/ChromeClassTester.cpp

Issue 6577011: Make the clang plugin look for path components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // A general interface for filtering and only acting on classes in Chromium C++ 5 // A general interface for filtering and only acting on classes in Chromium C++
6 // code. 6 // code.
7 7
8 #include "ChromeClassTester.h" 8 #include "ChromeClassTester.h"
9 9
10 #include <sys/param.h>
11
10 using namespace clang; 12 using namespace clang;
11 13
12 namespace { 14 namespace {
13 15
14 bool starts_with(const std::string& one, const std::string& two) { 16 bool starts_with(const std::string& one, const std::string& two) {
15 return one.substr(0, two.size()) == two; 17 return one.substr(0, two.size()) == two;
16 } 18 }
17 19
18 bool ends_with(const std::string& one, const std::string& two) { 20 bool ends_with(const std::string& one, const std::string& two) {
19 if (two.size() > one.size()) 21 if (two.size() > one.size())
20 return false; 22 return false;
21 23
22 return one.substr(one.size() - two.size(), two.size()) == two; 24 return one.substr(one.size() - two.size(), two.size()) == two;
23 } 25 }
24 26
25 } // namespace 27 } // namespace
26 28
27 ChromeClassTester::ChromeClassTester(CompilerInstance& instance) 29 ChromeClassTester::ChromeClassTester(CompilerInstance& instance)
28 : instance_(instance), 30 : instance_(instance),
29 diagnostic_(instance.getDiagnostics()) { 31 diagnostic_(instance.getDiagnostics()) {
30 banned_namespaces_.push_back("std"); 32 banned_namespaces_.push_back("std");
31 banned_namespaces_.push_back("__gnu_cxx"); 33 banned_namespaces_.push_back("__gnu_cxx");
32 34
33 banned_directories_.push_back("third_party"); 35 // If the path to the file in question has this as a path component, than
Nico 2011/02/24 16:00:05 then
34 banned_directories_.push_back("native_client"); 36 // abort. We just do a simple string find on the path.
35 banned_directories_.push_back("breakpad"); 37 banned_directories_.push_back("third_party/");
36 banned_directories_.push_back("courgette"); 38 banned_directories_.push_back("native_client/");
37 banned_directories_.push_back("ppapi"); 39 banned_directories_.push_back("breakpad/");
38 banned_directories_.push_back("/usr"); 40 banned_directories_.push_back("courgette/");
39 banned_directories_.push_back("testing"); 41 banned_directories_.push_back("ppapi/");
40 banned_directories_.push_back("googleurl"); 42 banned_directories_.push_back("usr/");
41 banned_directories_.push_back("v8"); 43 banned_directories_.push_back("testing/");
42 banned_directories_.push_back("sdch"); 44 banned_directories_.push_back("googleurl/");
45 banned_directories_.push_back("v8/");
46 banned_directories_.push_back("sdch/");
43 47
44 // You are standing in a mazy of twisty dependencies, all resolved by 48 // You are standing in a mazy of twisty dependencies, all resolved by
45 // putting everything in the header. 49 // putting everything in the header.
46 banned_directories_.push_back("chrome/test/automation"); 50 banned_directories_.push_back("automation/");
47 51
48 // Used in really low level threading code that probably shouldn't be out of 52 // Used in really low level threading code that probably shouldn't be out of
49 // lined. 53 // lined.
50 ignored_record_names_.push_back("ThreadLocalBoolean"); 54 ignored_record_names_.push_back("ThreadLocalBoolean");
51 55
52 // A complicated pickle derived struct that is all packed integers. 56 // A complicated pickle derived struct that is all packed integers.
53 ignored_record_names_.push_back("Header"); 57 ignored_record_names_.push_back("Header");
54 58
55 // Part of the GPU system that uses multiple included header 59 // Part of the GPU system that uses multiple included header
56 // weirdness. Never getting this right. 60 // weirdness. Never getting this right.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // Don't complain about these things in implementation files. 181 // Don't complain about these things in implementation files.
178 if (ends_with(b, ".cc") || ends_with(b, ".cpp") || ends_with(b, ".mm")) { 182 if (ends_with(b, ".cc") || ends_with(b, ".cpp") || ends_with(b, ".mm")) {
179 return true; 183 return true;
180 } 184 }
181 185
182 // Don't complain about autogenerated protobuf files. 186 // Don't complain about autogenerated protobuf files.
183 if (ends_with(b, ".pb.h")) { 187 if (ends_with(b, ".pb.h")) {
184 return true; 188 return true;
185 } 189 }
186 190
187 // Strip out all preceding path garbage. Linux and mac builds have 191 // Resolve the path.
188 // different path garbage, but after doing this, the path should be 192 char resolvedPath[MAXPATHLEN];
189 // relative to the root of the source tree. (If we didn't require 193 if (realpath(b.c_str(), resolvedPath)) {
Nico 2011/02/24 16:00:05 did you measure the build time impact of this?
Elliot Glaysher 2011/02/25 01:51:21 On linux, this adds 14 seconds to make -j8 chrome
190 // relative paths, we could have just used realpath().) 194 b = resolvedPath;
191 if (!b.empty() && b[0] != '/') {
192 size_t i = 0;
193 for (; i < b.size() && (b[i] == '.' || b[i] == '/'); ++i) {}
194 b = b.substr(i);
195 } 195 }
196 196
197 for (std::vector<std::string>::const_iterator it = 197 for (std::vector<std::string>::const_iterator it =
198 banned_directories_.begin(); 198 banned_directories_.begin();
199 it != banned_directories_.end(); ++it) { 199 it != banned_directories_.end(); ++it) {
200 if (starts_with(b, *it)) 200 // If we can find any of the banned path components in this path, than
Nico 2011/02/24 16:00:05 then
201 // this file is rejected.
202 if (b.find(*it) != std::string::npos)
Nico 2011/02/24 16:00:05 hm, i'm almost certain this will start banning dir
Elliot Glaysher 2011/02/25 01:51:21 The relative paths will often be bellow the direct
201 return true; 203 return true;
202 } 204 }
203 } 205 }
204 } 206 }
205 207
206 return false; 208 return false;
207 } 209 }
208 210
209 bool ChromeClassTester::IsIgnoredType(const std::string& base_name) { 211 bool ChromeClassTester::IsIgnoredType(const std::string& base_name) {
210 for (std::vector<std::string>::const_iterator it = 212 for (std::vector<std::string>::const_iterator it =
211 ignored_record_names_.begin(); 213 ignored_record_names_.begin();
212 it != ignored_record_names_.end(); ++it) { 214 it != ignored_record_names_.end(); ++it) {
213 if (base_name == *it) 215 if (base_name == *it)
214 return true; 216 return true;
215 } 217 }
216 218
217 return false; 219 return false;
218 } 220 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698