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