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