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