OLD | NEW |
---|---|
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> | 10 #include <sys/param.h> |
(...skipping 13 matching lines...) Expand all Loading... | |
24 return false; | 24 return false; |
25 | 25 |
26 return one.compare(one.size() - two.size(), two.size(), two) == 0; | 26 return one.compare(one.size() - two.size(), two.size(), two) == 0; |
27 } | 27 } |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 ChromeClassTester::ChromeClassTester(CompilerInstance& instance) | 31 ChromeClassTester::ChromeClassTester(CompilerInstance& instance) |
32 : instance_(instance), | 32 : instance_(instance), |
33 diagnostic_(instance.getDiagnostics()) { | 33 diagnostic_(instance.getDiagnostics()) { |
34 FigureOutSrcRoot(); | |
35 BuildBannedLists(); | 34 BuildBannedLists(); |
36 } | 35 } |
37 | 36 |
38 void ChromeClassTester::FigureOutSrcRoot() { | |
39 char c_cwd[MAXPATHLEN]; | |
40 if (getcwd(c_cwd, MAXPATHLEN) > 0) { | |
41 size_t pos = 1; | |
42 std::string cwd = c_cwd; | |
43 | |
44 // Add a trailing '/' because the search below requires it. | |
45 if (cwd[cwd.size() - 1] != '/') | |
46 cwd += '/'; | |
47 | |
48 // Search the directory tree downwards until we find a path that contains | |
49 // "build/common.gypi" and assume that that is our srcroot. | |
50 size_t next_slash = cwd.find('/', pos); | |
51 while (next_slash != std::string::npos) { | |
52 next_slash++; | |
53 std::string candidate = cwd.substr(0, next_slash); | |
54 | |
55 if (ends_with(candidate, "src/")) { | |
56 std::string common = candidate + "build/common.gypi"; | |
57 if (access(common.c_str(), F_OK) != -1) { | |
58 src_root_ = candidate; | |
59 break; | |
60 } | |
61 } | |
62 | |
63 pos = next_slash; | |
64 next_slash = cwd.find('/', pos); | |
65 } | |
66 } | |
67 | |
68 if (src_root_.empty()) { | |
69 unsigned id = diagnostic().getCustomDiagID( | |
70 Diagnostic::Error, | |
71 "WARNING: Can't figure out srcroot!\n"); | |
72 diagnostic().Report(id); | |
73 } | |
74 } | |
75 | |
76 void ChromeClassTester::BuildBannedLists() { | 37 void ChromeClassTester::BuildBannedLists() { |
77 banned_namespaces_.push_back("std"); | 38 banned_namespaces_.push_back("std"); |
78 banned_namespaces_.push_back("__gnu_cxx"); | 39 banned_namespaces_.push_back("__gnu_cxx"); |
79 | 40 |
80 banned_directories_.push_back("third_party"); | 41 banned_directories_.push_back("third_party/"); |
81 banned_directories_.push_back("native_client"); | 42 banned_directories_.push_back("native_client/"); |
82 banned_directories_.push_back("breakpad"); | 43 banned_directories_.push_back("breakpad/"); |
83 banned_directories_.push_back("courgette"); | 44 banned_directories_.push_back("courgette/"); |
84 banned_directories_.push_back("ppapi"); | 45 banned_directories_.push_back("ppapi/"); |
85 banned_directories_.push_back("testing"); | 46 banned_directories_.push_back("usr/"); |
hans
2012/01/16 11:14:22
It's not uncommon to have Chromium checked out in
| |
86 banned_directories_.push_back("googleurl"); | 47 banned_directories_.push_back("testing/"); |
87 banned_directories_.push_back("v8"); | 48 banned_directories_.push_back("googleurl/"); |
88 banned_directories_.push_back("sdch"); | 49 banned_directories_.push_back("v8/"); |
50 banned_directories_.push_back("sdch/"); | |
89 | 51 |
90 // Don't check autogenerated headers. | 52 // Don't check autogenerated headers. |
91 banned_directories_.push_back("out"); | 53 banned_directories_.push_back("out/"); |
92 banned_directories_.push_back("llvm"); | 54 banned_directories_.push_back("llvm/"); |
93 banned_directories_.push_back("ninja"); | 55 banned_directories_.push_back("ninja/"); |
94 banned_directories_.push_back("xcodebuild"); | 56 banned_directories_.push_back("xcodebuild/"); |
95 banned_directories_.push_back("clang"); | 57 banned_directories_.push_back("clang/"); |
96 | 58 |
97 // You are standing in a mazy of twisty dependencies, all resolved by | 59 // You are standing in a mazy of twisty dependencies, all resolved by |
98 // putting everything in the header. | 60 // putting everything in the header. |
99 banned_directories_.push_back("chrome/test/automation"); | 61 banned_directories_.push_back("automation/"); |
100 | 62 |
101 // Don't check system headers. | 63 // Don't check system headers. |
102 banned_directories_.push_back("/usr"); | 64 banned_directories_.push_back("/Developer/"); |
103 banned_directories_.push_back("/Developer"); | |
104 | 65 |
105 // Used in really low level threading code that probably shouldn't be out of | 66 // Used in really low level threading code that probably shouldn't be out of |
106 // lined. | 67 // lined. |
107 ignored_record_names_.insert("ThreadLocalBoolean"); | 68 ignored_record_names_.insert("ThreadLocalBoolean"); |
108 | 69 |
109 // A complicated pickle derived struct that is all packed integers. | 70 // A complicated pickle derived struct that is all packed integers. |
110 ignored_record_names_.insert("Header"); | 71 ignored_record_names_.insert("Header"); |
111 | 72 |
112 // Part of the GPU system that uses multiple included header | 73 // Part of the GPU system that uses multiple included header |
113 // weirdness. Never getting this right. | 74 // weirdness. Never getting this right. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 if (ends_with(b, ".pb.h")) { | 219 if (ends_with(b, ".pb.h")) { |
259 return true; | 220 return true; |
260 } | 221 } |
261 | 222 |
262 // We need to munge the paths so that they are relative to the repository | 223 // We need to munge the paths so that they are relative to the repository |
263 // srcroot. We first resolve the symlinktastic relative path and then | 224 // srcroot. We first resolve the symlinktastic relative path and then |
264 // remove our known srcroot from it if needed. | 225 // remove our known srcroot from it if needed. |
265 char resolvedPath[MAXPATHLEN]; | 226 char resolvedPath[MAXPATHLEN]; |
266 if (realpath(b.c_str(), resolvedPath)) { | 227 if (realpath(b.c_str(), resolvedPath)) { |
267 std::string resolved = resolvedPath; | 228 std::string resolved = resolvedPath; |
268 if (starts_with(resolved, src_root_)) { | |
269 b = resolved.substr(src_root_.size()); | |
270 } | |
271 } | 229 } |
272 | 230 |
273 for (std::vector<std::string>::const_iterator it = | 231 for (std::vector<std::string>::const_iterator it = |
274 banned_directories_.begin(); | 232 banned_directories_.begin(); |
275 it != banned_directories_.end(); ++it) { | 233 it != banned_directories_.end(); ++it) { |
276 if (starts_with(b, *it)) { | 234 // If we can find any of the banned path components in this path, then |
235 // this file is rejected. | |
236 if (b.find(*it) != std::string::npos) | |
277 return true; | 237 return true; |
278 } | |
279 } | 238 } |
280 } | 239 } |
281 | 240 |
282 return false; | 241 return false; |
283 } | 242 } |
284 | 243 |
285 bool ChromeClassTester::IsIgnoredType(const std::string& base_name) { | 244 bool ChromeClassTester::IsIgnoredType(const std::string& base_name) { |
286 return ignored_record_names_.find(base_name) != ignored_record_names_.end(); | 245 return ignored_record_names_.find(base_name) != ignored_record_names_.end(); |
287 } | 246 } |
OLD | NEW |