blob: 9cfda61bead41b96225a7eeb41b92523e519381c [file] [log] [blame]
[email protected]a18130a2012-01-03 17:52:081# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ca8d1982009-02-19 16:33:122# 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]f1293792009-07-31 18:09:567See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
[email protected]50d7d721e2009-11-15 17:56:188for more details about the presubmit API built into gcl.
[email protected]ca8d1982009-02-19 16:33:129"""
10
[email protected]eea609a2011-11-18 13:10:1211
[email protected]9d16ad12011-12-14 20:49:4712import re
[email protected]55f9f382012-07-31 11:02:1813import sys
[email protected]9d16ad12011-12-14 20:49:4714
15
[email protected]379e7dd2010-01-28 17:39:2116_EXCLUDED_PATHS = (
[email protected]3e4eb112011-01-18 03:29:5417 r"^breakpad[\\\/].*",
[email protected]40d1dbb2012-10-26 07:18:0018 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
19 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
[email protected]8886ffcb2013-02-12 04:56:2820 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
[email protected]a18130a2012-01-03 17:52:0821 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
[email protected]3e4eb112011-01-18 03:29:5422 r"^skia[\\\/].*",
23 r"^v8[\\\/].*",
24 r".*MakeFile$",
[email protected]1084ccc2012-03-14 03:22:5325 r".+_autogen\.h$",
[email protected]ce145c02012-09-06 09:49:3426 r".+[\\\/]pnacl_shim\.c$",
[email protected]e07b6ac72013-08-20 00:30:4227 r"^gpu[\\\/]config[\\\/].*_list_json\.cc$",
[email protected]4306417642009-06-11 00:33:4028)
[email protected]ca8d1982009-02-19 16:33:1229
[email protected]de28fed2e2014-02-01 14:36:3230# TestRunner and NetscapePlugIn library is temporarily excluded from pan-project
31# checks until it's transitioned to chromium coding style.
[email protected]3de922f2013-12-20 13:27:3832_TESTRUNNER_PATHS = (
33 r"^content[\\\/]shell[\\\/]renderer[\\\/]test_runner[\\\/].*",
34 r"^content[\\\/]shell[\\\/]common[\\\/]test_runner[\\\/].*",
[email protected]de28fed2e2014-02-01 14:36:3235 r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*",
[email protected]3de922f2013-12-20 13:27:3836)
37
[email protected]06e6d0ff2012-12-11 01:36:4438# 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]6e04f8c2014-01-29 18:08:3247 r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
[email protected]e2d7e6f2013-04-23 12:57:1248 _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4449 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
50 r'.*[/\\](test|tool(s)?)[/\\].*',
[email protected]ef070cc2013-05-03 11:53:0551 # content_shell is used for running layout tests.
52 r'content[/\\]shell[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4453 # At request of folks maintaining this folder.
54 r'chrome[/\\]browser[/\\]automation[/\\].*',
[email protected]7b054982013-11-27 00:44:4755 # Non-production example code.
56 r'mojo[/\\]examples[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4457)
[email protected]ca8d1982009-02-19 16:33:1258
[email protected]eea609a2011-11-18 13:10:1259_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]cf9b78f2012-11-14 11:40:2867_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]127f18ec2012-06-16 05:05:5972_BANNED_OBJC_FUNCTIONS = (
73 (
74 'addTrackingRect:',
[email protected]23e6cbc2012-06-16 18:51:2075 (
76 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
[email protected]127f18ec2012-06-16 05:05:5977 '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]23e6cbc2012-06-16 18:51:2084 (
85 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
[email protected]127f18ec2012-06-16 05:05:5986 'instead.',
87 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
88 ),
89 False,
90 ),
91 (
92 'convertPointFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2093 (
94 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5995 '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]23e6cbc2012-06-16 18:51:20102 (
103 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59104 '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]23e6cbc2012-06-16 18:51:20111 (
112 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59113 '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]23e6cbc2012-06-16 18:51:20120 (
121 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59122 '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]23e6cbc2012-06-16 18:51:20129 (
130 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59131 '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]23e6cbc2012-06-16 18:51:20138 (
139 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59140 '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]23e6cbc2012-06-16 18:51:20149 # 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]e00ccc92012-11-01 17:32:30151 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
[email protected]23e6cbc2012-06-16 18:51:20152 (
153 'FRIEND_TEST(',
154 (
[email protected]e3c945502012-06-26 20:01:49155 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
[email protected]23e6cbc2012-06-16 18:51:20156 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
157 ),
158 False,
[email protected]7345da02012-11-27 14:31:49159 (),
[email protected]23e6cbc2012-06-16 18:51:20160 ),
161 (
162 'ScopedAllowIO',
163 (
[email protected]e3c945502012-06-26 20:01:49164 'New code should not use ScopedAllowIO. Post a task to the blocking',
165 'pool or the FILE thread instead.',
[email protected]23e6cbc2012-06-16 18:51:20166 ),
[email protected]e3c945502012-06-26 20:01:49167 True,
[email protected]7345da02012-11-27 14:31:49168 (
[email protected]0b818f72013-10-22 00:11:03169 r"^components[\\\/]breakpad[\\\/]app[\\\/]breakpad_mac\.mm$",
[email protected]de7d61ff2013-08-20 11:30:41170 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
171 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
[email protected]398ad132013-04-02 15:11:01172 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
[email protected]7345da02012-11-27 14:31:49173 ),
[email protected]23e6cbc2012-06-16 18:51:20174 ),
[email protected]52657f62013-05-20 05:30:31175 (
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]d89eec82013-12-03 14:10:59212 (
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]127f18ec2012-06-16 05:05:59236)
237
238
[email protected]b00342e7f2013-03-26 16:21:54239_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',
[email protected]eda7afa12014-02-06 12:27:37252 'OS_QNX',
[email protected]b00342e7f2013-03-26 16:21:54253 'OS_SOLARIS',
[email protected]b00342e7f2013-03-26 16:21:54254 'OS_WIN',
255)
256
257
[email protected]55459852011-08-10 15:17:19258def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
259 """Attempts to prevent use of functions intended only for testing in
260 non-testing code. For now this is just a best-effort implementation
261 that ignores header files and may have some false positives. A
262 better implementation would probably need a proper C++ parser.
263 """
264 # We only scan .cc files and the like, as the declaration of
265 # for-testing functions in header files are hard to distinguish from
266 # calls to such functions without a proper C++ parser.
[email protected]06e6d0ff2012-12-11 01:36:44267 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
[email protected]55459852011-08-10 15:17:19268
269 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
270 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
[email protected]de4f7d22013-05-23 14:27:46271 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
[email protected]55459852011-08-10 15:17:19272 exclusion_pattern = input_api.re.compile(
273 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
274 base_function_pattern, base_function_pattern))
275
276 def FilterFile(affected_file):
[email protected]06e6d0ff2012-12-11 01:36:44277 black_list = (_EXCLUDED_PATHS +
278 _TEST_CODE_EXCLUDED_PATHS +
279 input_api.DEFAULT_BLACK_LIST)
[email protected]55459852011-08-10 15:17:19280 return input_api.FilterSourceFile(
281 affected_file,
282 white_list=(file_inclusion_pattern, ),
283 black_list=black_list)
284
285 problems = []
286 for f in input_api.AffectedSourceFiles(FilterFile):
287 local_path = f.LocalPath()
[email protected]825d27182014-01-02 21:24:24288 for line_number, line in f.ChangedContents():
[email protected]2fdd1f362013-01-16 03:56:03289 if (inclusion_pattern.search(line) and
[email protected]de4f7d22013-05-23 14:27:46290 not comment_pattern.search(line) and
[email protected]2fdd1f362013-01-16 03:56:03291 not exclusion_pattern.search(line)):
[email protected]55459852011-08-10 15:17:19292 problems.append(
[email protected]2fdd1f362013-01-16 03:56:03293 '%s:%d\n %s' % (local_path, line_number, line.strip()))
[email protected]55459852011-08-10 15:17:19294
295 if problems:
[email protected]f7051d52013-04-02 18:31:42296 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
[email protected]2fdd1f362013-01-16 03:56:03297 else:
298 return []
[email protected]55459852011-08-10 15:17:19299
300
[email protected]10689ca2011-09-02 02:31:54301def _CheckNoIOStreamInHeaders(input_api, output_api):
302 """Checks to make sure no .h files include <iostream>."""
303 files = []
304 pattern = input_api.re.compile(r'^#include\s*<iostream>',
305 input_api.re.MULTILINE)
306 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
307 if not f.LocalPath().endswith('.h'):
308 continue
309 contents = input_api.ReadFile(f)
310 if pattern.search(contents):
311 files.append(f)
312
313 if len(files):
314 return [ output_api.PresubmitError(
[email protected]6c063c62012-07-11 19:11:06315 'Do not #include <iostream> in header files, since it inserts static '
316 'initialization into every file including the header. Instead, '
[email protected]10689ca2011-09-02 02:31:54317 '#include <ostream>. See http://crbug.com/94794',
318 files) ]
319 return []
320
321
[email protected]72df4e782012-06-21 16:28:18322def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
323 """Checks to make sure no source files use UNIT_TEST"""
324 problems = []
325 for f in input_api.AffectedFiles():
326 if (not f.LocalPath().endswith(('.cc', '.mm'))):
327 continue
328
329 for line_num, line in f.ChangedContents():
[email protected]549f86a2013-11-19 13:00:04330 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
[email protected]72df4e782012-06-21 16:28:18331 problems.append(' %s:%d' % (f.LocalPath(), line_num))
332
333 if not problems:
334 return []
335 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
336 '\n'.join(problems))]
337
338
[email protected]8ea5d4b2011-09-13 21:49:22339def _CheckNoNewWStrings(input_api, output_api):
340 """Checks to make sure we don't introduce use of wstrings."""
[email protected]55463aa62011-10-12 00:48:27341 problems = []
[email protected]8ea5d4b2011-09-13 21:49:22342 for f in input_api.AffectedFiles():
[email protected]b5c24292011-11-28 14:38:20343 if (not f.LocalPath().endswith(('.cc', '.h')) or
[email protected]24be83c2013-08-29 23:01:23344 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
[email protected]b5c24292011-11-28 14:38:20345 continue
[email protected]8ea5d4b2011-09-13 21:49:22346
[email protected]a11dbe9b2012-08-07 01:32:58347 allowWString = False
[email protected]b5c24292011-11-28 14:38:20348 for line_num, line in f.ChangedContents():
[email protected]a11dbe9b2012-08-07 01:32:58349 if 'presubmit: allow wstring' in line:
350 allowWString = True
351 elif not allowWString and 'wstring' in line:
[email protected]55463aa62011-10-12 00:48:27352 problems.append(' %s:%d' % (f.LocalPath(), line_num))
[email protected]a11dbe9b2012-08-07 01:32:58353 allowWString = False
354 else:
355 allowWString = False
[email protected]8ea5d4b2011-09-13 21:49:22356
[email protected]55463aa62011-10-12 00:48:27357 if not problems:
358 return []
359 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
[email protected]a11dbe9b2012-08-07 01:32:58360 ' If you are calling a cross-platform API that accepts a wstring, '
361 'fix the API.\n' +
[email protected]55463aa62011-10-12 00:48:27362 '\n'.join(problems))]
[email protected]8ea5d4b2011-09-13 21:49:22363
364
[email protected]2a8ac9c2011-10-19 17:20:44365def _CheckNoDEPSGIT(input_api, output_api):
366 """Make sure .DEPS.git is never modified manually."""
367 if any(f.LocalPath().endswith('.DEPS.git') for f in
368 input_api.AffectedFiles()):
369 return [output_api.PresubmitError(
370 'Never commit changes to .DEPS.git. This file is maintained by an\n'
371 'automated system based on what\'s in DEPS and your changes will be\n'
372 'overwritten.\n'
373 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
374 'for more information')]
375 return []
376
377
[email protected]127f18ec2012-06-16 05:05:59378def _CheckNoBannedFunctions(input_api, output_api):
379 """Make sure that banned functions are not used."""
380 warnings = []
381 errors = []
382
383 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
384 for f in input_api.AffectedFiles(file_filter=file_filter):
385 for line_num, line in f.ChangedContents():
386 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
387 if func_name in line:
388 problems = warnings;
389 if error:
390 problems = errors;
391 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
392 for message_line in message:
393 problems.append(' %s' % message_line)
394
395 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
396 for f in input_api.AffectedFiles(file_filter=file_filter):
397 for line_num, line in f.ChangedContents():
[email protected]7345da02012-11-27 14:31:49398 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
399 def IsBlacklisted(affected_file, blacklist):
400 local_path = affected_file.LocalPath()
401 for item in blacklist:
402 if input_api.re.match(item, local_path):
403 return True
404 return False
405 if IsBlacklisted(f, excluded_paths):
406 continue
[email protected]d89eec82013-12-03 14:10:59407 matched = False
408 if func_name[0:1] == '/':
409 regex = func_name[1:]
410 if input_api.re.search(regex, line):
411 matched = True
412 elif func_name in line:
413 matched = True
414 if matched:
[email protected]127f18ec2012-06-16 05:05:59415 problems = warnings;
416 if error:
417 problems = errors;
418 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
419 for message_line in message:
420 problems.append(' %s' % message_line)
421
422 result = []
423 if (warnings):
424 result.append(output_api.PresubmitPromptWarning(
425 'Banned functions were used.\n' + '\n'.join(warnings)))
426 if (errors):
427 result.append(output_api.PresubmitError(
428 'Banned functions were used.\n' + '\n'.join(errors)))
429 return result
430
431
[email protected]6c063c62012-07-11 19:11:06432def _CheckNoPragmaOnce(input_api, output_api):
433 """Make sure that banned functions are not used."""
434 files = []
435 pattern = input_api.re.compile(r'^#pragma\s+once',
436 input_api.re.MULTILINE)
437 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
438 if not f.LocalPath().endswith('.h'):
439 continue
440 contents = input_api.ReadFile(f)
441 if pattern.search(contents):
442 files.append(f)
443
444 if files:
445 return [output_api.PresubmitError(
446 'Do not use #pragma once in header files.\n'
447 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
448 files)]
449 return []
450
[email protected]127f18ec2012-06-16 05:05:59451
[email protected]e7479052012-09-19 00:26:12452def _CheckNoTrinaryTrueFalse(input_api, output_api):
453 """Checks to make sure we don't introduce use of foo ? true : false."""
454 problems = []
455 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
456 for f in input_api.AffectedFiles():
457 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
458 continue
459
460 for line_num, line in f.ChangedContents():
461 if pattern.match(line):
462 problems.append(' %s:%d' % (f.LocalPath(), line_num))
463
464 if not problems:
465 return []
466 return [output_api.PresubmitPromptWarning(
467 'Please consider avoiding the "? true : false" pattern if possible.\n' +
468 '\n'.join(problems))]
469
470
[email protected]55f9f382012-07-31 11:02:18471def _CheckUnwantedDependencies(input_api, output_api):
472 """Runs checkdeps on #include statements added in this
473 change. Breaking - rules is an error, breaking ! rules is a
474 warning.
475 """
476 # We need to wait until we have an input_api object and use this
477 # roundabout construct to import checkdeps because this file is
478 # eval-ed and thus doesn't have __file__.
479 original_sys_path = sys.path
480 try:
481 sys.path = sys.path + [input_api.os_path.join(
482 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
483 import checkdeps
484 from cpp_checker import CppChecker
485 from rules import Rule
486 finally:
487 # Restore sys.path to what it was before.
488 sys.path = original_sys_path
489
490 added_includes = []
491 for f in input_api.AffectedFiles():
492 if not CppChecker.IsCppFile(f.LocalPath()):
493 continue
494
495 changed_lines = [line for line_num, line in f.ChangedContents()]
496 added_includes.append([f.LocalPath(), changed_lines])
497
[email protected]26385172013-05-09 23:11:35498 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
[email protected]55f9f382012-07-31 11:02:18499
500 error_descriptions = []
501 warning_descriptions = []
502 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
503 added_includes):
504 description_with_path = '%s\n %s' % (path, rule_description)
505 if rule_type == Rule.DISALLOW:
506 error_descriptions.append(description_with_path)
507 else:
508 warning_descriptions.append(description_with_path)
509
510 results = []
511 if error_descriptions:
512 results.append(output_api.PresubmitError(
513 'You added one or more #includes that violate checkdeps rules.',
514 error_descriptions))
515 if warning_descriptions:
[email protected]f7051d52013-04-02 18:31:42516 results.append(output_api.PresubmitPromptOrNotify(
[email protected]55f9f382012-07-31 11:02:18517 'You added one or more #includes of files that are temporarily\n'
518 'allowed but being removed. Can you avoid introducing the\n'
519 '#include? See relevant DEPS file(s) for details and contacts.',
520 warning_descriptions))
521 return results
522
523
[email protected]fbcafe5a2012-08-08 15:31:22524def _CheckFilePermissions(input_api, output_api):
525 """Check that all files have their permissions properly set."""
[email protected]791507202014-02-03 23:19:15526 if input_api.platform == 'win32':
527 return []
[email protected]fbcafe5a2012-08-08 15:31:22528 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
529 input_api.change.RepositoryRoot()]
530 for f in input_api.AffectedFiles():
531 args += ['--file', f.LocalPath()]
[email protected]f0d330f2014-01-30 01:44:34532 checkperms = input_api.subprocess.Popen(args,
533 stdout=input_api.subprocess.PIPE)
534 errors = checkperms.communicate()[0].strip()
[email protected]fbcafe5a2012-08-08 15:31:22535 if errors:
[email protected]f0d330f2014-01-30 01:44:34536 return [output_api.PresubmitError('checkperms.py failed.',
537 errors.splitlines())]
538 return []
[email protected]fbcafe5a2012-08-08 15:31:22539
540
[email protected]c8278b32012-10-30 20:35:49541def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
542 """Makes sure we don't include ui/aura/window_property.h
543 in header files.
544 """
545 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
546 errors = []
547 for f in input_api.AffectedFiles():
548 if not f.LocalPath().endswith('.h'):
549 continue
550 for line_num, line in f.ChangedContents():
551 if pattern.match(line):
552 errors.append(' %s:%d' % (f.LocalPath(), line_num))
553
554 results = []
555 if errors:
556 results.append(output_api.PresubmitError(
557 'Header files should not include ui/aura/window_property.h', errors))
558 return results
559
560
[email protected]cf9b78f2012-11-14 11:40:28561def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
562 """Checks that the lines in scope occur in the right order.
563
564 1. C system files in alphabetical order
565 2. C++ system files in alphabetical order
566 3. Project's .h files
567 """
568
569 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
570 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
571 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
572
573 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
574
575 state = C_SYSTEM_INCLUDES
576
577 previous_line = ''
[email protected]728b9bb2012-11-14 20:38:57578 previous_line_num = 0
[email protected]cf9b78f2012-11-14 11:40:28579 problem_linenums = []
580 for line_num, line in scope:
581 if c_system_include_pattern.match(line):
582 if state != C_SYSTEM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57583 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28584 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57585 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28586 elif cpp_system_include_pattern.match(line):
587 if state == C_SYSTEM_INCLUDES:
588 state = CPP_SYSTEM_INCLUDES
589 elif state == CUSTOM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57590 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28591 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57592 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28593 elif custom_include_pattern.match(line):
594 if state != CUSTOM_INCLUDES:
595 state = CUSTOM_INCLUDES
596 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57597 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28598 else:
599 problem_linenums.append(line_num)
600 previous_line = line
[email protected]728b9bb2012-11-14 20:38:57601 previous_line_num = line_num
[email protected]cf9b78f2012-11-14 11:40:28602
603 warnings = []
[email protected]728b9bb2012-11-14 20:38:57604 for (line_num, previous_line_num) in problem_linenums:
605 if line_num in changed_linenums or previous_line_num in changed_linenums:
[email protected]cf9b78f2012-11-14 11:40:28606 warnings.append(' %s:%d' % (file_path, line_num))
607 return warnings
608
609
[email protected]ac294a12012-12-06 16:38:43610def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
[email protected]cf9b78f2012-11-14 11:40:28611 """Checks the #include order for the given file f."""
612
[email protected]2299dcf2012-11-15 19:56:24613 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
[email protected]23093b62013-09-20 12:16:30614 # Exclude the following includes from the check:
615 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
616 # specific order.
617 # 2) <atlbase.h>, "build/build_config.h"
618 excluded_include_pattern = input_api.re.compile(
619 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
[email protected]2299dcf2012-11-15 19:56:24620 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
[email protected]3e83618c2013-10-09 22:32:33621 # Match the final or penultimate token if it is xxxtest so we can ignore it
622 # when considering the special first include.
623 test_file_tag_pattern = input_api.re.compile(
624 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
[email protected]0e5c1852012-12-18 20:17:11625 if_pattern = input_api.re.compile(
626 r'\s*#\s*(if|elif|else|endif|define|undef).*')
627 # Some files need specialized order of includes; exclude such files from this
628 # check.
629 uncheckable_includes_pattern = input_api.re.compile(
630 r'\s*#include '
631 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
[email protected]cf9b78f2012-11-14 11:40:28632
633 contents = f.NewContents()
634 warnings = []
635 line_num = 0
636
[email protected]ac294a12012-12-06 16:38:43637 # Handle the special first include. If the first include file is
638 # some/path/file.h, the corresponding including file can be some/path/file.cc,
639 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
640 # etc. It's also possible that no special first include exists.
[email protected]3e83618c2013-10-09 22:32:33641 # If the included file is some/path/file_platform.h the including file could
642 # also be some/path/file_xxxtest_platform.h.
643 including_file_base_name = test_file_tag_pattern.sub(
644 '', input_api.os_path.basename(f.LocalPath()))
645
[email protected]ac294a12012-12-06 16:38:43646 for line in contents:
647 line_num += 1
648 if system_include_pattern.match(line):
649 # No special first include -> process the line again along with normal
650 # includes.
651 line_num -= 1
652 break
653 match = custom_include_pattern.match(line)
654 if match:
655 match_dict = match.groupdict()
[email protected]3e83618c2013-10-09 22:32:33656 header_basename = test_file_tag_pattern.sub(
657 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
658
659 if header_basename not in including_file_base_name:
[email protected]2299dcf2012-11-15 19:56:24660 # No special first include -> process the line again along with normal
661 # includes.
662 line_num -= 1
[email protected]ac294a12012-12-06 16:38:43663 break
[email protected]cf9b78f2012-11-14 11:40:28664
665 # Split into scopes: Each region between #if and #endif is its own scope.
666 scopes = []
667 current_scope = []
668 for line in contents[line_num:]:
669 line_num += 1
[email protected]0e5c1852012-12-18 20:17:11670 if uncheckable_includes_pattern.match(line):
[email protected]4436c9e2014-01-07 23:19:54671 continue
[email protected]2309b0fa02012-11-16 12:18:27672 if if_pattern.match(line):
[email protected]cf9b78f2012-11-14 11:40:28673 scopes.append(current_scope)
674 current_scope = []
[email protected]962f117e2012-11-22 18:11:56675 elif ((system_include_pattern.match(line) or
676 custom_include_pattern.match(line)) and
677 not excluded_include_pattern.match(line)):
[email protected]cf9b78f2012-11-14 11:40:28678 current_scope.append((line_num, line))
679 scopes.append(current_scope)
680
681 for scope in scopes:
682 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
683 changed_linenums))
684 return warnings
685
686
687def _CheckIncludeOrder(input_api, output_api):
688 """Checks that the #include order is correct.
689
690 1. The corresponding header for source files.
691 2. C system files in alphabetical order
692 3. C++ system files in alphabetical order
693 4. Project's .h files in alphabetical order
694
[email protected]ac294a12012-12-06 16:38:43695 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
696 these rules separately.
[email protected]cf9b78f2012-11-14 11:40:28697 """
698
699 warnings = []
700 for f in input_api.AffectedFiles():
[email protected]ac294a12012-12-06 16:38:43701 if f.LocalPath().endswith(('.cc', '.h')):
702 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
703 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
[email protected]cf9b78f2012-11-14 11:40:28704
705 results = []
706 if warnings:
[email protected]f7051d52013-04-02 18:31:42707 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
[email protected]120cf540d2012-12-10 17:55:53708 warnings))
[email protected]cf9b78f2012-11-14 11:40:28709 return results
710
711
[email protected]70ca77752012-11-20 03:45:03712def _CheckForVersionControlConflictsInFile(input_api, f):
713 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
714 errors = []
715 for line_num, line in f.ChangedContents():
716 if pattern.match(line):
717 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
718 return errors
719
720
721def _CheckForVersionControlConflicts(input_api, output_api):
722 """Usually this is not intentional and will cause a compile failure."""
723 errors = []
724 for f in input_api.AffectedFiles():
725 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
726
727 results = []
728 if errors:
729 results.append(output_api.PresubmitError(
730 'Version control conflict markers found, please resolve.', errors))
731 return results
732
733
[email protected]06e6d0ff2012-12-11 01:36:44734def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
735 def FilterFile(affected_file):
736 """Filter function for use with input_api.AffectedSourceFiles,
737 below. This filters out everything except non-test files from
738 top-level directories that generally speaking should not hard-code
739 service URLs (e.g. src/android_webview/, src/content/ and others).
740 """
741 return input_api.FilterSourceFile(
742 affected_file,
[email protected]78bb39d62012-12-11 15:11:56743 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
[email protected]06e6d0ff2012-12-11 01:36:44744 black_list=(_EXCLUDED_PATHS +
745 _TEST_CODE_EXCLUDED_PATHS +
746 input_api.DEFAULT_BLACK_LIST))
747
[email protected]de4f7d22013-05-23 14:27:46748 base_pattern = '"[^"]*google\.com[^"]*"'
749 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
750 pattern = input_api.re.compile(base_pattern)
[email protected]06e6d0ff2012-12-11 01:36:44751 problems = [] # items are (filename, line_number, line)
752 for f in input_api.AffectedSourceFiles(FilterFile):
753 for line_num, line in f.ChangedContents():
[email protected]de4f7d22013-05-23 14:27:46754 if not comment_pattern.search(line) and pattern.search(line):
[email protected]06e6d0ff2012-12-11 01:36:44755 problems.append((f.LocalPath(), line_num, line))
756
757 if problems:
[email protected]f7051d52013-04-02 18:31:42758 return [output_api.PresubmitPromptOrNotify(
[email protected]06e6d0ff2012-12-11 01:36:44759 'Most layers below src/chrome/ should not hardcode service URLs.\n'
760 'Are you sure this is correct? (Contact: [email protected])',
761 [' %s:%d: %s' % (
762 problem[0], problem[1], problem[2]) for problem in problems])]
[email protected]2fdd1f362013-01-16 03:56:03763 else:
764 return []
[email protected]06e6d0ff2012-12-11 01:36:44765
766
[email protected]d2530012013-01-25 16:39:27767def _CheckNoAbbreviationInPngFileName(input_api, output_api):
768 """Makes sure there are no abbreviations in the name of PNG files.
769 """
[email protected]4053a48e2013-01-25 21:43:04770 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
[email protected]d2530012013-01-25 16:39:27771 errors = []
772 for f in input_api.AffectedFiles(include_deletes=False):
773 if pattern.match(f.LocalPath()):
774 errors.append(' %s' % f.LocalPath())
775
776 results = []
777 if errors:
778 results.append(output_api.PresubmitError(
779 'The name of PNG files should not have abbreviations. \n'
780 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
781 'Contact [email protected] if you have questions.', errors))
782 return results
783
784
[email protected]14a6131c2014-01-08 01:15:41785def _FilesToCheckForIncomingDeps(re, changed_lines):
[email protected]f32e2d1e2013-07-26 21:39:08786 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
[email protected]14a6131c2014-01-08 01:15:41787 a set of DEPS entries that we should look up.
788
789 For a directory (rather than a specific filename) we fake a path to
790 a specific filename by adding /DEPS. This is chosen as a file that
791 will seldom or never be subject to per-file include_rules.
792 """
[email protected]2b438d62013-11-14 17:54:14793 # We ignore deps entries on auto-generated directories.
794 AUTO_GENERATED_DIRS = ['grit', 'jni']
[email protected]f32e2d1e2013-07-26 21:39:08795
796 # This pattern grabs the path without basename in the first
797 # parentheses, and the basename (if present) in the second. It
798 # relies on the simple heuristic that if there is a basename it will
799 # be a header file ending in ".h".
800 pattern = re.compile(
801 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
[email protected]2b438d62013-11-14 17:54:14802 results = set()
[email protected]f32e2d1e2013-07-26 21:39:08803 for changed_line in changed_lines:
804 m = pattern.match(changed_line)
805 if m:
806 path = m.group(1)
[email protected]2b438d62013-11-14 17:54:14807 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
[email protected]14a6131c2014-01-08 01:15:41808 if m.group(2):
809 results.add('%s%s' % (path, m.group(2)))
810 else:
811 results.add('%s/DEPS' % path)
[email protected]f32e2d1e2013-07-26 21:39:08812 return results
813
814
[email protected]e871964c2013-05-13 14:14:55815def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
816 """When a dependency prefixed with + is added to a DEPS file, we
817 want to make sure that the change is reviewed by an OWNER of the
818 target file or directory, to avoid layering violations from being
819 introduced. This check verifies that this happens.
820 """
821 changed_lines = set()
822 for f in input_api.AffectedFiles():
823 filename = input_api.os_path.basename(f.LocalPath())
824 if filename == 'DEPS':
825 changed_lines |= set(line.strip()
826 for line_num, line
827 in f.ChangedContents())
828 if not changed_lines:
829 return []
830
[email protected]14a6131c2014-01-08 01:15:41831 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
832 changed_lines)
[email protected]e871964c2013-05-13 14:14:55833 if not virtual_depended_on_files:
834 return []
835
836 if input_api.is_committing:
837 if input_api.tbr:
838 return [output_api.PresubmitNotifyResult(
839 '--tbr was specified, skipping OWNERS check for DEPS additions')]
840 if not input_api.change.issue:
841 return [output_api.PresubmitError(
842 "DEPS approval by OWNERS check failed: this change has "
843 "no Rietveld issue number, so we can't check it for approvals.")]
844 output = output_api.PresubmitError
845 else:
846 output = output_api.PresubmitNotifyResult
847
848 owners_db = input_api.owners_db
849 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
850 input_api,
851 owners_db.email_regexp,
852 approval_needed=input_api.is_committing)
853
854 owner_email = owner_email or input_api.change.author_email
855
[email protected]de4f7d22013-05-23 14:27:46856 reviewers_plus_owner = set(reviewers)
[email protected]e71c6082013-05-22 02:28:51857 if owner_email:
[email protected]de4f7d22013-05-23 14:27:46858 reviewers_plus_owner.add(owner_email)
[email protected]e871964c2013-05-13 14:14:55859 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
860 reviewers_plus_owner)
[email protected]14a6131c2014-01-08 01:15:41861
862 # We strip the /DEPS part that was added by
863 # _FilesToCheckForIncomingDeps to fake a path to a file in a
864 # directory.
865 def StripDeps(path):
866 start_deps = path.rfind('/DEPS')
867 if start_deps != -1:
868 return path[:start_deps]
869 else:
870 return path
871 unapproved_dependencies = ["'+%s'," % StripDeps(path)
[email protected]e871964c2013-05-13 14:14:55872 for path in missing_files]
873
874 if unapproved_dependencies:
875 output_list = [
[email protected]14a6131c2014-01-08 01:15:41876 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
[email protected]e871964c2013-05-13 14:14:55877 '\n '.join(sorted(unapproved_dependencies)))]
878 if not input_api.is_committing:
879 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
880 output_list.append(output(
881 'Suggested missing target path OWNERS:\n %s' %
882 '\n '.join(suggested_owners or [])))
883 return output_list
884
885 return []
886
887
[email protected]85218562013-11-22 07:41:40888def _CheckSpamLogging(input_api, output_api):
889 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
890 black_list = (_EXCLUDED_PATHS +
891 _TEST_CODE_EXCLUDED_PATHS +
892 input_api.DEFAULT_BLACK_LIST +
[email protected]6f742dd02013-11-26 23:19:50893 (r"^base[\\\/]logging\.h$",
[email protected]80f360a2014-01-23 01:36:19894 r"^base[\\\/]logging\.cc$",
[email protected]b3643872014-02-11 23:29:39895 r"^cloud_print[\\\/]",
[email protected]8dc338c2013-12-09 16:28:48896 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
[email protected]6e268db2013-12-04 01:41:46897 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
[email protected]4de75262013-12-18 23:16:12898 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
899 r"startup_browser_creator\.cc$",
[email protected]fe0e6e12013-12-04 05:52:58900 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
[email protected]95c6b3012013-12-02 14:30:31901 r"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
[email protected]6e268db2013-12-04 01:41:46902 r"logging_native_handler\.cc$",
[email protected]9056e732014-01-08 06:25:25903 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
904 r"gl_helper_benchmark\.cc$",
[email protected]cdbdced2013-11-27 21:35:50905 r"^remoting[\\\/]base[\\\/]logging\.h$",
[email protected]67c96ab2013-12-17 02:05:36906 r"^remoting[\\\/]host[\\\/].*",
[email protected]8232f8fd2013-12-14 00:52:31907 r"^sandbox[\\\/]linux[\\\/].*",
[email protected]0b7a21e2014-02-11 18:38:13908 r"^tools[\\\/]",
[email protected]8232f8fd2013-12-14 00:52:31909 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
[email protected]85218562013-11-22 07:41:40910 source_file_filter = lambda x: input_api.FilterSourceFile(
911 x, white_list=(file_inclusion_pattern,), black_list=black_list)
912
913 log_info = []
914 printf = []
915
916 for f in input_api.AffectedSourceFiles(source_file_filter):
917 contents = input_api.ReadFile(f, 'rb')
918 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
919 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37920 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
[email protected]85210652013-11-28 05:50:13921 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37922
923 if re.search(r"\bprintf\(", contents):
924 printf.append(f.LocalPath())
925 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
[email protected]85218562013-11-22 07:41:40926 printf.append(f.LocalPath())
927
928 if log_info:
929 return [output_api.PresubmitError(
930 'These files spam the console log with LOG(INFO):',
931 items=log_info)]
932 if printf:
933 return [output_api.PresubmitError(
934 'These files spam the console log with printf/fprintf:',
935 items=printf)]
936 return []
937
938
[email protected]49aa76a2013-12-04 06:59:16939def _CheckForAnonymousVariables(input_api, output_api):
940 """These types are all expected to hold locks while in scope and
941 so should never be anonymous (which causes them to be immediately
942 destroyed)."""
943 they_who_must_be_named = [
944 'base::AutoLock',
945 'base::AutoReset',
946 'base::AutoUnlock',
947 'SkAutoAlphaRestore',
948 'SkAutoBitmapShaderInstall',
949 'SkAutoBlitterChoose',
950 'SkAutoBounderCommit',
951 'SkAutoCallProc',
952 'SkAutoCanvasRestore',
953 'SkAutoCommentBlock',
954 'SkAutoDescriptor',
955 'SkAutoDisableDirectionCheck',
956 'SkAutoDisableOvalCheck',
957 'SkAutoFree',
958 'SkAutoGlyphCache',
959 'SkAutoHDC',
960 'SkAutoLockColors',
961 'SkAutoLockPixels',
962 'SkAutoMalloc',
963 'SkAutoMaskFreeImage',
964 'SkAutoMutexAcquire',
965 'SkAutoPathBoundsUpdate',
966 'SkAutoPDFRelease',
967 'SkAutoRasterClipValidate',
968 'SkAutoRef',
969 'SkAutoTime',
970 'SkAutoTrace',
971 'SkAutoUnref',
972 ]
973 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
974 # bad: base::AutoLock(lock.get());
975 # not bad: base::AutoLock lock(lock.get());
976 bad_pattern = input_api.re.compile(anonymous)
977 # good: new base::AutoLock(lock.get())
978 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
979 errors = []
980
981 for f in input_api.AffectedFiles():
982 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
983 continue
984 for linenum, line in f.ChangedContents():
985 if bad_pattern.search(line) and not good_pattern.search(line):
986 errors.append('%s:%d' % (f.LocalPath(), linenum))
987
988 if errors:
989 return [output_api.PresubmitError(
990 'These lines create anonymous variables that need to be named:',
991 items=errors)]
992 return []
993
994
[email protected]5fe0f8742013-11-29 01:04:59995def _CheckCygwinShell(input_api, output_api):
996 source_file_filter = lambda x: input_api.FilterSourceFile(
997 x, white_list=(r'.+\.(gyp|gypi)$',))
998 cygwin_shell = []
999
1000 for f in input_api.AffectedSourceFiles(source_file_filter):
1001 for linenum, line in f.ChangedContents():
1002 if 'msvs_cygwin_shell' in line:
1003 cygwin_shell.append(f.LocalPath())
1004 break
1005
1006 if cygwin_shell:
1007 return [output_api.PresubmitError(
1008 'These files should not use msvs_cygwin_shell (the default is 0):',
1009 items=cygwin_shell)]
1010 return []
1011
[email protected]85218562013-11-22 07:41:401012
[email protected]760deea2013-12-10 19:33:491013def _CheckJavaStyle(input_api, output_api):
1014 """Runs checkstyle on changed java files and returns errors if any exist."""
1015 original_sys_path = sys.path
1016 try:
1017 sys.path = sys.path + [input_api.os_path.join(
1018 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1019 import checkstyle
1020 finally:
1021 # Restore sys.path to what it was before.
1022 sys.path = original_sys_path
1023
1024 return checkstyle.RunCheckstyle(
1025 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1026
1027
[email protected]22c9bd72011-03-27 16:47:391028def _CommonChecks(input_api, output_api):
1029 """Checks common to both upload and commit."""
1030 results = []
1031 results.extend(input_api.canned_checks.PanProjectChecks(
[email protected]3de922f2013-12-20 13:27:381032 input_api, output_api,
1033 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
[email protected]66daa702011-05-28 14:41:461034 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]55459852011-08-10 15:17:191035 results.extend(
[email protected]760deea2013-12-10 19:33:491036 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
[email protected]10689ca2011-09-02 02:31:541037 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
[email protected]72df4e782012-06-21 16:28:181038 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
[email protected]8ea5d4b2011-09-13 21:49:221039 results.extend(_CheckNoNewWStrings(input_api, output_api))
[email protected]2a8ac9c2011-10-19 17:20:441040 results.extend(_CheckNoDEPSGIT(input_api, output_api))
[email protected]127f18ec2012-06-16 05:05:591041 results.extend(_CheckNoBannedFunctions(input_api, output_api))
[email protected]6c063c62012-07-11 19:11:061042 results.extend(_CheckNoPragmaOnce(input_api, output_api))
[email protected]e7479052012-09-19 00:26:121043 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
[email protected]55f9f382012-07-31 11:02:181044 results.extend(_CheckUnwantedDependencies(input_api, output_api))
[email protected]fbcafe5a2012-08-08 15:31:221045 results.extend(_CheckFilePermissions(input_api, output_api))
[email protected]c8278b32012-10-30 20:35:491046 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
[email protected]2309b0fa02012-11-16 12:18:271047 results.extend(_CheckIncludeOrder(input_api, output_api))
[email protected]70ca77752012-11-20 03:45:031048 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
[email protected]b8079ae4a2012-12-05 19:56:491049 results.extend(_CheckPatchFiles(input_api, output_api))
[email protected]06e6d0ff2012-12-11 01:36:441050 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
[email protected]d2530012013-01-25 16:39:271051 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
[email protected]b00342e7f2013-03-26 16:21:541052 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
[email protected]e871964c2013-05-13 14:14:551053 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
[email protected]9f919cc2013-07-31 03:04:041054 results.extend(
1055 input_api.canned_checks.CheckChangeHasNoTabs(
1056 input_api,
1057 output_api,
1058 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
[email protected]85218562013-11-22 07:41:401059 results.extend(_CheckSpamLogging(input_api, output_api))
[email protected]49aa76a2013-12-04 06:59:161060 results.extend(_CheckForAnonymousVariables(input_api, output_api))
[email protected]5fe0f8742013-11-29 01:04:591061 results.extend(_CheckCygwinShell(input_api, output_api))
[email protected]760deea2013-12-10 19:33:491062 results.extend(_CheckJavaStyle(input_api, output_api))
[email protected]2299dcf2012-11-15 19:56:241063
1064 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1065 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1066 input_api, output_api,
1067 input_api.PresubmitLocalPath(),
[email protected]6be63382013-01-21 15:42:381068 whitelist=[r'^PRESUBMIT_test\.py$']))
[email protected]22c9bd72011-03-27 16:47:391069 return results
[email protected]1f7b4172010-01-28 01:17:341070
[email protected]b337cb5b2011-01-23 21:24:051071
1072def _CheckSubversionConfig(input_api, output_api):
1073 """Verifies the subversion config file is correctly setup.
1074
1075 Checks that autoprops are enabled, returns an error otherwise.
1076 """
1077 join = input_api.os_path.join
1078 if input_api.platform == 'win32':
1079 appdata = input_api.environ.get('APPDATA', '')
1080 if not appdata:
1081 return [output_api.PresubmitError('%APPDATA% is not configured.')]
1082 path = join(appdata, 'Subversion', 'config')
1083 else:
1084 home = input_api.environ.get('HOME', '')
1085 if not home:
1086 return [output_api.PresubmitError('$HOME is not configured.')]
1087 path = join(home, '.subversion', 'config')
1088
1089 error_msg = (
1090 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1091 'configure your subversion configuration file. This enables automatic\n'
[email protected]c6a3c10b2011-01-24 16:14:201092 'properties to simplify the project maintenance.\n'
1093 'Pro-tip: just download and install\n'
1094 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
[email protected]b337cb5b2011-01-23 21:24:051095
1096 try:
1097 lines = open(path, 'r').read().splitlines()
1098 # Make sure auto-props is enabled and check for 2 Chromium standard
1099 # auto-prop.
1100 if (not '*.cc = svn:eol-style=LF' in lines or
1101 not '*.pdf = svn:mime-type=application/pdf' in lines or
1102 not 'enable-auto-props = yes' in lines):
1103 return [
[email protected]79ed7e62011-02-21 21:08:531104 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:051105 'It looks like you have not configured your subversion config '
[email protected]b5359c02011-02-01 20:29:561106 'file or it is not up-to-date.\n' + error_msg)
[email protected]b337cb5b2011-01-23 21:24:051107 ]
1108 except (OSError, IOError):
1109 return [
[email protected]79ed7e62011-02-21 21:08:531110 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:051111 'Can\'t find your subversion config file.\n' + error_msg)
1112 ]
1113 return []
1114
1115
[email protected]66daa702011-05-28 14:41:461116def _CheckAuthorizedAuthor(input_api, output_api):
1117 """For non-googler/chromites committers, verify the author's email address is
1118 in AUTHORS.
1119 """
[email protected]9bb9cb82011-06-13 20:43:011120 # TODO(maruel): Add it to input_api?
1121 import fnmatch
1122
[email protected]66daa702011-05-28 14:41:461123 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:011124 if not author:
1125 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:461126 return []
[email protected]c99663292011-05-31 19:46:081127 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:461128 input_api.PresubmitLocalPath(), 'AUTHORS')
1129 valid_authors = (
1130 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1131 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:181132 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]d8b50be2011-06-15 14:19:441133 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]5861efb2013-01-07 18:33:231134 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
[email protected]66daa702011-05-28 14:41:461135 return [output_api.PresubmitPromptWarning(
1136 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1137 '\n'
1138 'http://www.chromium.org/developers/contributing-code and read the '
1139 '"Legal" section\n'
1140 'If you are a chromite, verify the contributor signed the CLA.') %
1141 author)]
1142 return []
1143
1144
[email protected]b8079ae4a2012-12-05 19:56:491145def _CheckPatchFiles(input_api, output_api):
1146 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1147 if f.LocalPath().endswith(('.orig', '.rej'))]
1148 if problems:
1149 return [output_api.PresubmitError(
1150 "Don't commit .rej and .orig files.", problems)]
[email protected]2fdd1f362013-01-16 03:56:031151 else:
1152 return []
[email protected]b8079ae4a2012-12-05 19:56:491153
1154
[email protected]b00342e7f2013-03-26 16:21:541155def _DidYouMeanOSMacro(bad_macro):
1156 try:
1157 return {'A': 'OS_ANDROID',
1158 'B': 'OS_BSD',
1159 'C': 'OS_CHROMEOS',
1160 'F': 'OS_FREEBSD',
1161 'L': 'OS_LINUX',
1162 'M': 'OS_MACOSX',
1163 'N': 'OS_NACL',
1164 'O': 'OS_OPENBSD',
1165 'P': 'OS_POSIX',
1166 'S': 'OS_SOLARIS',
1167 'W': 'OS_WIN'}[bad_macro[3].upper()]
1168 except KeyError:
1169 return ''
1170
1171
1172def _CheckForInvalidOSMacrosInFile(input_api, f):
1173 """Check for sensible looking, totally invalid OS macros."""
1174 preprocessor_statement = input_api.re.compile(r'^\s*#')
1175 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1176 results = []
1177 for lnum, line in f.ChangedContents():
1178 if preprocessor_statement.search(line):
1179 for match in os_macro.finditer(line):
1180 if not match.group(1) in _VALID_OS_MACROS:
1181 good = _DidYouMeanOSMacro(match.group(1))
1182 did_you_mean = ' (did you mean %s?)' % good if good else ''
1183 results.append(' %s:%d %s%s' % (f.LocalPath(),
1184 lnum,
1185 match.group(1),
1186 did_you_mean))
1187 return results
1188
1189
1190def _CheckForInvalidOSMacros(input_api, output_api):
1191 """Check all affected files for invalid OS macros."""
1192 bad_macros = []
1193 for f in input_api.AffectedFiles():
1194 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1195 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1196
1197 if not bad_macros:
1198 return []
1199
1200 return [output_api.PresubmitError(
1201 'Possibly invalid OS macro[s] found. Please fix your code\n'
1202 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1203
1204
[email protected]1f7b4172010-01-28 01:17:341205def CheckChangeOnUpload(input_api, output_api):
1206 results = []
1207 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541208 return results
[email protected]ca8d1982009-02-19 16:33:121209
1210
[email protected]38c6a512013-12-18 23:48:011211def GetDefaultTryConfigs(bots=None):
1212 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1213
1214 To add tests to this list, they MUST be in the the corresponding master's
1215 gatekeeper config. For example, anything on master.chromium would be closed by
1216 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1217
1218 If 'bots' is specified, will only return configurations for bots in that list.
1219 """
1220
1221 standard_tests = [
1222 'base_unittests',
1223 'browser_tests',
1224 'cacheinvalidation_unittests',
1225 'check_deps',
1226 'check_deps2git',
1227 'content_browsertests',
1228 'content_unittests',
1229 'crypto_unittests',
1230 #'gfx_unittests',
1231 'gpu_unittests',
1232 'interactive_ui_tests',
1233 'ipc_tests',
1234 'jingle_unittests',
1235 'media_unittests',
1236 'net_unittests',
1237 'ppapi_unittests',
1238 'printing_unittests',
1239 'sql_unittests',
1240 'sync_unit_tests',
1241 'unit_tests',
1242 # Broken in release.
1243 #'url_unittests',
1244 #'webkit_unit_tests',
1245 ]
1246
[email protected]38c6a512013-12-18 23:48:011247 builders_and_tests = {
1248 # TODO(maruel): Figure out a way to run 'sizes' where people can
1249 # effectively update the perf expectation correctly. This requires a
1250 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1251 # incremental build. Reference:
1252 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1253 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1254 # of this step as a try job failure.
1255 'android_aosp': ['compile'],
1256 'android_clang_dbg': ['slave_steps'],
1257 'android_dbg': ['slave_steps'],
1258 'cros_x86': ['defaulttests'],
1259 'ios_dbg_simulator': [
1260 'compile',
1261 'base_unittests',
1262 'content_unittests',
1263 'crypto_unittests',
1264 'url_unittests',
1265 'net_unittests',
1266 'sql_unittests',
1267 'ui_unittests',
1268 ],
1269 'ios_rel_device': ['compile'],
1270 'linux_asan': ['defaulttests'],
1271 #TODO(stip): Change the name of this builder to reflect that it's release.
[email protected]71afb4ec2014-02-07 02:45:131272 'linux_gtk': standard_tests,
[email protected]38c6a512013-12-18 23:48:011273 'linux_chromeos_asan': ['defaulttests'],
1274 'linux_chromeos_clang': ['compile'],
1275 # Note: It is a Release builder even if its name convey otherwise.
1276 'linux_chromeos': standard_tests + [
1277 'app_list_unittests',
1278 'aura_unittests',
1279 'ash_unittests',
1280 'chromeos_unittests',
1281 'components_unittests',
1282 'dbus_unittests',
1283 'device_unittests',
1284 'events_unittests',
1285 'google_apis_unittests',
1286 'sandbox_linux_unittests',
1287 ],
[email protected]23c81d552014-01-07 13:45:461288 'linux_chromium_dbg': ['defaulttests'],
1289 'linux_chromium_rel': ['defaulttests'],
[email protected]38c6a512013-12-18 23:48:011290 'linux_clang': ['compile'],
[email protected]9780bac2014-01-11 00:12:021291 'linux_nacl_sdk_build': ['compile'],
[email protected]38c6a512013-12-18 23:48:011292 'linux_rel': standard_tests + [
[email protected]71afb4ec2014-02-07 02:45:131293 'app_list_unittests',
1294 'aura_unittests',
[email protected]38c6a512013-12-18 23:48:011295 'cc_unittests',
[email protected]5d0413fc2014-01-03 18:24:301296 'chromedriver_unittests',
[email protected]38c6a512013-12-18 23:48:011297 'components_unittests',
[email protected]71afb4ec2014-02-07 02:45:131298 'compositor_unittests',
1299 'events_unittests',
[email protected]38c6a512013-12-18 23:48:011300 'google_apis_unittests',
1301 'nacl_integration',
1302 'remoting_unittests',
1303 'sandbox_linux_unittests',
1304 'sync_integration_tests',
[email protected]9021a5f72014-01-24 19:02:381305 'telemetry_perf_unittests',
1306 'telemetry_unittests',
[email protected]38c6a512013-12-18 23:48:011307 ],
1308 'mac': ['compile'],
[email protected]23c81d552014-01-07 13:45:461309 'mac_chromium_dbg': ['defaulttests'],
1310 'mac_chromium_rel': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021311 'mac_nacl_sdk_build': ['compile'],
[email protected]38c6a512013-12-18 23:48:011312 'mac_rel': standard_tests + [
1313 'app_list_unittests',
1314 'cc_unittests',
[email protected]5d0413fc2014-01-03 18:24:301315 'chromedriver_unittests',
[email protected]38c6a512013-12-18 23:48:011316 'components_unittests',
1317 'google_apis_unittests',
1318 'message_center_unittests',
1319 'nacl_integration',
1320 'remoting_unittests',
1321 'sync_integration_tests',
[email protected]9021a5f72014-01-24 19:02:381322 'telemetry_perf_unittests',
[email protected]38c6a512013-12-18 23:48:011323 'telemetry_unittests',
1324 ],
1325 'win': ['compile'],
[email protected]9780bac2014-01-11 00:12:021326 'win_nacl_sdk_build': ['compile'],
[email protected]38c6a512013-12-18 23:48:011327 'win_rel': standard_tests + [
1328 'app_list_unittests',
1329 'ash_unittests',
1330 'aura_unittests',
1331 'cc_unittests',
1332 'chrome_elf_unittests',
[email protected]5d0413fc2014-01-03 18:24:301333 'chromedriver_unittests',
[email protected]38c6a512013-12-18 23:48:011334 'components_unittests',
1335 'compositor_unittests',
1336 'events_unittests',
1337 'google_apis_unittests',
1338 'installer_util_unittests',
1339 'mini_installer_test',
1340 'nacl_integration',
1341 'remoting_unittests',
1342 'sync_integration_tests',
[email protected]9021a5f72014-01-24 19:02:381343 'telemetry_perf_unittests',
[email protected]38c6a512013-12-18 23:48:011344 '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]ca8d1982009-02-19 16:33:121377def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:541378 results = []
[email protected]1f7b4172010-01-28 01:17:341379 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:511380 # 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]fe5f57c52009-06-05 14:25:541383 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:271384 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:341385 input_api,
1386 output_api,
[email protected]2fdd1f362013-01-16 03:56:031387 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:271388 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
[email protected]2fdd1f362013-01-16 03:56:031389 output_api, 'http://codereview.chromium.org',
[email protected]c1ba4c52012-03-09 14:23:281390 ('win_rel', 'linux_rel', 'mac_rel, win:compile'),
1391 '[email protected]'))
[email protected]806e98e2010-03-19 17:49:271392
[email protected]3e4eb112011-01-18 03:29:541393 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1394 input_api, output_api))
[email protected]c4b47562011-12-05 23:39:411395 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1396 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:051397 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541398 return results
[email protected]ca8d1982009-02-19 16:33:121399
1400
[email protected]5efb2a822011-09-27 23:06:131401def GetPreferredTrySlaves(project, change):
[email protected]4ce995ea2012-06-27 02:13:101402 files = change.LocalPaths()
1403
[email protected]751b05f2013-01-10 23:12:171404 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
[email protected]3019c902012-06-29 00:09:031405 return []
1406
[email protected]d668899a2012-09-06 18:16:591407 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011408 return GetDefaultTryConfigs(['mac', 'mac_rel'])
[email protected]d668899a2012-09-06 18:16:591409 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
[email protected]3630be892013-12-19 05:34:281410 return GetDefaultTryConfigs(['win', 'win_rel'])
[email protected]d668899a2012-09-06 18:16:591411 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011412 return GetDefaultTryConfigs([
1413 'android_aosp',
1414 'android_clang_dbg',
1415 'android_dbg',
1416 ])
[email protected]de142152012-10-03 23:02:451417 if all(re.search('[/_]ios[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011418 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
[email protected]4ce995ea2012-06-27 02:13:101419
[email protected]38c6a512013-12-18 23:48:011420 trybots = GetDefaultTryConfigs([
[email protected]3e2f0402012-11-02 16:28:011421 'android_clang_dbg',
1422 'android_dbg',
1423 'ios_dbg_simulator',
1424 'ios_rel_device',
[email protected]71afb4ec2014-02-07 02:45:131425 'linux_gtk',
[email protected]38c6a512013-12-18 23:48:011426 'linux_asan',
[email protected]3e2f0402012-11-02 16:28:011427 'linux_chromeos',
[email protected]38c6a512013-12-18 23:48:011428 'linux_clang',
[email protected]3056a392014-01-23 20:17:191429 'linux_nacl_sdk_build',
[email protected]3e2f0402012-11-02 16:28:011430 'linux_rel',
[email protected]38c6a512013-12-18 23:48:011431 'mac',
[email protected]9780bac2014-01-11 00:12:021432 'mac_nacl_sdk_build',
[email protected]3e2f0402012-11-02 16:28:011433 'mac_rel',
[email protected]38c6a512013-12-18 23:48:011434 'win',
[email protected]9780bac2014-01-11 00:12:021435 'win_nacl_sdk_build',
[email protected]3e2f0402012-11-02 16:28:011436 'win_rel',
[email protected]38c6a512013-12-18 23:48:011437 'win_x64_rel',
1438 ])
[email protected]911753b2012-08-02 12:11:541439
1440 # Match things like path/aura/file.cc and path/file_aura.cc.
[email protected]95c989162012-11-29 05:58:251441 # Same for chromeos.
1442 if any(re.search('[/_](aura|chromeos)', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011443 trybots.extend(GetDefaultTryConfigs([
1444 'linux_chromeos_asan', 'linux_chromeos_clang']))
[email protected]4ce995ea2012-06-27 02:13:101445
[email protected]e8df48f2013-09-30 20:07:541446 # 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]38c6a512013-12-18 23:48:011452 trybots.extend(GetDefaultTryConfigs(['cros_x86']))
[email protected]e8df48f2013-09-30 20:07:541453
[email protected]d95948ef2013-07-02 10:51:001454 # 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]38c6a512013-12-18 23:48:011459 trybots.extend(GetDefaultTryConfigs(['android_aosp']))
[email protected]d95948ef2013-07-02 10:51:001460
[email protected]4ce995ea2012-06-27 02:13:101461 return trybots