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