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