[email protected] | a18130a | 2012-01-03 17:52:08 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Top-level presubmit script for Chromium. |
| 6 | |
[email protected] | f129379 | 2009-07-31 18:09:56 | [diff] [blame] | 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
[email protected] | 50d7d721e | 2009-11-15 17:56:18 | [diff] [blame] | 8 | for more details about the presubmit API built into gcl. |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 9 | """ |
| 10 | |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 11 | |
[email protected] | 9d16ad1 | 2011-12-14 20:49:47 | [diff] [blame] | 12 | import re |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 13 | import sys |
[email protected] | 9d16ad1 | 2011-12-14 20:49:47 | [diff] [blame] | 14 | |
| 15 | |
[email protected] | 379e7dd | 2010-01-28 17:39:21 | [diff] [blame] | 16 | _EXCLUDED_PATHS = ( |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 17 | r"^breakpad[\\\/].*", |
[email protected] | 40d1dbb | 2012-10-26 07:18:00 | [diff] [blame] | 18 | r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py", |
| 19 | r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py", |
[email protected] | 8886ffcb | 2013-02-12 04:56:28 | [diff] [blame] | 20 | r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk", |
[email protected] | a18130a | 2012-01-03 17:52:08 | [diff] [blame] | 21 | r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*", |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 22 | r"^skia[\\\/].*", |
| 23 | r"^v8[\\\/].*", |
| 24 | r".*MakeFile$", |
[email protected] | 1084ccc | 2012-03-14 03:22:53 | [diff] [blame] | 25 | r".+_autogen\.h$", |
[email protected] | ce145c0 | 2012-09-06 09:49:34 | [diff] [blame] | 26 | r".+[\\\/]pnacl_shim\.c$", |
[email protected] | e07b6ac7 | 2013-08-20 00:30:42 | [diff] [blame] | 27 | r"^gpu[\\\/]config[\\\/].*_list_json\.cc$", |
[email protected] | d260060 | 2014-02-19 00:09:19 | [diff] [blame] | 28 | r"^chrome[\\\/]browser[\\\/]resources[\\\/]pdf[\\\/]index.js" |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 29 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 30 | |
[email protected] | de28fed2e | 2014-02-01 14:36:32 | [diff] [blame] | 31 | # TestRunner and NetscapePlugIn library is temporarily excluded from pan-project |
| 32 | # checks until it's transitioned to chromium coding style. |
[email protected] | 3de922f | 2013-12-20 13:27:38 | [diff] [blame] | 33 | _TESTRUNNER_PATHS = ( |
| 34 | r"^content[\\\/]shell[\\\/]renderer[\\\/]test_runner[\\\/].*", |
[email protected] | de28fed2e | 2014-02-01 14:36:32 | [diff] [blame] | 35 | r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*", |
[email protected] | 3de922f | 2013-12-20 13:27:38 | [diff] [blame] | 36 | ) |
| 37 | |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 38 | # Fragment of a regular expression that matches C++ and Objective-C++ |
| 39 | # implementation files. |
| 40 | _IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$' |
| 41 | |
| 42 | # Regular expression that matches code only used for test binaries |
| 43 | # (best effort). |
| 44 | _TEST_CODE_EXCLUDED_PATHS = ( |
| 45 | r'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS, |
| 46 | r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS, |
[email protected] | 6e04f8c | 2014-01-29 18:08:32 | [diff] [blame] | 47 | r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' % |
[email protected] | e2d7e6f | 2013-04-23 12:57:12 | [diff] [blame] | 48 | _IMPLEMENTATION_EXTENSIONS, |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 49 | r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS, |
| 50 | r'.*[/\\](test|tool(s)?)[/\\].*', |
[email protected] | ef070cc | 2013-05-03 11:53:05 | [diff] [blame] | 51 | # content_shell is used for running layout tests. |
| 52 | r'content[/\\]shell[/\\].*', |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 53 | # At request of folks maintaining this folder. |
| 54 | r'chrome[/\\]browser[/\\]automation[/\\].*', |
[email protected] | 7b05498 | 2013-11-27 00:44:47 | [diff] [blame] | 55 | # Non-production example code. |
| 56 | r'mojo[/\\]examples[/\\].*', |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 57 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 58 | |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 59 | _TEST_ONLY_WARNING = ( |
| 60 | 'You might be calling functions intended only for testing from\n' |
| 61 | 'production code. It is OK to ignore this warning if you know what\n' |
| 62 | 'you are doing, as the heuristics used to detect the situation are\n' |
[email protected] | b014977 | 2014-03-27 16:47:58 | [diff] [blame] | 63 | 'not perfect. The commit queue will not block on this warning.') |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 64 | |
| 65 | |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 66 | _INCLUDE_ORDER_WARNING = ( |
| 67 | 'Your #include order seems to be broken. Send mail to\n' |
| 68 | '[email protected] if this is not the case.') |
| 69 | |
| 70 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 71 | _BANNED_OBJC_FUNCTIONS = ( |
| 72 | ( |
| 73 | 'addTrackingRect:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 74 | ( |
| 75 | 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 76 | 'prohibited. Please use CrTrackingArea instead.', |
| 77 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 78 | ), |
| 79 | False, |
| 80 | ), |
| 81 | ( |
[email protected] | eaae197 | 2014-04-16 04:17:26 | [diff] [blame] | 82 | r'/NSTrackingArea\W', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 83 | ( |
| 84 | 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 85 | 'instead.', |
| 86 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 87 | ), |
| 88 | False, |
| 89 | ), |
| 90 | ( |
| 91 | 'convertPointFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 92 | ( |
| 93 | 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 94 | 'Please use |convertPoint:(point) fromView:nil| instead.', |
| 95 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 96 | ), |
| 97 | True, |
| 98 | ), |
| 99 | ( |
| 100 | 'convertPointToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 101 | ( |
| 102 | 'The use of -[NSView convertPointToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 103 | 'Please use |convertPoint:(point) toView:nil| instead.', |
| 104 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 105 | ), |
| 106 | True, |
| 107 | ), |
| 108 | ( |
| 109 | 'convertRectFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 110 | ( |
| 111 | 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 112 | 'Please use |convertRect:(point) fromView:nil| instead.', |
| 113 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 114 | ), |
| 115 | True, |
| 116 | ), |
| 117 | ( |
| 118 | 'convertRectToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 119 | ( |
| 120 | 'The use of -[NSView convertRectToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 121 | 'Please use |convertRect:(point) toView:nil| instead.', |
| 122 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 123 | ), |
| 124 | True, |
| 125 | ), |
| 126 | ( |
| 127 | 'convertSizeFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 128 | ( |
| 129 | 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 130 | 'Please use |convertSize:(point) fromView:nil| instead.', |
| 131 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 132 | ), |
| 133 | True, |
| 134 | ), |
| 135 | ( |
| 136 | 'convertSizeToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 137 | ( |
| 138 | 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 139 | 'Please use |convertSize:(point) toView:nil| instead.', |
| 140 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 141 | ), |
| 142 | True, |
| 143 | ), |
| 144 | ) |
| 145 | |
| 146 | |
| 147 | _BANNED_CPP_FUNCTIONS = ( |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 148 | # Make sure that gtest's FRIEND_TEST() macro is not used; the |
| 149 | # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be |
[email protected] | e00ccc9 | 2012-11-01 17:32:30 | [diff] [blame] | 150 | # used instead since that allows for FLAKY_ and DISABLED_ prefixes. |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 151 | ( |
| 152 | 'FRIEND_TEST(', |
| 153 | ( |
[email protected] | e3c94550 | 2012-06-26 20:01:49 | [diff] [blame] | 154 | 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 155 | 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.', |
| 156 | ), |
| 157 | False, |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 158 | (), |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 159 | ), |
| 160 | ( |
| 161 | 'ScopedAllowIO', |
| 162 | ( |
[email protected] | e3c94550 | 2012-06-26 20:01:49 | [diff] [blame] | 163 | 'New code should not use ScopedAllowIO. Post a task to the blocking', |
| 164 | 'pool or the FILE thread instead.', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 165 | ), |
[email protected] | e3c94550 | 2012-06-26 20:01:49 | [diff] [blame] | 166 | True, |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 167 | ( |
[email protected] | b01b9e2 | 2014-06-03 22:20:19 | [diff] [blame^] | 168 | r"^chrome[\\\/]browser[\\\/]chromeos[\\\/]boot_times_loader\.cc$", |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 169 | r"^components[\\\/]breakpad[\\\/]app[\\\/]breakpad_mac\.mm$", |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 170 | r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$", |
| 171 | r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$", |
[email protected] | ac1df70 | 2014-03-21 20:45:27 | [diff] [blame] | 172 | r"^mojo[\\\/]system[\\\/]raw_shared_buffer_posix\.cc$", |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 173 | r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$", |
[email protected] | 1f52a57 | 2014-05-12 23:21:54 | [diff] [blame] | 174 | r"^net[\\\/]url_request[\\\/]test_url_fetcher_factory\.cc$", |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 175 | ), |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 176 | ), |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 177 | ( |
| 178 | 'SkRefPtr', |
| 179 | ( |
| 180 | 'The use of SkRefPtr is prohibited. ', |
| 181 | 'Please use skia::RefPtr instead.' |
| 182 | ), |
| 183 | True, |
| 184 | (), |
| 185 | ), |
| 186 | ( |
| 187 | 'SkAutoRef', |
| 188 | ( |
| 189 | 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ', |
| 190 | 'Please use skia::RefPtr instead.' |
| 191 | ), |
| 192 | True, |
| 193 | (), |
| 194 | ), |
| 195 | ( |
| 196 | 'SkAutoTUnref', |
| 197 | ( |
| 198 | 'The use of SkAutoTUnref is dangerous because it implicitly ', |
| 199 | 'converts to a raw pointer. Please use skia::RefPtr instead.' |
| 200 | ), |
| 201 | True, |
| 202 | (), |
| 203 | ), |
| 204 | ( |
| 205 | 'SkAutoUnref', |
| 206 | ( |
| 207 | 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ', |
| 208 | 'because it implicitly converts to a raw pointer. ', |
| 209 | 'Please use skia::RefPtr instead.' |
| 210 | ), |
| 211 | True, |
| 212 | (), |
| 213 | ), |
[email protected] | d89eec8 | 2013-12-03 14:10:59 | [diff] [blame] | 214 | ( |
| 215 | r'/HANDLE_EINTR\(.*close', |
| 216 | ( |
| 217 | 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file', |
| 218 | 'descriptor will be closed, and it is incorrect to retry the close.', |
| 219 | 'Either call close directly and ignore its return value, or wrap close', |
| 220 | 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623' |
| 221 | ), |
| 222 | True, |
| 223 | (), |
| 224 | ), |
| 225 | ( |
| 226 | r'/IGNORE_EINTR\((?!.*close)', |
| 227 | ( |
| 228 | 'IGNORE_EINTR is only valid when wrapping close. To wrap other system', |
| 229 | 'calls, use HANDLE_EINTR. See http://crbug.com/269623', |
| 230 | ), |
| 231 | True, |
| 232 | ( |
| 233 | # Files that #define IGNORE_EINTR. |
| 234 | r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$', |
| 235 | r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$', |
| 236 | ), |
| 237 | ), |
[email protected] | ec5b3f0 | 2014-04-04 18:43:43 | [diff] [blame] | 238 | ( |
| 239 | r'/v8::Extension\(', |
| 240 | ( |
| 241 | 'Do not introduce new v8::Extensions into the code base, use', |
| 242 | 'gin::Wrappable instead. See http://crbug.com/334679', |
| 243 | ), |
| 244 | True, |
[email protected] | f55c90ee6 | 2014-04-12 00:50:03 | [diff] [blame] | 245 | ( |
| 246 | r'extensions[/\\]renderer[/\\]safe_builtins\.*', |
| 247 | ), |
[email protected] | ec5b3f0 | 2014-04-04 18:43:43 | [diff] [blame] | 248 | ), |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 249 | ) |
| 250 | |
| 251 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 252 | _VALID_OS_MACROS = ( |
| 253 | # Please keep sorted. |
| 254 | 'OS_ANDROID', |
[email protected] | f4440b4 | 2014-03-19 05:47:01 | [diff] [blame] | 255 | 'OS_ANDROID_HOST', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 256 | 'OS_BSD', |
| 257 | 'OS_CAT', # For testing. |
| 258 | 'OS_CHROMEOS', |
| 259 | 'OS_FREEBSD', |
| 260 | 'OS_IOS', |
| 261 | 'OS_LINUX', |
| 262 | 'OS_MACOSX', |
| 263 | 'OS_NACL', |
| 264 | 'OS_OPENBSD', |
| 265 | 'OS_POSIX', |
[email protected] | eda7afa1 | 2014-02-06 12:27:37 | [diff] [blame] | 266 | 'OS_QNX', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 267 | 'OS_SOLARIS', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 268 | 'OS_WIN', |
| 269 | ) |
| 270 | |
| 271 | |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 272 | def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): |
| 273 | """Attempts to prevent use of functions intended only for testing in |
| 274 | non-testing code. For now this is just a best-effort implementation |
| 275 | that ignores header files and may have some false positives. A |
| 276 | better implementation would probably need a proper C++ parser. |
| 277 | """ |
| 278 | # We only scan .cc files and the like, as the declaration of |
| 279 | # for-testing functions in header files are hard to distinguish from |
| 280 | # calls to such functions without a proper C++ parser. |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 281 | file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 282 | |
[email protected] | 2350182 | 2014-05-14 02:06:09 | [diff] [blame] | 283 | base_function_pattern = r'[ :]test::[^\s]+|ForTest(ing)?|for_test(ing)?' |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 284 | inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern) |
[email protected] | 2350182 | 2014-05-14 02:06:09 | [diff] [blame] | 285 | comment_pattern = input_api.re.compile(r'//.*(%s)' % base_function_pattern) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 286 | exclusion_pattern = input_api.re.compile( |
| 287 | r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % ( |
| 288 | base_function_pattern, base_function_pattern)) |
| 289 | |
| 290 | def FilterFile(affected_file): |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 291 | black_list = (_EXCLUDED_PATHS + |
| 292 | _TEST_CODE_EXCLUDED_PATHS + |
| 293 | input_api.DEFAULT_BLACK_LIST) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 294 | return input_api.FilterSourceFile( |
| 295 | affected_file, |
| 296 | white_list=(file_inclusion_pattern, ), |
| 297 | black_list=black_list) |
| 298 | |
| 299 | problems = [] |
| 300 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 301 | local_path = f.LocalPath() |
[email protected] | 825d2718 | 2014-01-02 21:24:24 | [diff] [blame] | 302 | for line_number, line in f.ChangedContents(): |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 303 | if (inclusion_pattern.search(line) and |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 304 | not comment_pattern.search(line) and |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 305 | not exclusion_pattern.search(line)): |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 306 | problems.append( |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 307 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 308 | |
| 309 | if problems: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 310 | return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 311 | else: |
| 312 | return [] |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 313 | |
| 314 | |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 315 | def _CheckNoIOStreamInHeaders(input_api, output_api): |
| 316 | """Checks to make sure no .h files include <iostream>.""" |
| 317 | files = [] |
| 318 | pattern = input_api.re.compile(r'^#include\s*<iostream>', |
| 319 | input_api.re.MULTILINE) |
| 320 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 321 | if not f.LocalPath().endswith('.h'): |
| 322 | continue |
| 323 | contents = input_api.ReadFile(f) |
| 324 | if pattern.search(contents): |
| 325 | files.append(f) |
| 326 | |
| 327 | if len(files): |
| 328 | return [ output_api.PresubmitError( |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 329 | 'Do not #include <iostream> in header files, since it inserts static ' |
| 330 | 'initialization into every file including the header. Instead, ' |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 331 | '#include <ostream>. See http://crbug.com/94794', |
| 332 | files) ] |
| 333 | return [] |
| 334 | |
| 335 | |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 336 | def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api): |
| 337 | """Checks to make sure no source files use UNIT_TEST""" |
| 338 | problems = [] |
| 339 | for f in input_api.AffectedFiles(): |
| 340 | if (not f.LocalPath().endswith(('.cc', '.mm'))): |
| 341 | continue |
| 342 | |
| 343 | for line_num, line in f.ChangedContents(): |
[email protected] | 549f86a | 2013-11-19 13:00:04 | [diff] [blame] | 344 | if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'): |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 345 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 346 | |
| 347 | if not problems: |
| 348 | return [] |
| 349 | return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' + |
| 350 | '\n'.join(problems))] |
| 351 | |
| 352 | |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 353 | def _CheckNoNewWStrings(input_api, output_api): |
| 354 | """Checks to make sure we don't introduce use of wstrings.""" |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 355 | problems = [] |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 356 | for f in input_api.AffectedFiles(): |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 357 | if (not f.LocalPath().endswith(('.cc', '.h')) or |
[email protected] | 24be83c | 2013-08-29 23:01:23 | [diff] [blame] | 358 | f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))): |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 359 | continue |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 360 | |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 361 | allowWString = False |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 362 | for line_num, line in f.ChangedContents(): |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 363 | if 'presubmit: allow wstring' in line: |
| 364 | allowWString = True |
| 365 | elif not allowWString and 'wstring' in line: |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 366 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 367 | allowWString = False |
| 368 | else: |
| 369 | allowWString = False |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 370 | |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 371 | if not problems: |
| 372 | return [] |
| 373 | return [output_api.PresubmitPromptWarning('New code should not use wstrings.' |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 374 | ' If you are calling a cross-platform API that accepts a wstring, ' |
| 375 | 'fix the API.\n' + |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 376 | '\n'.join(problems))] |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 377 | |
| 378 | |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 379 | def _CheckNoDEPSGIT(input_api, output_api): |
| 380 | """Make sure .DEPS.git is never modified manually.""" |
| 381 | if any(f.LocalPath().endswith('.DEPS.git') for f in |
| 382 | input_api.AffectedFiles()): |
| 383 | return [output_api.PresubmitError( |
| 384 | 'Never commit changes to .DEPS.git. This file is maintained by an\n' |
| 385 | 'automated system based on what\'s in DEPS and your changes will be\n' |
| 386 | 'overwritten.\n' |
| 387 | 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n' |
| 388 | 'for more information')] |
| 389 | return [] |
| 390 | |
| 391 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 392 | def _CheckNoBannedFunctions(input_api, output_api): |
| 393 | """Make sure that banned functions are not used.""" |
| 394 | warnings = [] |
| 395 | errors = [] |
| 396 | |
| 397 | file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) |
| 398 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 399 | for line_num, line in f.ChangedContents(): |
| 400 | for func_name, message, error in _BANNED_OBJC_FUNCTIONS: |
[email protected] | eaae197 | 2014-04-16 04:17:26 | [diff] [blame] | 401 | matched = False |
| 402 | if func_name[0:1] == '/': |
| 403 | regex = func_name[1:] |
| 404 | if input_api.re.search(regex, line): |
| 405 | matched = True |
| 406 | elif func_name in line: |
| 407 | matched = True |
| 408 | if matched: |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 409 | problems = warnings; |
| 410 | if error: |
| 411 | problems = errors; |
| 412 | problems.append(' %s:%d:' % (f.LocalPath(), line_num)) |
| 413 | for message_line in message: |
| 414 | problems.append(' %s' % message_line) |
| 415 | |
| 416 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h')) |
| 417 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 418 | for line_num, line in f.ChangedContents(): |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 419 | for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS: |
| 420 | def IsBlacklisted(affected_file, blacklist): |
| 421 | local_path = affected_file.LocalPath() |
| 422 | for item in blacklist: |
| 423 | if input_api.re.match(item, local_path): |
| 424 | return True |
| 425 | return False |
| 426 | if IsBlacklisted(f, excluded_paths): |
| 427 | continue |
[email protected] | d89eec8 | 2013-12-03 14:10:59 | [diff] [blame] | 428 | matched = False |
| 429 | if func_name[0:1] == '/': |
| 430 | regex = func_name[1:] |
| 431 | if input_api.re.search(regex, line): |
| 432 | matched = True |
| 433 | elif func_name in line: |
| 434 | matched = True |
| 435 | if matched: |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 436 | problems = warnings; |
| 437 | if error: |
| 438 | problems = errors; |
| 439 | problems.append(' %s:%d:' % (f.LocalPath(), line_num)) |
| 440 | for message_line in message: |
| 441 | problems.append(' %s' % message_line) |
| 442 | |
| 443 | result = [] |
| 444 | if (warnings): |
| 445 | result.append(output_api.PresubmitPromptWarning( |
| 446 | 'Banned functions were used.\n' + '\n'.join(warnings))) |
| 447 | if (errors): |
| 448 | result.append(output_api.PresubmitError( |
| 449 | 'Banned functions were used.\n' + '\n'.join(errors))) |
| 450 | return result |
| 451 | |
| 452 | |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 453 | def _CheckNoPragmaOnce(input_api, output_api): |
| 454 | """Make sure that banned functions are not used.""" |
| 455 | files = [] |
| 456 | pattern = input_api.re.compile(r'^#pragma\s+once', |
| 457 | input_api.re.MULTILINE) |
| 458 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 459 | if not f.LocalPath().endswith('.h'): |
| 460 | continue |
| 461 | contents = input_api.ReadFile(f) |
| 462 | if pattern.search(contents): |
| 463 | files.append(f) |
| 464 | |
| 465 | if files: |
| 466 | return [output_api.PresubmitError( |
| 467 | 'Do not use #pragma once in header files.\n' |
| 468 | 'See http://www.chromium.org/developers/coding-style#TOC-File-headers', |
| 469 | files)] |
| 470 | return [] |
| 471 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 472 | |
[email protected] | e747905 | 2012-09-19 00:26:12 | [diff] [blame] | 473 | def _CheckNoTrinaryTrueFalse(input_api, output_api): |
| 474 | """Checks to make sure we don't introduce use of foo ? true : false.""" |
| 475 | problems = [] |
| 476 | pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)') |
| 477 | for f in input_api.AffectedFiles(): |
| 478 | if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')): |
| 479 | continue |
| 480 | |
| 481 | for line_num, line in f.ChangedContents(): |
| 482 | if pattern.match(line): |
| 483 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 484 | |
| 485 | if not problems: |
| 486 | return [] |
| 487 | return [output_api.PresubmitPromptWarning( |
| 488 | 'Please consider avoiding the "? true : false" pattern if possible.\n' + |
| 489 | '\n'.join(problems))] |
| 490 | |
| 491 | |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 492 | def _CheckUnwantedDependencies(input_api, output_api): |
| 493 | """Runs checkdeps on #include statements added in this |
| 494 | change. Breaking - rules is an error, breaking ! rules is a |
| 495 | warning. |
| 496 | """ |
| 497 | # We need to wait until we have an input_api object and use this |
| 498 | # roundabout construct to import checkdeps because this file is |
| 499 | # eval-ed and thus doesn't have __file__. |
| 500 | original_sys_path = sys.path |
| 501 | try: |
| 502 | sys.path = sys.path + [input_api.os_path.join( |
[email protected] | 5298cc98 | 2014-05-29 20:53:47 | [diff] [blame] | 503 | input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 504 | import checkdeps |
| 505 | from cpp_checker import CppChecker |
| 506 | from rules import Rule |
| 507 | finally: |
| 508 | # Restore sys.path to what it was before. |
| 509 | sys.path = original_sys_path |
| 510 | |
| 511 | added_includes = [] |
| 512 | for f in input_api.AffectedFiles(): |
| 513 | if not CppChecker.IsCppFile(f.LocalPath()): |
| 514 | continue |
| 515 | |
| 516 | changed_lines = [line for line_num, line in f.ChangedContents()] |
| 517 | added_includes.append([f.LocalPath(), changed_lines]) |
| 518 | |
[email protected] | 2638517 | 2013-05-09 23:11:35 | [diff] [blame] | 519 | deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 520 | |
| 521 | error_descriptions = [] |
| 522 | warning_descriptions = [] |
| 523 | for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( |
| 524 | added_includes): |
| 525 | description_with_path = '%s\n %s' % (path, rule_description) |
| 526 | if rule_type == Rule.DISALLOW: |
| 527 | error_descriptions.append(description_with_path) |
| 528 | else: |
| 529 | warning_descriptions.append(description_with_path) |
| 530 | |
| 531 | results = [] |
| 532 | if error_descriptions: |
| 533 | results.append(output_api.PresubmitError( |
| 534 | 'You added one or more #includes that violate checkdeps rules.', |
| 535 | error_descriptions)) |
| 536 | if warning_descriptions: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 537 | results.append(output_api.PresubmitPromptOrNotify( |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 538 | 'You added one or more #includes of files that are temporarily\n' |
| 539 | 'allowed but being removed. Can you avoid introducing the\n' |
| 540 | '#include? See relevant DEPS file(s) for details and contacts.', |
| 541 | warning_descriptions)) |
| 542 | return results |
| 543 | |
| 544 | |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 545 | def _CheckFilePermissions(input_api, output_api): |
| 546 | """Check that all files have their permissions properly set.""" |
[email protected] | 79150720 | 2014-02-03 23:19:15 | [diff] [blame] | 547 | if input_api.platform == 'win32': |
| 548 | return [] |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 549 | args = [sys.executable, 'tools/checkperms/checkperms.py', '--root', |
| 550 | input_api.change.RepositoryRoot()] |
| 551 | for f in input_api.AffectedFiles(): |
| 552 | args += ['--file', f.LocalPath()] |
[email protected] | f0d330f | 2014-01-30 01:44:34 | [diff] [blame] | 553 | checkperms = input_api.subprocess.Popen(args, |
| 554 | stdout=input_api.subprocess.PIPE) |
| 555 | errors = checkperms.communicate()[0].strip() |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 556 | if errors: |
[email protected] | f0d330f | 2014-01-30 01:44:34 | [diff] [blame] | 557 | return [output_api.PresubmitError('checkperms.py failed.', |
| 558 | errors.splitlines())] |
| 559 | return [] |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 560 | |
| 561 | |
[email protected] | c8278b3 | 2012-10-30 20:35:49 | [diff] [blame] | 562 | def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api): |
| 563 | """Makes sure we don't include ui/aura/window_property.h |
| 564 | in header files. |
| 565 | """ |
| 566 | pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"') |
| 567 | errors = [] |
| 568 | for f in input_api.AffectedFiles(): |
| 569 | if not f.LocalPath().endswith('.h'): |
| 570 | continue |
| 571 | for line_num, line in f.ChangedContents(): |
| 572 | if pattern.match(line): |
| 573 | errors.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 574 | |
| 575 | results = [] |
| 576 | if errors: |
| 577 | results.append(output_api.PresubmitError( |
| 578 | 'Header files should not include ui/aura/window_property.h', errors)) |
| 579 | return results |
| 580 | |
| 581 | |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 582 | def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums): |
| 583 | """Checks that the lines in scope occur in the right order. |
| 584 | |
| 585 | 1. C system files in alphabetical order |
| 586 | 2. C++ system files in alphabetical order |
| 587 | 3. Project's .h files |
| 588 | """ |
| 589 | |
| 590 | c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>') |
| 591 | cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>') |
| 592 | custom_include_pattern = input_api.re.compile(r'\s*#include ".*') |
| 593 | |
| 594 | C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3) |
| 595 | |
| 596 | state = C_SYSTEM_INCLUDES |
| 597 | |
| 598 | previous_line = '' |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 599 | previous_line_num = 0 |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 600 | problem_linenums = [] |
| 601 | for line_num, line in scope: |
| 602 | if c_system_include_pattern.match(line): |
| 603 | if state != C_SYSTEM_INCLUDES: |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 604 | problem_linenums.append((line_num, previous_line_num)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 605 | elif previous_line and previous_line > line: |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 606 | problem_linenums.append((line_num, previous_line_num)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 607 | elif cpp_system_include_pattern.match(line): |
| 608 | if state == C_SYSTEM_INCLUDES: |
| 609 | state = CPP_SYSTEM_INCLUDES |
| 610 | elif state == CUSTOM_INCLUDES: |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 611 | problem_linenums.append((line_num, previous_line_num)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 612 | elif previous_line and previous_line > line: |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 613 | problem_linenums.append((line_num, previous_line_num)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 614 | elif custom_include_pattern.match(line): |
| 615 | if state != CUSTOM_INCLUDES: |
| 616 | state = CUSTOM_INCLUDES |
| 617 | elif previous_line and previous_line > line: |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 618 | problem_linenums.append((line_num, previous_line_num)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 619 | else: |
| 620 | problem_linenums.append(line_num) |
| 621 | previous_line = line |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 622 | previous_line_num = line_num |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 623 | |
| 624 | warnings = [] |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 625 | for (line_num, previous_line_num) in problem_linenums: |
| 626 | if line_num in changed_linenums or previous_line_num in changed_linenums: |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 627 | warnings.append(' %s:%d' % (file_path, line_num)) |
| 628 | return warnings |
| 629 | |
| 630 | |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 631 | def _CheckIncludeOrderInFile(input_api, f, changed_linenums): |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 632 | """Checks the #include order for the given file f.""" |
| 633 | |
[email protected] | 2299dcf | 2012-11-15 19:56:24 | [diff] [blame] | 634 | system_include_pattern = input_api.re.compile(r'\s*#include \<.*') |
[email protected] | 23093b6 | 2013-09-20 12:16:30 | [diff] [blame] | 635 | # Exclude the following includes from the check: |
| 636 | # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a |
| 637 | # specific order. |
| 638 | # 2) <atlbase.h>, "build/build_config.h" |
| 639 | excluded_include_pattern = input_api.re.compile( |
| 640 | r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")') |
[email protected] | 2299dcf | 2012-11-15 19:56:24 | [diff] [blame] | 641 | custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"') |
[email protected] | 3e83618c | 2013-10-09 22:32:33 | [diff] [blame] | 642 | # Match the final or penultimate token if it is xxxtest so we can ignore it |
| 643 | # when considering the special first include. |
| 644 | test_file_tag_pattern = input_api.re.compile( |
| 645 | r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)') |
[email protected] | 0e5c185 | 2012-12-18 20:17:11 | [diff] [blame] | 646 | if_pattern = input_api.re.compile( |
| 647 | r'\s*#\s*(if|elif|else|endif|define|undef).*') |
| 648 | # Some files need specialized order of includes; exclude such files from this |
| 649 | # check. |
| 650 | uncheckable_includes_pattern = input_api.re.compile( |
| 651 | r'\s*#include ' |
| 652 | '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*') |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 653 | |
| 654 | contents = f.NewContents() |
| 655 | warnings = [] |
| 656 | line_num = 0 |
| 657 | |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 658 | # Handle the special first include. If the first include file is |
| 659 | # some/path/file.h, the corresponding including file can be some/path/file.cc, |
| 660 | # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h |
| 661 | # etc. It's also possible that no special first include exists. |
[email protected] | 3e83618c | 2013-10-09 22:32:33 | [diff] [blame] | 662 | # If the included file is some/path/file_platform.h the including file could |
| 663 | # also be some/path/file_xxxtest_platform.h. |
| 664 | including_file_base_name = test_file_tag_pattern.sub( |
| 665 | '', input_api.os_path.basename(f.LocalPath())) |
| 666 | |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 667 | for line in contents: |
| 668 | line_num += 1 |
| 669 | if system_include_pattern.match(line): |
| 670 | # No special first include -> process the line again along with normal |
| 671 | # includes. |
| 672 | line_num -= 1 |
| 673 | break |
| 674 | match = custom_include_pattern.match(line) |
| 675 | if match: |
| 676 | match_dict = match.groupdict() |
[email protected] | 3e83618c | 2013-10-09 22:32:33 | [diff] [blame] | 677 | header_basename = test_file_tag_pattern.sub( |
| 678 | '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '') |
| 679 | |
| 680 | if header_basename not in including_file_base_name: |
[email protected] | 2299dcf | 2012-11-15 19:56:24 | [diff] [blame] | 681 | # No special first include -> process the line again along with normal |
| 682 | # includes. |
| 683 | line_num -= 1 |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 684 | break |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 685 | |
| 686 | # Split into scopes: Each region between #if and #endif is its own scope. |
| 687 | scopes = [] |
| 688 | current_scope = [] |
| 689 | for line in contents[line_num:]: |
| 690 | line_num += 1 |
[email protected] | 0e5c185 | 2012-12-18 20:17:11 | [diff] [blame] | 691 | if uncheckable_includes_pattern.match(line): |
[email protected] | 4436c9e | 2014-01-07 23:19:54 | [diff] [blame] | 692 | continue |
[email protected] | 2309b0fa0 | 2012-11-16 12:18:27 | [diff] [blame] | 693 | if if_pattern.match(line): |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 694 | scopes.append(current_scope) |
| 695 | current_scope = [] |
[email protected] | 962f117e | 2012-11-22 18:11:56 | [diff] [blame] | 696 | elif ((system_include_pattern.match(line) or |
| 697 | custom_include_pattern.match(line)) and |
| 698 | not excluded_include_pattern.match(line)): |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 699 | current_scope.append((line_num, line)) |
| 700 | scopes.append(current_scope) |
| 701 | |
| 702 | for scope in scopes: |
| 703 | warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(), |
| 704 | changed_linenums)) |
| 705 | return warnings |
| 706 | |
| 707 | |
| 708 | def _CheckIncludeOrder(input_api, output_api): |
| 709 | """Checks that the #include order is correct. |
| 710 | |
| 711 | 1. The corresponding header for source files. |
| 712 | 2. C system files in alphabetical order |
| 713 | 3. C++ system files in alphabetical order |
| 714 | 4. Project's .h files in alphabetical order |
| 715 | |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 716 | Each region separated by #if, #elif, #else, #endif, #define and #undef follows |
| 717 | these rules separately. |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 718 | """ |
| 719 | |
| 720 | warnings = [] |
| 721 | for f in input_api.AffectedFiles(): |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 722 | if f.LocalPath().endswith(('.cc', '.h')): |
| 723 | changed_linenums = set(line_num for line_num, _ in f.ChangedContents()) |
| 724 | warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 725 | |
| 726 | results = [] |
| 727 | if warnings: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 728 | results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING, |
[email protected] | 120cf540d | 2012-12-10 17:55:53 | [diff] [blame] | 729 | warnings)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 730 | return results |
| 731 | |
| 732 | |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 733 | def _CheckForVersionControlConflictsInFile(input_api, f): |
| 734 | pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$') |
| 735 | errors = [] |
| 736 | for line_num, line in f.ChangedContents(): |
| 737 | if pattern.match(line): |
| 738 | errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) |
| 739 | return errors |
| 740 | |
| 741 | |
| 742 | def _CheckForVersionControlConflicts(input_api, output_api): |
| 743 | """Usually this is not intentional and will cause a compile failure.""" |
| 744 | errors = [] |
| 745 | for f in input_api.AffectedFiles(): |
| 746 | errors.extend(_CheckForVersionControlConflictsInFile(input_api, f)) |
| 747 | |
| 748 | results = [] |
| 749 | if errors: |
| 750 | results.append(output_api.PresubmitError( |
| 751 | 'Version control conflict markers found, please resolve.', errors)) |
| 752 | return results |
| 753 | |
| 754 | |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 755 | def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api): |
| 756 | def FilterFile(affected_file): |
| 757 | """Filter function for use with input_api.AffectedSourceFiles, |
| 758 | below. This filters out everything except non-test files from |
| 759 | top-level directories that generally speaking should not hard-code |
| 760 | service URLs (e.g. src/android_webview/, src/content/ and others). |
| 761 | """ |
| 762 | return input_api.FilterSourceFile( |
| 763 | affected_file, |
[email protected] | 78bb39d6 | 2012-12-11 15:11:56 | [diff] [blame] | 764 | white_list=(r'^(android_webview|base|content|net)[\\\/].*', ), |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 765 | black_list=(_EXCLUDED_PATHS + |
| 766 | _TEST_CODE_EXCLUDED_PATHS + |
| 767 | input_api.DEFAULT_BLACK_LIST)) |
| 768 | |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 769 | base_pattern = '"[^"]*google\.com[^"]*"' |
| 770 | comment_pattern = input_api.re.compile('//.*%s' % base_pattern) |
| 771 | pattern = input_api.re.compile(base_pattern) |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 772 | problems = [] # items are (filename, line_number, line) |
| 773 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 774 | for line_num, line in f.ChangedContents(): |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 775 | if not comment_pattern.search(line) and pattern.search(line): |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 776 | problems.append((f.LocalPath(), line_num, line)) |
| 777 | |
| 778 | if problems: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 779 | return [output_api.PresubmitPromptOrNotify( |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 780 | 'Most layers below src/chrome/ should not hardcode service URLs.\n' |
[email protected] | b014977 | 2014-03-27 16:47:58 | [diff] [blame] | 781 | 'Are you sure this is correct?', |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 782 | [' %s:%d: %s' % ( |
| 783 | problem[0], problem[1], problem[2]) for problem in problems])] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 784 | else: |
| 785 | return [] |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 786 | |
| 787 | |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 788 | def _CheckNoAbbreviationInPngFileName(input_api, output_api): |
| 789 | """Makes sure there are no abbreviations in the name of PNG files. |
| 790 | """ |
[email protected] | 4053a48e | 2013-01-25 21:43:04 | [diff] [blame] | 791 | pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$') |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 792 | errors = [] |
| 793 | for f in input_api.AffectedFiles(include_deletes=False): |
| 794 | if pattern.match(f.LocalPath()): |
| 795 | errors.append(' %s' % f.LocalPath()) |
| 796 | |
| 797 | results = [] |
| 798 | if errors: |
| 799 | results.append(output_api.PresubmitError( |
| 800 | 'The name of PNG files should not have abbreviations. \n' |
| 801 | 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n' |
| 802 | 'Contact [email protected] if you have questions.', errors)) |
| 803 | return results |
| 804 | |
| 805 | |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 806 | def _FilesToCheckForIncomingDeps(re, changed_lines): |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 807 | """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 808 | a set of DEPS entries that we should look up. |
| 809 | |
| 810 | For a directory (rather than a specific filename) we fake a path to |
| 811 | a specific filename by adding /DEPS. This is chosen as a file that |
| 812 | will seldom or never be subject to per-file include_rules. |
| 813 | """ |
[email protected] | 2b438d6 | 2013-11-14 17:54:14 | [diff] [blame] | 814 | # We ignore deps entries on auto-generated directories. |
| 815 | AUTO_GENERATED_DIRS = ['grit', 'jni'] |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 816 | |
| 817 | # This pattern grabs the path without basename in the first |
| 818 | # parentheses, and the basename (if present) in the second. It |
| 819 | # relies on the simple heuristic that if there is a basename it will |
| 820 | # be a header file ending in ".h". |
| 821 | pattern = re.compile( |
| 822 | r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""") |
[email protected] | 2b438d6 | 2013-11-14 17:54:14 | [diff] [blame] | 823 | results = set() |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 824 | for changed_line in changed_lines: |
| 825 | m = pattern.match(changed_line) |
| 826 | if m: |
| 827 | path = m.group(1) |
[email protected] | 2b438d6 | 2013-11-14 17:54:14 | [diff] [blame] | 828 | if path.split('/')[0] not in AUTO_GENERATED_DIRS: |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 829 | if m.group(2): |
| 830 | results.add('%s%s' % (path, m.group(2))) |
| 831 | else: |
| 832 | results.add('%s/DEPS' % path) |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 833 | return results |
| 834 | |
| 835 | |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 836 | def _CheckAddedDepsHaveTargetApprovals(input_api, output_api): |
| 837 | """When a dependency prefixed with + is added to a DEPS file, we |
| 838 | want to make sure that the change is reviewed by an OWNER of the |
| 839 | target file or directory, to avoid layering violations from being |
| 840 | introduced. This check verifies that this happens. |
| 841 | """ |
| 842 | changed_lines = set() |
| 843 | for f in input_api.AffectedFiles(): |
| 844 | filename = input_api.os_path.basename(f.LocalPath()) |
| 845 | if filename == 'DEPS': |
| 846 | changed_lines |= set(line.strip() |
| 847 | for line_num, line |
| 848 | in f.ChangedContents()) |
| 849 | if not changed_lines: |
| 850 | return [] |
| 851 | |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 852 | virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re, |
| 853 | changed_lines) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 854 | if not virtual_depended_on_files: |
| 855 | return [] |
| 856 | |
| 857 | if input_api.is_committing: |
| 858 | if input_api.tbr: |
| 859 | return [output_api.PresubmitNotifyResult( |
| 860 | '--tbr was specified, skipping OWNERS check for DEPS additions')] |
| 861 | if not input_api.change.issue: |
| 862 | return [output_api.PresubmitError( |
| 863 | "DEPS approval by OWNERS check failed: this change has " |
| 864 | "no Rietveld issue number, so we can't check it for approvals.")] |
| 865 | output = output_api.PresubmitError |
| 866 | else: |
| 867 | output = output_api.PresubmitNotifyResult |
| 868 | |
| 869 | owners_db = input_api.owners_db |
| 870 | owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers( |
| 871 | input_api, |
| 872 | owners_db.email_regexp, |
| 873 | approval_needed=input_api.is_committing) |
| 874 | |
| 875 | owner_email = owner_email or input_api.change.author_email |
| 876 | |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 877 | reviewers_plus_owner = set(reviewers) |
[email protected] | e71c608 | 2013-05-22 02:28:51 | [diff] [blame] | 878 | if owner_email: |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 879 | reviewers_plus_owner.add(owner_email) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 880 | missing_files = owners_db.files_not_covered_by(virtual_depended_on_files, |
| 881 | reviewers_plus_owner) |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 882 | |
| 883 | # We strip the /DEPS part that was added by |
| 884 | # _FilesToCheckForIncomingDeps to fake a path to a file in a |
| 885 | # directory. |
| 886 | def StripDeps(path): |
| 887 | start_deps = path.rfind('/DEPS') |
| 888 | if start_deps != -1: |
| 889 | return path[:start_deps] |
| 890 | else: |
| 891 | return path |
| 892 | unapproved_dependencies = ["'+%s'," % StripDeps(path) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 893 | for path in missing_files] |
| 894 | |
| 895 | if unapproved_dependencies: |
| 896 | output_list = [ |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 897 | output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' % |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 898 | '\n '.join(sorted(unapproved_dependencies)))] |
| 899 | if not input_api.is_committing: |
| 900 | suggested_owners = owners_db.reviewers_for(missing_files, owner_email) |
| 901 | output_list.append(output( |
| 902 | 'Suggested missing target path OWNERS:\n %s' % |
| 903 | '\n '.join(suggested_owners or []))) |
| 904 | return output_list |
| 905 | |
| 906 | return [] |
| 907 | |
| 908 | |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 909 | def _CheckSpamLogging(input_api, output_api): |
| 910 | file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS |
| 911 | black_list = (_EXCLUDED_PATHS + |
| 912 | _TEST_CODE_EXCLUDED_PATHS + |
| 913 | input_api.DEFAULT_BLACK_LIST + |
[email protected] | 6f742dd0 | 2013-11-26 23:19:50 | [diff] [blame] | 914 | (r"^base[\\\/]logging\.h$", |
[email protected] | 80f360a | 2014-01-23 01:36:19 | [diff] [blame] | 915 | r"^base[\\\/]logging\.cc$", |
[email protected] | b364387 | 2014-02-11 23:29:39 | [diff] [blame] | 916 | r"^cloud_print[\\\/]", |
[email protected] | c80b3502 | 2014-03-03 17:01:41 | [diff] [blame] | 917 | r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$", |
[email protected] | 8dc338c | 2013-12-09 16:28:48 | [diff] [blame] | 918 | r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$", |
[email protected] | 6e268db | 2013-12-04 01:41:46 | [diff] [blame] | 919 | r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$", |
[email protected] | 4de7526 | 2013-12-18 23:16:12 | [diff] [blame] | 920 | r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]" |
| 921 | r"startup_browser_creator\.cc$", |
[email protected] | fe0e6e1 | 2013-12-04 05:52:58 | [diff] [blame] | 922 | r"^chrome[\\\/]installer[\\\/]setup[\\\/].*", |
[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 923 | r"^extensions[\\\/]renderer[\\\/]logging_native_handler\.cc$", |
[email protected] | 9056e73 | 2014-01-08 06:25:25 | [diff] [blame] | 924 | r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]" |
| 925 | r"gl_helper_benchmark\.cc$", |
[email protected] | 9c36d92 | 2014-03-24 16:47:52 | [diff] [blame] | 926 | r"^native_client_sdk[\\\/]", |
[email protected] | cdbdced | 2013-11-27 21:35:50 | [diff] [blame] | 927 | r"^remoting[\\\/]base[\\\/]logging\.h$", |
[email protected] | 67c96ab | 2013-12-17 02:05:36 | [diff] [blame] | 928 | r"^remoting[\\\/]host[\\\/].*", |
[email protected] | 8232f8fd | 2013-12-14 00:52:31 | [diff] [blame] | 929 | r"^sandbox[\\\/]linux[\\\/].*", |
[email protected] | 0b7a21e | 2014-02-11 18:38:13 | [diff] [blame] | 930 | r"^tools[\\\/]", |
[email protected] | 8232f8fd | 2013-12-14 00:52:31 | [diff] [blame] | 931 | r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",)) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 932 | source_file_filter = lambda x: input_api.FilterSourceFile( |
| 933 | x, white_list=(file_inclusion_pattern,), black_list=black_list) |
| 934 | |
| 935 | log_info = [] |
| 936 | printf = [] |
| 937 | |
| 938 | for f in input_api.AffectedSourceFiles(source_file_filter): |
| 939 | contents = input_api.ReadFile(f, 'rb') |
| 940 | if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): |
| 941 | log_info.append(f.LocalPath()) |
[email protected] | 18b466b | 2013-12-02 22:01:37 | [diff] [blame] | 942 | elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents): |
[email protected] | 8521065 | 2013-11-28 05:50:13 | [diff] [blame] | 943 | log_info.append(f.LocalPath()) |
[email protected] | 18b466b | 2013-12-02 22:01:37 | [diff] [blame] | 944 | |
| 945 | if re.search(r"\bprintf\(", contents): |
| 946 | printf.append(f.LocalPath()) |
| 947 | elif re.search(r"\bfprintf\((stdout|stderr)", contents): |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 948 | printf.append(f.LocalPath()) |
| 949 | |
| 950 | if log_info: |
| 951 | return [output_api.PresubmitError( |
| 952 | 'These files spam the console log with LOG(INFO):', |
| 953 | items=log_info)] |
| 954 | if printf: |
| 955 | return [output_api.PresubmitError( |
| 956 | 'These files spam the console log with printf/fprintf:', |
| 957 | items=printf)] |
| 958 | return [] |
| 959 | |
| 960 | |
[email protected] | 49aa76a | 2013-12-04 06:59:16 | [diff] [blame] | 961 | def _CheckForAnonymousVariables(input_api, output_api): |
| 962 | """These types are all expected to hold locks while in scope and |
| 963 | so should never be anonymous (which causes them to be immediately |
| 964 | destroyed).""" |
| 965 | they_who_must_be_named = [ |
| 966 | 'base::AutoLock', |
| 967 | 'base::AutoReset', |
| 968 | 'base::AutoUnlock', |
| 969 | 'SkAutoAlphaRestore', |
| 970 | 'SkAutoBitmapShaderInstall', |
| 971 | 'SkAutoBlitterChoose', |
| 972 | 'SkAutoBounderCommit', |
| 973 | 'SkAutoCallProc', |
| 974 | 'SkAutoCanvasRestore', |
| 975 | 'SkAutoCommentBlock', |
| 976 | 'SkAutoDescriptor', |
| 977 | 'SkAutoDisableDirectionCheck', |
| 978 | 'SkAutoDisableOvalCheck', |
| 979 | 'SkAutoFree', |
| 980 | 'SkAutoGlyphCache', |
| 981 | 'SkAutoHDC', |
| 982 | 'SkAutoLockColors', |
| 983 | 'SkAutoLockPixels', |
| 984 | 'SkAutoMalloc', |
| 985 | 'SkAutoMaskFreeImage', |
| 986 | 'SkAutoMutexAcquire', |
| 987 | 'SkAutoPathBoundsUpdate', |
| 988 | 'SkAutoPDFRelease', |
| 989 | 'SkAutoRasterClipValidate', |
| 990 | 'SkAutoRef', |
| 991 | 'SkAutoTime', |
| 992 | 'SkAutoTrace', |
| 993 | 'SkAutoUnref', |
| 994 | ] |
| 995 | anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named) |
| 996 | # bad: base::AutoLock(lock.get()); |
| 997 | # not bad: base::AutoLock lock(lock.get()); |
| 998 | bad_pattern = input_api.re.compile(anonymous) |
| 999 | # good: new base::AutoLock(lock.get()) |
| 1000 | good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous) |
| 1001 | errors = [] |
| 1002 | |
| 1003 | for f in input_api.AffectedFiles(): |
| 1004 | if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')): |
| 1005 | continue |
| 1006 | for linenum, line in f.ChangedContents(): |
| 1007 | if bad_pattern.search(line) and not good_pattern.search(line): |
| 1008 | errors.append('%s:%d' % (f.LocalPath(), linenum)) |
| 1009 | |
| 1010 | if errors: |
| 1011 | return [output_api.PresubmitError( |
| 1012 | 'These lines create anonymous variables that need to be named:', |
| 1013 | items=errors)] |
| 1014 | return [] |
| 1015 | |
| 1016 | |
[email protected] | 5fe0f874 | 2013-11-29 01:04:59 | [diff] [blame] | 1017 | def _CheckCygwinShell(input_api, output_api): |
| 1018 | source_file_filter = lambda x: input_api.FilterSourceFile( |
| 1019 | x, white_list=(r'.+\.(gyp|gypi)$',)) |
| 1020 | cygwin_shell = [] |
| 1021 | |
| 1022 | for f in input_api.AffectedSourceFiles(source_file_filter): |
| 1023 | for linenum, line in f.ChangedContents(): |
| 1024 | if 'msvs_cygwin_shell' in line: |
| 1025 | cygwin_shell.append(f.LocalPath()) |
| 1026 | break |
| 1027 | |
| 1028 | if cygwin_shell: |
| 1029 | return [output_api.PresubmitError( |
| 1030 | 'These files should not use msvs_cygwin_shell (the default is 0):', |
| 1031 | items=cygwin_shell)] |
| 1032 | return [] |
| 1033 | |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1034 | |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1035 | def _CheckUserActionUpdate(input_api, output_api): |
| 1036 | """Checks if any new user action has been added.""" |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1037 | if any('actions.xml' == input_api.os_path.basename(f) for f in |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1038 | input_api.LocalPaths()): |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1039 | # If actions.xml is already included in the changelist, the PRESUBMIT |
| 1040 | # for actions.xml will do a more complete presubmit check. |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1041 | return [] |
| 1042 | |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1043 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm')) |
| 1044 | action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)' |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1045 | current_actions = None |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1046 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1047 | for line_num, line in f.ChangedContents(): |
| 1048 | match = input_api.re.search(action_re, line) |
| 1049 | if match: |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1050 | # Loads contents in tools/metrics/actions/actions.xml to memory. It's |
| 1051 | # loaded only once. |
| 1052 | if not current_actions: |
| 1053 | with open('tools/metrics/actions/actions.xml') as actions_f: |
| 1054 | current_actions = actions_f.read() |
| 1055 | # Search for the matched user action name in |current_actions|. |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1056 | for action_name in match.groups(): |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1057 | action = 'name="{0}"'.format(action_name) |
| 1058 | if action not in current_actions: |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1059 | return [output_api.PresubmitPromptWarning( |
| 1060 | 'File %s line %d: %s is missing in ' |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1061 | 'tools/metrics/actions/actions.xml. Please run ' |
| 1062 | 'tools/metrics/actions/extract_actions.py to update.' |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1063 | % (f.LocalPath(), line_num, action_name))] |
| 1064 | return [] |
| 1065 | |
| 1066 | |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 1067 | def _GetJSONParseError(input_api, filename, eat_comments=True): |
| 1068 | try: |
| 1069 | contents = input_api.ReadFile(filename) |
| 1070 | if eat_comments: |
| 1071 | json_comment_eater = input_api.os_path.join( |
| 1072 | input_api.PresubmitLocalPath(), |
| 1073 | 'tools', 'json_comment_eater', 'json_comment_eater.py') |
| 1074 | process = input_api.subprocess.Popen( |
| 1075 | [input_api.python_executable, json_comment_eater], |
| 1076 | stdin=input_api.subprocess.PIPE, |
| 1077 | stdout=input_api.subprocess.PIPE, |
| 1078 | universal_newlines=True) |
| 1079 | (contents, _) = process.communicate(input=contents) |
| 1080 | |
| 1081 | input_api.json.loads(contents) |
| 1082 | except ValueError as e: |
| 1083 | return e |
| 1084 | return None |
| 1085 | |
| 1086 | |
| 1087 | def _GetIDLParseError(input_api, filename): |
| 1088 | try: |
| 1089 | contents = input_api.ReadFile(filename) |
| 1090 | idl_schema = input_api.os_path.join( |
| 1091 | input_api.PresubmitLocalPath(), |
| 1092 | 'tools', 'json_schema_compiler', 'idl_schema.py') |
| 1093 | process = input_api.subprocess.Popen( |
| 1094 | [input_api.python_executable, idl_schema], |
| 1095 | stdin=input_api.subprocess.PIPE, |
| 1096 | stdout=input_api.subprocess.PIPE, |
| 1097 | stderr=input_api.subprocess.PIPE, |
| 1098 | universal_newlines=True) |
| 1099 | (_, error) = process.communicate(input=contents) |
| 1100 | return error or None |
| 1101 | except ValueError as e: |
| 1102 | return e |
| 1103 | |
| 1104 | |
| 1105 | def _CheckParseErrors(input_api, output_api): |
| 1106 | """Check that IDL and JSON files do not contain syntax errors.""" |
| 1107 | actions = { |
| 1108 | '.idl': _GetIDLParseError, |
| 1109 | '.json': _GetJSONParseError, |
| 1110 | } |
| 1111 | # These paths contain test data and other known invalid JSON files. |
| 1112 | excluded_patterns = [ |
| 1113 | 'test/data/', |
| 1114 | '^components/policy/resources/policy_templates.json$', |
| 1115 | ] |
| 1116 | # Most JSON files are preprocessed and support comments, but these do not. |
| 1117 | json_no_comments_patterns = [ |
| 1118 | '^testing/', |
| 1119 | ] |
| 1120 | # Only run IDL checker on files in these directories. |
| 1121 | idl_included_patterns = [ |
| 1122 | '^chrome/common/extensions/api/', |
| 1123 | '^extensions/common/api/', |
| 1124 | ] |
| 1125 | |
| 1126 | def get_action(affected_file): |
| 1127 | filename = affected_file.LocalPath() |
| 1128 | return actions.get(input_api.os_path.splitext(filename)[1]) |
| 1129 | |
| 1130 | def MatchesFile(patterns, path): |
| 1131 | for pattern in patterns: |
| 1132 | if input_api.re.search(pattern, path): |
| 1133 | return True |
| 1134 | return False |
| 1135 | |
| 1136 | def FilterFile(affected_file): |
| 1137 | action = get_action(affected_file) |
| 1138 | if not action: |
| 1139 | return False |
| 1140 | path = affected_file.LocalPath() |
| 1141 | |
| 1142 | if MatchesFile(excluded_patterns, path): |
| 1143 | return False |
| 1144 | |
| 1145 | if (action == _GetIDLParseError and |
| 1146 | not MatchesFile(idl_included_patterns, path)): |
| 1147 | return False |
| 1148 | return True |
| 1149 | |
| 1150 | results = [] |
| 1151 | for affected_file in input_api.AffectedFiles( |
| 1152 | file_filter=FilterFile, include_deletes=False): |
| 1153 | action = get_action(affected_file) |
| 1154 | kwargs = {} |
| 1155 | if (action == _GetJSONParseError and |
| 1156 | MatchesFile(json_no_comments_patterns, affected_file.LocalPath())): |
| 1157 | kwargs['eat_comments'] = False |
| 1158 | parse_error = action(input_api, |
| 1159 | affected_file.AbsoluteLocalPath(), |
| 1160 | **kwargs) |
| 1161 | if parse_error: |
| 1162 | results.append(output_api.PresubmitError('%s could not be parsed: %s' % |
| 1163 | (affected_file.LocalPath(), parse_error))) |
| 1164 | return results |
| 1165 | |
| 1166 | |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 1167 | def _CheckJavaStyle(input_api, output_api): |
| 1168 | """Runs checkstyle on changed java files and returns errors if any exist.""" |
| 1169 | original_sys_path = sys.path |
| 1170 | try: |
| 1171 | sys.path = sys.path + [input_api.os_path.join( |
| 1172 | input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] |
| 1173 | import checkstyle |
| 1174 | finally: |
| 1175 | # Restore sys.path to what it was before. |
| 1176 | sys.path = original_sys_path |
| 1177 | |
| 1178 | return checkstyle.RunCheckstyle( |
| 1179 | input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml') |
| 1180 | |
| 1181 | |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 1182 | _DEPRECATED_CSS = [ |
| 1183 | # Values |
| 1184 | ( "-webkit-box", "flex" ), |
| 1185 | ( "-webkit-inline-box", "inline-flex" ), |
| 1186 | ( "-webkit-flex", "flex" ), |
| 1187 | ( "-webkit-inline-flex", "inline-flex" ), |
| 1188 | ( "-webkit-min-content", "min-content" ), |
| 1189 | ( "-webkit-max-content", "max-content" ), |
| 1190 | |
| 1191 | # Properties |
| 1192 | ( "-webkit-background-clip", "background-clip" ), |
| 1193 | ( "-webkit-background-origin", "background-origin" ), |
| 1194 | ( "-webkit-background-size", "background-size" ), |
| 1195 | ( "-webkit-box-shadow", "box-shadow" ), |
| 1196 | |
| 1197 | # Functions |
| 1198 | ( "-webkit-gradient", "gradient" ), |
| 1199 | ( "-webkit-repeating-gradient", "repeating-gradient" ), |
| 1200 | ( "-webkit-linear-gradient", "linear-gradient" ), |
| 1201 | ( "-webkit-repeating-linear-gradient", "repeating-linear-gradient" ), |
| 1202 | ( "-webkit-radial-gradient", "radial-gradient" ), |
| 1203 | ( "-webkit-repeating-radial-gradient", "repeating-radial-gradient" ), |
| 1204 | ] |
| 1205 | |
| 1206 | def _CheckNoDeprecatedCSS(input_api, output_api): |
| 1207 | """ Make sure that we don't use deprecated CSS |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 1208 | properties, functions or values. Our external |
| 1209 | documentation is ignored by the hooks as it |
| 1210 | needs to be consumed by WebKit. """ |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 1211 | results = [] |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 1212 | file_inclusion_pattern = (r".+\.css$") |
| 1213 | black_list = (_EXCLUDED_PATHS + |
| 1214 | _TEST_CODE_EXCLUDED_PATHS + |
| 1215 | input_api.DEFAULT_BLACK_LIST + |
| 1216 | (r"^chrome/common/extensions/docs", |
| 1217 | r"^chrome/docs", |
| 1218 | r"^native_client_sdk")) |
| 1219 | file_filter = lambda f: input_api.FilterSourceFile( |
| 1220 | f, white_list=file_inclusion_pattern, black_list=black_list) |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 1221 | for fpath in input_api.AffectedFiles(file_filter=file_filter): |
| 1222 | for line_num, line in fpath.ChangedContents(): |
| 1223 | for (deprecated_value, value) in _DEPRECATED_CSS: |
| 1224 | if input_api.re.search(deprecated_value, line): |
| 1225 | results.append(output_api.PresubmitError( |
| 1226 | "%s:%d: Use of deprecated CSS %s, use %s instead" % |
| 1227 | (fpath.LocalPath(), line_num, deprecated_value, value))) |
| 1228 | return results |
| 1229 | |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 1230 | def _CommonChecks(input_api, output_api): |
| 1231 | """Checks common to both upload and commit.""" |
| 1232 | results = [] |
| 1233 | results.extend(input_api.canned_checks.PanProjectChecks( |
[email protected] | 3de922f | 2013-12-20 13:27:38 | [diff] [blame] | 1234 | input_api, output_api, |
| 1235 | excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1236 | results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1237 | results.extend( |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 1238 | _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 1239 | results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 1240 | results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1241 | results.extend(_CheckNoNewWStrings(input_api, output_api)) |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 1242 | results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1243 | results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 1244 | results.extend(_CheckNoPragmaOnce(input_api, output_api)) |
[email protected] | e747905 | 2012-09-19 00:26:12 | [diff] [blame] | 1245 | results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1246 | results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 1247 | results.extend(_CheckFilePermissions(input_api, output_api)) |
[email protected] | c8278b3 | 2012-10-30 20:35:49 | [diff] [blame] | 1248 | results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) |
[email protected] | 2309b0fa0 | 2012-11-16 12:18:27 | [diff] [blame] | 1249 | results.extend(_CheckIncludeOrder(input_api, output_api)) |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 1250 | results.extend(_CheckForVersionControlConflicts(input_api, output_api)) |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 1251 | results.extend(_CheckPatchFiles(input_api, output_api)) |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 1252 | results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 1253 | results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api)) |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1254 | results.extend(_CheckForInvalidOSMacros(input_api, output_api)) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1255 | results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) |
[email protected] | 9f919cc | 2013-07-31 03:04:04 | [diff] [blame] | 1256 | results.extend( |
| 1257 | input_api.canned_checks.CheckChangeHasNoTabs( |
| 1258 | input_api, |
| 1259 | output_api, |
| 1260 | source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1261 | results.extend(_CheckSpamLogging(input_api, output_api)) |
[email protected] | 49aa76a | 2013-12-04 06:59:16 | [diff] [blame] | 1262 | results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
[email protected] | 5fe0f874 | 2013-11-29 01:04:59 | [diff] [blame] | 1263 | results.extend(_CheckCygwinShell(input_api, output_api)) |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1264 | results.extend(_CheckUserActionUpdate(input_api, output_api)) |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 1265 | results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 1266 | results.extend(_CheckParseErrors(input_api, output_api)) |
[email protected] | 2299dcf | 2012-11-15 19:56:24 | [diff] [blame] | 1267 | |
| 1268 | if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
| 1269 | results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 1270 | input_api, output_api, |
| 1271 | input_api.PresubmitLocalPath(), |
[email protected] | 6be6338 | 2013-01-21 15:42:38 | [diff] [blame] | 1272 | whitelist=[r'^PRESUBMIT_test\.py$'])) |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 1273 | return results |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 1274 | |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 1275 | |
| 1276 | def _CheckSubversionConfig(input_api, output_api): |
| 1277 | """Verifies the subversion config file is correctly setup. |
| 1278 | |
| 1279 | Checks that autoprops are enabled, returns an error otherwise. |
| 1280 | """ |
| 1281 | join = input_api.os_path.join |
| 1282 | if input_api.platform == 'win32': |
| 1283 | appdata = input_api.environ.get('APPDATA', '') |
| 1284 | if not appdata: |
| 1285 | return [output_api.PresubmitError('%APPDATA% is not configured.')] |
| 1286 | path = join(appdata, 'Subversion', 'config') |
| 1287 | else: |
| 1288 | home = input_api.environ.get('HOME', '') |
| 1289 | if not home: |
| 1290 | return [output_api.PresubmitError('$HOME is not configured.')] |
| 1291 | path = join(home, '.subversion', 'config') |
| 1292 | |
| 1293 | error_msg = ( |
| 1294 | 'Please look at http://dev.chromium.org/developers/coding-style to\n' |
| 1295 | 'configure your subversion configuration file. This enables automatic\n' |
[email protected] | c6a3c10b | 2011-01-24 16:14:20 | [diff] [blame] | 1296 | 'properties to simplify the project maintenance.\n' |
| 1297 | 'Pro-tip: just download and install\n' |
| 1298 | 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n') |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 1299 | |
| 1300 | try: |
| 1301 | lines = open(path, 'r').read().splitlines() |
| 1302 | # Make sure auto-props is enabled and check for 2 Chromium standard |
| 1303 | # auto-prop. |
| 1304 | if (not '*.cc = svn:eol-style=LF' in lines or |
| 1305 | not '*.pdf = svn:mime-type=application/pdf' in lines or |
| 1306 | not 'enable-auto-props = yes' in lines): |
| 1307 | return [ |
[email protected] | 79ed7e6 | 2011-02-21 21:08:53 | [diff] [blame] | 1308 | output_api.PresubmitNotifyResult( |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 1309 | 'It looks like you have not configured your subversion config ' |
[email protected] | b5359c0 | 2011-02-01 20:29:56 | [diff] [blame] | 1310 | 'file or it is not up-to-date.\n' + error_msg) |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 1311 | ] |
| 1312 | except (OSError, IOError): |
| 1313 | return [ |
[email protected] | 79ed7e6 | 2011-02-21 21:08:53 | [diff] [blame] | 1314 | output_api.PresubmitNotifyResult( |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 1315 | 'Can\'t find your subversion config file.\n' + error_msg) |
| 1316 | ] |
| 1317 | return [] |
| 1318 | |
| 1319 | |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1320 | def _CheckAuthorizedAuthor(input_api, output_api): |
| 1321 | """For non-googler/chromites committers, verify the author's email address is |
| 1322 | in AUTHORS. |
| 1323 | """ |
[email protected] | 9bb9cb8 | 2011-06-13 20:43:01 | [diff] [blame] | 1324 | # TODO(maruel): Add it to input_api? |
| 1325 | import fnmatch |
| 1326 | |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1327 | author = input_api.change.author_email |
[email protected] | 9bb9cb8 | 2011-06-13 20:43:01 | [diff] [blame] | 1328 | if not author: |
| 1329 | input_api.logging.info('No author, skipping AUTHOR check') |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1330 | return [] |
[email protected] | c9966329 | 2011-05-31 19:46:08 | [diff] [blame] | 1331 | authors_path = input_api.os_path.join( |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1332 | input_api.PresubmitLocalPath(), 'AUTHORS') |
| 1333 | valid_authors = ( |
| 1334 | input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line) |
| 1335 | for line in open(authors_path)) |
[email protected] | ac54b13 | 2011-06-06 18:11:18 | [diff] [blame] | 1336 | valid_authors = [item.group(1).lower() for item in valid_authors if item] |
[email protected] | d8b50be | 2011-06-15 14:19:44 | [diff] [blame] | 1337 | if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors): |
[email protected] | 5861efb | 2013-01-07 18:33:23 | [diff] [blame] | 1338 | input_api.logging.info('Valid authors are %s', ', '.join(valid_authors)) |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1339 | return [output_api.PresubmitPromptWarning( |
| 1340 | ('%s is not in AUTHORS file. If you are a new contributor, please visit' |
| 1341 | '\n' |
| 1342 | 'http://www.chromium.org/developers/contributing-code and read the ' |
| 1343 | '"Legal" section\n' |
| 1344 | 'If you are a chromite, verify the contributor signed the CLA.') % |
| 1345 | author)] |
| 1346 | return [] |
| 1347 | |
| 1348 | |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 1349 | def _CheckPatchFiles(input_api, output_api): |
| 1350 | problems = [f.LocalPath() for f in input_api.AffectedFiles() |
| 1351 | if f.LocalPath().endswith(('.orig', '.rej'))] |
| 1352 | if problems: |
| 1353 | return [output_api.PresubmitError( |
| 1354 | "Don't commit .rej and .orig files.", problems)] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 1355 | else: |
| 1356 | return [] |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 1357 | |
| 1358 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1359 | def _DidYouMeanOSMacro(bad_macro): |
| 1360 | try: |
| 1361 | return {'A': 'OS_ANDROID', |
| 1362 | 'B': 'OS_BSD', |
| 1363 | 'C': 'OS_CHROMEOS', |
| 1364 | 'F': 'OS_FREEBSD', |
| 1365 | 'L': 'OS_LINUX', |
| 1366 | 'M': 'OS_MACOSX', |
| 1367 | 'N': 'OS_NACL', |
| 1368 | 'O': 'OS_OPENBSD', |
| 1369 | 'P': 'OS_POSIX', |
| 1370 | 'S': 'OS_SOLARIS', |
| 1371 | 'W': 'OS_WIN'}[bad_macro[3].upper()] |
| 1372 | except KeyError: |
| 1373 | return '' |
| 1374 | |
| 1375 | |
| 1376 | def _CheckForInvalidOSMacrosInFile(input_api, f): |
| 1377 | """Check for sensible looking, totally invalid OS macros.""" |
| 1378 | preprocessor_statement = input_api.re.compile(r'^\s*#') |
| 1379 | os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)') |
| 1380 | results = [] |
| 1381 | for lnum, line in f.ChangedContents(): |
| 1382 | if preprocessor_statement.search(line): |
| 1383 | for match in os_macro.finditer(line): |
| 1384 | if not match.group(1) in _VALID_OS_MACROS: |
| 1385 | good = _DidYouMeanOSMacro(match.group(1)) |
| 1386 | did_you_mean = ' (did you mean %s?)' % good if good else '' |
| 1387 | results.append(' %s:%d %s%s' % (f.LocalPath(), |
| 1388 | lnum, |
| 1389 | match.group(1), |
| 1390 | did_you_mean)) |
| 1391 | return results |
| 1392 | |
| 1393 | |
| 1394 | def _CheckForInvalidOSMacros(input_api, output_api): |
| 1395 | """Check all affected files for invalid OS macros.""" |
| 1396 | bad_macros = [] |
| 1397 | for f in input_api.AffectedFiles(): |
| 1398 | if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')): |
| 1399 | bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f)) |
| 1400 | |
| 1401 | if not bad_macros: |
| 1402 | return [] |
| 1403 | |
| 1404 | return [output_api.PresubmitError( |
| 1405 | 'Possibly invalid OS macro[s] found. Please fix your code\n' |
| 1406 | 'or add your macro to src/PRESUBMIT.py.', bad_macros)] |
| 1407 | |
| 1408 | |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 1409 | def CheckChangeOnUpload(input_api, output_api): |
| 1410 | results = [] |
| 1411 | results.extend(_CommonChecks(input_api, output_api)) |
[email protected] | ae69ae7 | 2014-02-20 13:09:36 | [diff] [blame] | 1412 | results.extend(_CheckJavaStyle(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 1413 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 1414 | |
| 1415 | |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1416 | def GetTryServerMasterForBot(bot): |
| 1417 | """Returns the Try Server master for the given bot. |
| 1418 | |
| 1419 | Assumes that most Try Servers are on the tryserver.chromium master.""" |
| 1420 | non_default_master_map = { |
| 1421 | 'linux_gpu': 'tryserver.chromium.gpu', |
[email protected] | 5c5f1304 | 2014-05-09 21:28:30 | [diff] [blame] | 1422 | 'mac_gpu': 'tryserver.chromium.gpu', |
[email protected] | d263d5b | 2014-04-30 01:15:55 | [diff] [blame] | 1423 | 'win_gpu': 'tryserver.chromium.gpu', |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1424 | } |
| 1425 | return non_default_master_map.get(bot, 'tryserver.chromium') |
| 1426 | |
| 1427 | |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1428 | def GetDefaultTryConfigs(bots=None): |
| 1429 | """Returns a list of ('bot', set(['tests']), optionally filtered by [bots]. |
| 1430 | |
| 1431 | To add tests to this list, they MUST be in the the corresponding master's |
| 1432 | gatekeeper config. For example, anything on master.chromium would be closed by |
| 1433 | tools/build/masters/master.chromium/master_gatekeeper_cfg.py. |
| 1434 | |
| 1435 | If 'bots' is specified, will only return configurations for bots in that list. |
| 1436 | """ |
| 1437 | |
| 1438 | standard_tests = [ |
| 1439 | 'base_unittests', |
| 1440 | 'browser_tests', |
| 1441 | 'cacheinvalidation_unittests', |
| 1442 | 'check_deps', |
| 1443 | 'check_deps2git', |
| 1444 | 'content_browsertests', |
| 1445 | 'content_unittests', |
| 1446 | 'crypto_unittests', |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1447 | 'gpu_unittests', |
| 1448 | 'interactive_ui_tests', |
| 1449 | 'ipc_tests', |
| 1450 | 'jingle_unittests', |
| 1451 | 'media_unittests', |
| 1452 | 'net_unittests', |
| 1453 | 'ppapi_unittests', |
| 1454 | 'printing_unittests', |
| 1455 | 'sql_unittests', |
| 1456 | 'sync_unit_tests', |
| 1457 | 'unit_tests', |
| 1458 | # Broken in release. |
| 1459 | #'url_unittests', |
| 1460 | #'webkit_unit_tests', |
| 1461 | ] |
| 1462 | |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1463 | builders_and_tests = { |
| 1464 | # TODO(maruel): Figure out a way to run 'sizes' where people can |
| 1465 | # effectively update the perf expectation correctly. This requires a |
| 1466 | # clobber=True build running 'sizes'. 'sizes' is not accurate with |
| 1467 | # incremental build. Reference: |
| 1468 | # http://chromium.org/developers/tree-sheriffs/perf-sheriffs. |
| 1469 | # TODO(maruel): An option would be to run 'sizes' but not count a failure |
| 1470 | # of this step as a try job failure. |
| 1471 | 'android_aosp': ['compile'], |
[email protected] | 5a65d304 | 2014-05-07 14:26:01 | [diff] [blame] | 1472 | 'android_chromium_gn_compile_rel': ['compile'], |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1473 | 'android_clang_dbg': ['slave_steps'], |
| 1474 | 'android_dbg': ['slave_steps'], |
| 1475 | 'cros_x86': ['defaulttests'], |
| 1476 | 'ios_dbg_simulator': [ |
| 1477 | 'compile', |
| 1478 | 'base_unittests', |
| 1479 | 'content_unittests', |
| 1480 | 'crypto_unittests', |
| 1481 | 'url_unittests', |
| 1482 | 'net_unittests', |
| 1483 | 'sql_unittests', |
| 1484 | 'ui_unittests', |
| 1485 | ], |
| 1486 | 'ios_rel_device': ['compile'], |
[email protected] | 971b08ce | 2014-03-19 22:03:56 | [diff] [blame] | 1487 | 'linux_asan': ['compile'], |
| 1488 | 'mac_asan': ['compile'], |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1489 | #TODO(stip): Change the name of this builder to reflect that it's release. |
[email protected] | 71afb4ec | 2014-02-07 02:45:13 | [diff] [blame] | 1490 | 'linux_gtk': standard_tests, |
[email protected] | 971b08ce | 2014-03-19 22:03:56 | [diff] [blame] | 1491 | 'linux_chromeos_asan': ['compile'], |
[email protected] | d910b608 | 2014-02-27 18:15:43 | [diff] [blame] | 1492 | 'linux_chromium_chromeos_clang_dbg': ['defaulttests'], |
| 1493 | 'linux_chromium_chromeos_rel': ['defaulttests'], |
| 1494 | 'linux_chromium_compile_dbg': ['defaulttests'], |
[email protected] | 5a65d304 | 2014-05-07 14:26:01 | [diff] [blame] | 1495 | 'linux_chromium_gn_rel': ['defaulttests'], |
[email protected] | 23c81d55 | 2014-01-07 13:45:46 | [diff] [blame] | 1496 | 'linux_chromium_rel': ['defaulttests'], |
[email protected] | d910b608 | 2014-02-27 18:15:43 | [diff] [blame] | 1497 | 'linux_chromium_clang_dbg': ['defaulttests'], |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1498 | 'linux_gpu': ['defaulttests'], |
[email protected] | 9780bac | 2014-01-11 00:12:02 | [diff] [blame] | 1499 | 'linux_nacl_sdk_build': ['compile'], |
[email protected] | d910b608 | 2014-02-27 18:15:43 | [diff] [blame] | 1500 | 'linux_rel': [ |
[email protected] | 9021a5f7 | 2014-01-24 19:02:38 | [diff] [blame] | 1501 | 'telemetry_perf_unittests', |
| 1502 | 'telemetry_unittests', |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1503 | ], |
[email protected] | d910b608 | 2014-02-27 18:15:43 | [diff] [blame] | 1504 | 'mac_chromium_compile_dbg': ['defaulttests'], |
[email protected] | 23c81d55 | 2014-01-07 13:45:46 | [diff] [blame] | 1505 | 'mac_chromium_rel': ['defaulttests'], |
[email protected] | 5c5f1304 | 2014-05-09 21:28:30 | [diff] [blame] | 1506 | 'mac_gpu': ['defaulttests'], |
[email protected] | 9780bac | 2014-01-11 00:12:02 | [diff] [blame] | 1507 | 'mac_nacl_sdk_build': ['compile'], |
[email protected] | d910b608 | 2014-02-27 18:15:43 | [diff] [blame] | 1508 | 'mac_rel': [ |
[email protected] | 9021a5f7 | 2014-01-24 19:02:38 | [diff] [blame] | 1509 | 'telemetry_perf_unittests', |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1510 | 'telemetry_unittests', |
| 1511 | ], |
| 1512 | 'win': ['compile'], |
[email protected] | 0094fa1 | 2014-03-13 03:18:28 | [diff] [blame] | 1513 | 'win_chromium_compile_dbg': ['defaulttests'], |
[email protected] | c17144e4 | 2014-04-15 09:32:43 | [diff] [blame] | 1514 | 'win_chromium_dbg': ['defaulttests'], |
| 1515 | 'win_chromium_rel': ['defaulttests'], |
[email protected] | 2a20716 | 2014-04-15 17:05:30 | [diff] [blame] | 1516 | 'win_chromium_x64_rel': ['defaulttests'], |
[email protected] | d263d5b | 2014-04-30 01:15:55 | [diff] [blame] | 1517 | 'win_gpu': ['defaulttests'], |
[email protected] | 9780bac | 2014-01-11 00:12:02 | [diff] [blame] | 1518 | 'win_nacl_sdk_build': ['compile'], |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1519 | 'win_rel': standard_tests + [ |
| 1520 | 'app_list_unittests', |
| 1521 | 'ash_unittests', |
| 1522 | 'aura_unittests', |
| 1523 | 'cc_unittests', |
| 1524 | 'chrome_elf_unittests', |
[email protected] | 5d0413fc | 2014-01-03 18:24:30 | [diff] [blame] | 1525 | 'chromedriver_unittests', |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1526 | 'components_unittests', |
| 1527 | 'compositor_unittests', |
| 1528 | 'events_unittests', |
[email protected] | 0df555e | 2014-02-27 14:53:11 | [diff] [blame] | 1529 | 'gfx_unittests', |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1530 | 'google_apis_unittests', |
| 1531 | 'installer_util_unittests', |
[email protected] | 7982972 | 2014-06-02 16:44:44 | [diff] [blame] | 1532 | 'test_mini_installer', |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1533 | 'nacl_integration', |
| 1534 | 'remoting_unittests', |
| 1535 | 'sync_integration_tests', |
[email protected] | 9021a5f7 | 2014-01-24 19:02:38 | [diff] [blame] | 1536 | 'telemetry_perf_unittests', |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1537 | 'telemetry_unittests', |
| 1538 | 'views_unittests', |
| 1539 | ], |
| 1540 | 'win_x64_rel': [ |
| 1541 | 'base_unittests', |
| 1542 | ], |
| 1543 | } |
| 1544 | |
| 1545 | swarm_enabled_builders = ( |
[email protected] | 9714f3b | 2014-03-20 19:50:11 | [diff] [blame] | 1546 | # http://crbug.com/354263 |
| 1547 | # 'linux_rel', |
| 1548 | # 'mac_rel', |
| 1549 | # 'win_rel', |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1550 | ) |
| 1551 | |
| 1552 | swarm_enabled_tests = ( |
| 1553 | 'base_unittests', |
| 1554 | 'browser_tests', |
| 1555 | 'interactive_ui_tests', |
| 1556 | 'net_unittests', |
| 1557 | 'unit_tests', |
| 1558 | ) |
| 1559 | |
| 1560 | for bot in builders_and_tests: |
| 1561 | if bot in swarm_enabled_builders: |
| 1562 | builders_and_tests[bot] = [x + '_swarm' if x in swarm_enabled_tests else x |
| 1563 | for x in builders_and_tests[bot]] |
| 1564 | |
| 1565 | if bots: |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1566 | filtered_builders_and_tests = dict((bot, set(builders_and_tests[bot])) |
| 1567 | for bot in bots) |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1568 | else: |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1569 | filtered_builders_and_tests = dict( |
| 1570 | (bot, set(tests)) |
| 1571 | for bot, tests in builders_and_tests.iteritems()) |
| 1572 | |
| 1573 | # Build up the mapping from tryserver master to bot/test. |
| 1574 | out = dict() |
| 1575 | for bot, tests in filtered_builders_and_tests.iteritems(): |
| 1576 | out.setdefault(GetTryServerMasterForBot(bot), {})[bot] = tests |
| 1577 | return out |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1578 | |
| 1579 | |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 1580 | def CheckChangeOnCommit(input_api, output_api): |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 1581 | results = [] |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 1582 | results.extend(_CommonChecks(input_api, output_api)) |
[email protected] | dd805fe | 2009-10-01 08:11:51 | [diff] [blame] | 1583 | # TODO(thestig) temporarily disabled, doesn't work in third_party/ |
| 1584 | #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories( |
| 1585 | # input_api, output_api, sources)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 1586 | # Make sure the tree is 'open'. |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 1587 | results.extend(input_api.canned_checks.CheckTreeIsOpen( |
[email protected] | 7f23815 | 2009-08-12 19:00:34 | [diff] [blame] | 1588 | input_api, |
| 1589 | output_api, |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 1590 | json_url='http://chromium-status.appspot.com/current?format=json')) |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 1591 | |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 1592 | results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 1593 | input_api, output_api)) |
[email protected] | c4b4756 | 2011-12-05 23:39:41 | [diff] [blame] | 1594 | results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 1595 | input_api, output_api)) |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 1596 | results.extend(_CheckSubversionConfig(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 1597 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 1598 | |
| 1599 | |
[email protected] | 7468ac52 | 2014-03-12 23:35:57 | [diff] [blame] | 1600 | def GetPreferredTryMasters(project, change): |
[email protected] | 4ce995ea | 2012-06-27 02:13:10 | [diff] [blame] | 1601 | files = change.LocalPaths() |
| 1602 | |
[email protected] | 751b05f | 2013-01-10 23:12:17 | [diff] [blame] | 1603 | if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files): |
[email protected] | 7468ac52 | 2014-03-12 23:35:57 | [diff] [blame] | 1604 | return {} |
[email protected] | 3019c90 | 2012-06-29 00:09:03 | [diff] [blame] | 1605 | |
[email protected] | d668899a | 2012-09-06 18:16:59 | [diff] [blame] | 1606 | if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files): |
[email protected] | d96b1f4 | 2014-02-27 19:17:52 | [diff] [blame] | 1607 | return GetDefaultTryConfigs([ |
| 1608 | 'mac_chromium_compile_dbg', |
| 1609 | 'mac_chromium_rel', |
[email protected] | d96b1f4 | 2014-02-27 19:17:52 | [diff] [blame] | 1610 | ]) |
[email protected] | d668899a | 2012-09-06 18:16:59 | [diff] [blame] | 1611 | if all(re.search('(^|[/_])win[/_.]', f) for f in files): |
[email protected] | c17144e4 | 2014-04-15 09:32:43 | [diff] [blame] | 1612 | return GetDefaultTryConfigs(['win_chromium_dbg', 'win_chromium_rel']) |
[email protected] | d668899a | 2012-09-06 18:16:59 | [diff] [blame] | 1613 | if all(re.search('(^|[/_])android[/_.]', f) for f in files): |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1614 | return GetDefaultTryConfigs([ |
| 1615 | 'android_aosp', |
| 1616 | 'android_clang_dbg', |
| 1617 | 'android_dbg', |
| 1618 | ]) |
[email protected] | de14215 | 2012-10-03 23:02:45 | [diff] [blame] | 1619 | if all(re.search('[/_]ios[/_.]', f) for f in files): |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1620 | return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator']) |
[email protected] | 4ce995ea | 2012-06-27 02:13:10 | [diff] [blame] | 1621 | |
[email protected] | 7468ac52 | 2014-03-12 23:35:57 | [diff] [blame] | 1622 | builders = [ |
[email protected] | 5a65d304 | 2014-05-07 14:26:01 | [diff] [blame] | 1623 | 'android_chromium_gn_compile_rel', |
[email protected] | 3e2f040 | 2012-11-02 16:28:01 | [diff] [blame] | 1624 | 'android_clang_dbg', |
| 1625 | 'android_dbg', |
| 1626 | 'ios_dbg_simulator', |
| 1627 | 'ios_rel_device', |
[email protected] | d96b1f4 | 2014-02-27 19:17:52 | [diff] [blame] | 1628 | 'linux_chromium_chromeos_rel', |
| 1629 | 'linux_chromium_clang_dbg', |
[email protected] | 5a65d304 | 2014-05-07 14:26:01 | [diff] [blame] | 1630 | 'linux_chromium_gn_rel', |
[email protected] | d96b1f4 | 2014-02-27 19:17:52 | [diff] [blame] | 1631 | 'linux_chromium_rel', |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1632 | 'linux_gpu', |
[email protected] | d96b1f4 | 2014-02-27 19:17:52 | [diff] [blame] | 1633 | 'mac_chromium_compile_dbg', |
[email protected] | d96b1f4 | 2014-02-27 19:17:52 | [diff] [blame] | 1634 | 'mac_chromium_rel', |
[email protected] | 5c5f1304 | 2014-05-09 21:28:30 | [diff] [blame] | 1635 | 'mac_gpu', |
[email protected] | 0094fa1 | 2014-03-13 03:18:28 | [diff] [blame] | 1636 | 'win_chromium_compile_dbg', |
[email protected] | c17144e4 | 2014-04-15 09:32:43 | [diff] [blame] | 1637 | 'win_chromium_rel', |
[email protected] | 2a20716 | 2014-04-15 17:05:30 | [diff] [blame] | 1638 | 'win_chromium_x64_rel', |
[email protected] | d263d5b | 2014-04-30 01:15:55 | [diff] [blame] | 1639 | 'win_gpu', |
[email protected] | 7468ac52 | 2014-03-12 23:35:57 | [diff] [blame] | 1640 | ] |
[email protected] | 911753b | 2012-08-02 12:11:54 | [diff] [blame] | 1641 | |
| 1642 | # Match things like path/aura/file.cc and path/file_aura.cc. |
[email protected] | 95c98916 | 2012-11-29 05:58:25 | [diff] [blame] | 1643 | # Same for chromeos. |
| 1644 | if any(re.search('[/_](aura|chromeos)', f) for f in files): |
[email protected] | 7468ac52 | 2014-03-12 23:35:57 | [diff] [blame] | 1645 | builders.extend([ |
| 1646 | 'linux_chromeos_asan', |
| 1647 | 'linux_chromium_chromeos_clang_dbg' |
| 1648 | ]) |
[email protected] | 4ce995ea | 2012-06-27 02:13:10 | [diff] [blame] | 1649 | |
[email protected] | e8df48f | 2013-09-30 20:07:54 | [diff] [blame] | 1650 | # If there are gyp changes to base, build, or chromeos, run a full cros build |
| 1651 | # in addition to the shorter linux_chromeos build. Changes to high level gyp |
| 1652 | # files have a much higher chance of breaking the cros build, which is |
| 1653 | # differnt from the linux_chromeos build that most chrome developers test |
| 1654 | # with. |
| 1655 | if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files): |
[email protected] | 7468ac52 | 2014-03-12 23:35:57 | [diff] [blame] | 1656 | builders.extend(['cros_x86']) |
[email protected] | e8df48f | 2013-09-30 20:07:54 | [diff] [blame] | 1657 | |
[email protected] | d95948ef | 2013-07-02 10:51:00 | [diff] [blame] | 1658 | # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it |
| 1659 | # unless they're .gyp(i) files as changes to those files can break the gyp |
| 1660 | # step on that bot. |
| 1661 | if (not all(re.search('^chrome', f) for f in files) or |
| 1662 | any(re.search('\.gypi?$', f) for f in files)): |
[email protected] | 7468ac52 | 2014-03-12 23:35:57 | [diff] [blame] | 1663 | builders.extend(['android_aosp']) |
[email protected] | d95948ef | 2013-07-02 10:51:00 | [diff] [blame] | 1664 | |
[email protected] | 7468ac52 | 2014-03-12 23:35:57 | [diff] [blame] | 1665 | return GetDefaultTryConfigs(builders) |