Fix Callback Issue During Card Dismissal Request
[chromium-blink-merge.git] / PRESUBMIT.py
blob19d14c47bd3da786592d8e59860aaecb54a41f50
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$",
28 r"^chrome[\\\/]browser[\\\/]resources[\\\/]pdf[\\\/]index.js"
31 # TestRunner and NetscapePlugIn library is temporarily excluded from pan-project
32 # checks until it's transitioned to chromium coding style.
33 _TESTRUNNER_PATHS = (
34 r"^content[\\\/]shell[\\\/]renderer[\\\/]test_runner[\\\/].*",
35 r"^content[\\\/]shell[\\\/]common[\\\/]test_runner[\\\/].*",
36 r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*",
39 # Fragment of a regular expression that matches C++ and Objective-C++
40 # implementation files.
41 _IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
43 # Regular expression that matches code only used for test binaries
44 # (best effort).
45 _TEST_CODE_EXCLUDED_PATHS = (
46 r'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
47 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
48 r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
49 _IMPLEMENTATION_EXTENSIONS,
50 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
51 r'.*[/\\](test|tool(s)?)[/\\].*',
52 # content_shell is used for running layout tests.
53 r'content[/\\]shell[/\\].*',
54 # At request of folks maintaining this folder.
55 r'chrome[/\\]browser[/\\]automation[/\\].*',
56 # Non-production example code.
57 r'mojo[/\\]examples[/\\].*',
60 _TEST_ONLY_WARNING = (
61 'You might be calling functions intended only for testing from\n'
62 'production code. It is OK to ignore this warning if you know what\n'
63 'you are doing, as the heuristics used to detect the situation are\n'
64 'not perfect. The commit queue will not block on this warning.\n'
65 'Email joi@chromium.org if you have questions.')
68 _INCLUDE_ORDER_WARNING = (
69 'Your #include order seems to be broken. Send mail to\n'
70 'marja@chromium.org if this is not the case.')
73 _BANNED_OBJC_FUNCTIONS = (
75 'addTrackingRect:',
77 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
78 'prohibited. Please use CrTrackingArea instead.',
79 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
81 False,
84 'NSTrackingArea',
86 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
87 'instead.',
88 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
90 False,
93 'convertPointFromBase:',
95 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
96 'Please use |convertPoint:(point) fromView:nil| instead.',
97 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
99 True,
102 'convertPointToBase:',
104 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
105 'Please use |convertPoint:(point) toView:nil| instead.',
106 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
108 True,
111 'convertRectFromBase:',
113 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
114 'Please use |convertRect:(point) fromView:nil| instead.',
115 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
117 True,
120 'convertRectToBase:',
122 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
123 'Please use |convertRect:(point) toView:nil| instead.',
124 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
126 True,
129 'convertSizeFromBase:',
131 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
132 'Please use |convertSize:(point) fromView:nil| instead.',
133 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
135 True,
138 'convertSizeToBase:',
140 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
141 'Please use |convertSize:(point) toView:nil| instead.',
142 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
144 True,
149 _BANNED_CPP_FUNCTIONS = (
150 # Make sure that gtest's FRIEND_TEST() macro is not used; the
151 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
152 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
154 'FRIEND_TEST(',
156 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
157 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
159 False,
163 'ScopedAllowIO',
165 'New code should not use ScopedAllowIO. Post a task to the blocking',
166 'pool or the FILE thread instead.',
168 True,
170 r"^components[\\\/]breakpad[\\\/]app[\\\/]breakpad_mac\.mm$",
171 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
172 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
173 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
177 'SkRefPtr',
179 'The use of SkRefPtr is prohibited. ',
180 'Please use skia::RefPtr instead.'
182 True,
186 'SkAutoRef',
188 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
189 'Please use skia::RefPtr instead.'
191 True,
195 'SkAutoTUnref',
197 'The use of SkAutoTUnref is dangerous because it implicitly ',
198 'converts to a raw pointer. Please use skia::RefPtr instead.'
200 True,
204 'SkAutoUnref',
206 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
207 'because it implicitly converts to a raw pointer. ',
208 'Please use skia::RefPtr instead.'
210 True,
214 r'/HANDLE_EINTR\(.*close',
216 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
217 'descriptor will be closed, and it is incorrect to retry the close.',
218 'Either call close directly and ignore its return value, or wrap close',
219 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
221 True,
225 r'/IGNORE_EINTR\((?!.*close)',
227 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
228 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
230 True,
232 # Files that #define IGNORE_EINTR.
233 r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
234 r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
240 _VALID_OS_MACROS = (
241 # Please keep sorted.
242 'OS_ANDROID',
243 'OS_BSD',
244 'OS_CAT', # For testing.
245 'OS_CHROMEOS',
246 'OS_FREEBSD',
247 'OS_IOS',
248 'OS_LINUX',
249 'OS_MACOSX',
250 'OS_NACL',
251 'OS_OPENBSD',
252 'OS_POSIX',
253 'OS_QNX',
254 'OS_SOLARIS',
255 'OS_WIN',
259 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
260 """Attempts to prevent use of functions intended only for testing in
261 non-testing code. For now this is just a best-effort implementation
262 that ignores header files and may have some false positives. A
263 better implementation would probably need a proper C++ parser.
265 # We only scan .cc files and the like, as the declaration of
266 # for-testing functions in header files are hard to distinguish from
267 # calls to such functions without a proper C++ parser.
268 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
270 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
271 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
272 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
273 exclusion_pattern = input_api.re.compile(
274 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
275 base_function_pattern, base_function_pattern))
277 def FilterFile(affected_file):
278 black_list = (_EXCLUDED_PATHS +
279 _TEST_CODE_EXCLUDED_PATHS +
280 input_api.DEFAULT_BLACK_LIST)
281 return input_api.FilterSourceFile(
282 affected_file,
283 white_list=(file_inclusion_pattern, ),
284 black_list=black_list)
286 problems = []
287 for f in input_api.AffectedSourceFiles(FilterFile):
288 local_path = f.LocalPath()
289 for line_number, line in f.ChangedContents():
290 if (inclusion_pattern.search(line) and
291 not comment_pattern.search(line) and
292 not exclusion_pattern.search(line)):
293 problems.append(
294 '%s:%d\n %s' % (local_path, line_number, line.strip()))
296 if problems:
297 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
298 else:
299 return []
302 def _CheckNoIOStreamInHeaders(input_api, output_api):
303 """Checks to make sure no .h files include <iostream>."""
304 files = []
305 pattern = input_api.re.compile(r'^#include\s*<iostream>',
306 input_api.re.MULTILINE)
307 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
308 if not f.LocalPath().endswith('.h'):
309 continue
310 contents = input_api.ReadFile(f)
311 if pattern.search(contents):
312 files.append(f)
314 if len(files):
315 return [ output_api.PresubmitError(
316 'Do not #include <iostream> in header files, since it inserts static '
317 'initialization into every file including the header. Instead, '
318 '#include <ostream>. See http://crbug.com/94794',
319 files) ]
320 return []
323 def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
324 """Checks to make sure no source files use UNIT_TEST"""
325 problems = []
326 for f in input_api.AffectedFiles():
327 if (not f.LocalPath().endswith(('.cc', '.mm'))):
328 continue
330 for line_num, line in f.ChangedContents():
331 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
332 problems.append(' %s:%d' % (f.LocalPath(), line_num))
334 if not problems:
335 return []
336 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
337 '\n'.join(problems))]
340 def _CheckNoNewWStrings(input_api, output_api):
341 """Checks to make sure we don't introduce use of wstrings."""
342 problems = []
343 for f in input_api.AffectedFiles():
344 if (not f.LocalPath().endswith(('.cc', '.h')) or
345 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
346 continue
348 allowWString = False
349 for line_num, line in f.ChangedContents():
350 if 'presubmit: allow wstring' in line:
351 allowWString = True
352 elif not allowWString and 'wstring' in line:
353 problems.append(' %s:%d' % (f.LocalPath(), line_num))
354 allowWString = False
355 else:
356 allowWString = False
358 if not problems:
359 return []
360 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
361 ' If you are calling a cross-platform API that accepts a wstring, '
362 'fix the API.\n' +
363 '\n'.join(problems))]
366 def _CheckNoDEPSGIT(input_api, output_api):
367 """Make sure .DEPS.git is never modified manually."""
368 if any(f.LocalPath().endswith('.DEPS.git') for f in
369 input_api.AffectedFiles()):
370 return [output_api.PresubmitError(
371 'Never commit changes to .DEPS.git. This file is maintained by an\n'
372 'automated system based on what\'s in DEPS and your changes will be\n'
373 'overwritten.\n'
374 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
375 'for more information')]
376 return []
379 def _CheckNoBannedFunctions(input_api, output_api):
380 """Make sure that banned functions are not used."""
381 warnings = []
382 errors = []
384 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
385 for f in input_api.AffectedFiles(file_filter=file_filter):
386 for line_num, line in f.ChangedContents():
387 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
388 if func_name in line:
389 problems = warnings;
390 if error:
391 problems = errors;
392 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
393 for message_line in message:
394 problems.append(' %s' % message_line)
396 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
397 for f in input_api.AffectedFiles(file_filter=file_filter):
398 for line_num, line in f.ChangedContents():
399 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
400 def IsBlacklisted(affected_file, blacklist):
401 local_path = affected_file.LocalPath()
402 for item in blacklist:
403 if input_api.re.match(item, local_path):
404 return True
405 return False
406 if IsBlacklisted(f, excluded_paths):
407 continue
408 matched = False
409 if func_name[0:1] == '/':
410 regex = func_name[1:]
411 if input_api.re.search(regex, line):
412 matched = True
413 elif func_name in line:
414 matched = True
415 if matched:
416 problems = warnings;
417 if error:
418 problems = errors;
419 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
420 for message_line in message:
421 problems.append(' %s' % message_line)
423 result = []
424 if (warnings):
425 result.append(output_api.PresubmitPromptWarning(
426 'Banned functions were used.\n' + '\n'.join(warnings)))
427 if (errors):
428 result.append(output_api.PresubmitError(
429 'Banned functions were used.\n' + '\n'.join(errors)))
430 return result
433 def _CheckNoPragmaOnce(input_api, output_api):
434 """Make sure that banned functions are not used."""
435 files = []
436 pattern = input_api.re.compile(r'^#pragma\s+once',
437 input_api.re.MULTILINE)
438 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
439 if not f.LocalPath().endswith('.h'):
440 continue
441 contents = input_api.ReadFile(f)
442 if pattern.search(contents):
443 files.append(f)
445 if files:
446 return [output_api.PresubmitError(
447 'Do not use #pragma once in header files.\n'
448 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
449 files)]
450 return []
453 def _CheckNoTrinaryTrueFalse(input_api, output_api):
454 """Checks to make sure we don't introduce use of foo ? true : false."""
455 problems = []
456 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
457 for f in input_api.AffectedFiles():
458 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
459 continue
461 for line_num, line in f.ChangedContents():
462 if pattern.match(line):
463 problems.append(' %s:%d' % (f.LocalPath(), line_num))
465 if not problems:
466 return []
467 return [output_api.PresubmitPromptWarning(
468 'Please consider avoiding the "? true : false" pattern if possible.\n' +
469 '\n'.join(problems))]
472 def _CheckUnwantedDependencies(input_api, output_api):
473 """Runs checkdeps on #include statements added in this
474 change. Breaking - rules is an error, breaking ! rules is a
475 warning.
477 # We need to wait until we have an input_api object and use this
478 # roundabout construct to import checkdeps because this file is
479 # eval-ed and thus doesn't have __file__.
480 original_sys_path = sys.path
481 try:
482 sys.path = sys.path + [input_api.os_path.join(
483 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
484 import checkdeps
485 from cpp_checker import CppChecker
486 from rules import Rule
487 finally:
488 # Restore sys.path to what it was before.
489 sys.path = original_sys_path
491 added_includes = []
492 for f in input_api.AffectedFiles():
493 if not CppChecker.IsCppFile(f.LocalPath()):
494 continue
496 changed_lines = [line for line_num, line in f.ChangedContents()]
497 added_includes.append([f.LocalPath(), changed_lines])
499 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
501 error_descriptions = []
502 warning_descriptions = []
503 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
504 added_includes):
505 description_with_path = '%s\n %s' % (path, rule_description)
506 if rule_type == Rule.DISALLOW:
507 error_descriptions.append(description_with_path)
508 else:
509 warning_descriptions.append(description_with_path)
511 results = []
512 if error_descriptions:
513 results.append(output_api.PresubmitError(
514 'You added one or more #includes that violate checkdeps rules.',
515 error_descriptions))
516 if warning_descriptions:
517 results.append(output_api.PresubmitPromptOrNotify(
518 'You added one or more #includes of files that are temporarily\n'
519 'allowed but being removed. Can you avoid introducing the\n'
520 '#include? See relevant DEPS file(s) for details and contacts.',
521 warning_descriptions))
522 return results
525 def _CheckFilePermissions(input_api, output_api):
526 """Check that all files have their permissions properly set."""
527 if input_api.platform == 'win32':
528 return []
529 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
530 input_api.change.RepositoryRoot()]
531 for f in input_api.AffectedFiles():
532 args += ['--file', f.LocalPath()]
533 checkperms = input_api.subprocess.Popen(args,
534 stdout=input_api.subprocess.PIPE)
535 errors = checkperms.communicate()[0].strip()
536 if errors:
537 return [output_api.PresubmitError('checkperms.py failed.',
538 errors.splitlines())]
539 return []
542 def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
543 """Makes sure we don't include ui/aura/window_property.h
544 in header files.
546 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
547 errors = []
548 for f in input_api.AffectedFiles():
549 if not f.LocalPath().endswith('.h'):
550 continue
551 for line_num, line in f.ChangedContents():
552 if pattern.match(line):
553 errors.append(' %s:%d' % (f.LocalPath(), line_num))
555 results = []
556 if errors:
557 results.append(output_api.PresubmitError(
558 'Header files should not include ui/aura/window_property.h', errors))
559 return results
562 def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
563 """Checks that the lines in scope occur in the right order.
565 1. C system files in alphabetical order
566 2. C++ system files in alphabetical order
567 3. Project's .h files
570 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
571 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
572 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
574 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
576 state = C_SYSTEM_INCLUDES
578 previous_line = ''
579 previous_line_num = 0
580 problem_linenums = []
581 for line_num, line in scope:
582 if c_system_include_pattern.match(line):
583 if state != C_SYSTEM_INCLUDES:
584 problem_linenums.append((line_num, previous_line_num))
585 elif previous_line and previous_line > line:
586 problem_linenums.append((line_num, previous_line_num))
587 elif cpp_system_include_pattern.match(line):
588 if state == C_SYSTEM_INCLUDES:
589 state = CPP_SYSTEM_INCLUDES
590 elif state == CUSTOM_INCLUDES:
591 problem_linenums.append((line_num, previous_line_num))
592 elif previous_line and previous_line > line:
593 problem_linenums.append((line_num, previous_line_num))
594 elif custom_include_pattern.match(line):
595 if state != CUSTOM_INCLUDES:
596 state = CUSTOM_INCLUDES
597 elif previous_line and previous_line > line:
598 problem_linenums.append((line_num, previous_line_num))
599 else:
600 problem_linenums.append(line_num)
601 previous_line = line
602 previous_line_num = line_num
604 warnings = []
605 for (line_num, previous_line_num) in problem_linenums:
606 if line_num in changed_linenums or previous_line_num in changed_linenums:
607 warnings.append(' %s:%d' % (file_path, line_num))
608 return warnings
611 def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
612 """Checks the #include order for the given file f."""
614 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
615 # Exclude the following includes from the check:
616 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
617 # specific order.
618 # 2) <atlbase.h>, "build/build_config.h"
619 excluded_include_pattern = input_api.re.compile(
620 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
621 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
622 # Match the final or penultimate token if it is xxxtest so we can ignore it
623 # when considering the special first include.
624 test_file_tag_pattern = input_api.re.compile(
625 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
626 if_pattern = input_api.re.compile(
627 r'\s*#\s*(if|elif|else|endif|define|undef).*')
628 # Some files need specialized order of includes; exclude such files from this
629 # check.
630 uncheckable_includes_pattern = input_api.re.compile(
631 r'\s*#include '
632 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
634 contents = f.NewContents()
635 warnings = []
636 line_num = 0
638 # Handle the special first include. If the first include file is
639 # some/path/file.h, the corresponding including file can be some/path/file.cc,
640 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
641 # etc. It's also possible that no special first include exists.
642 # If the included file is some/path/file_platform.h the including file could
643 # also be some/path/file_xxxtest_platform.h.
644 including_file_base_name = test_file_tag_pattern.sub(
645 '', input_api.os_path.basename(f.LocalPath()))
647 for line in contents:
648 line_num += 1
649 if system_include_pattern.match(line):
650 # No special first include -> process the line again along with normal
651 # includes.
652 line_num -= 1
653 break
654 match = custom_include_pattern.match(line)
655 if match:
656 match_dict = match.groupdict()
657 header_basename = test_file_tag_pattern.sub(
658 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
660 if header_basename not in including_file_base_name:
661 # No special first include -> process the line again along with normal
662 # includes.
663 line_num -= 1
664 break
666 # Split into scopes: Each region between #if and #endif is its own scope.
667 scopes = []
668 current_scope = []
669 for line in contents[line_num:]:
670 line_num += 1
671 if uncheckable_includes_pattern.match(line):
672 continue
673 if if_pattern.match(line):
674 scopes.append(current_scope)
675 current_scope = []
676 elif ((system_include_pattern.match(line) or
677 custom_include_pattern.match(line)) and
678 not excluded_include_pattern.match(line)):
679 current_scope.append((line_num, line))
680 scopes.append(current_scope)
682 for scope in scopes:
683 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
684 changed_linenums))
685 return warnings
688 def _CheckIncludeOrder(input_api, output_api):
689 """Checks that the #include order is correct.
691 1. The corresponding header for source files.
692 2. C system files in alphabetical order
693 3. C++ system files in alphabetical order
694 4. Project's .h files in alphabetical order
696 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
697 these rules separately.
700 warnings = []
701 for f in input_api.AffectedFiles():
702 if f.LocalPath().endswith(('.cc', '.h')):
703 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
704 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
706 results = []
707 if warnings:
708 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
709 warnings))
710 return results
713 def _CheckForVersionControlConflictsInFile(input_api, f):
714 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
715 errors = []
716 for line_num, line in f.ChangedContents():
717 if pattern.match(line):
718 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
719 return errors
722 def _CheckForVersionControlConflicts(input_api, output_api):
723 """Usually this is not intentional and will cause a compile failure."""
724 errors = []
725 for f in input_api.AffectedFiles():
726 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
728 results = []
729 if errors:
730 results.append(output_api.PresubmitError(
731 'Version control conflict markers found, please resolve.', errors))
732 return results
735 def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
736 def FilterFile(affected_file):
737 """Filter function for use with input_api.AffectedSourceFiles,
738 below. This filters out everything except non-test files from
739 top-level directories that generally speaking should not hard-code
740 service URLs (e.g. src/android_webview/, src/content/ and others).
742 return input_api.FilterSourceFile(
743 affected_file,
744 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
745 black_list=(_EXCLUDED_PATHS +
746 _TEST_CODE_EXCLUDED_PATHS +
747 input_api.DEFAULT_BLACK_LIST))
749 base_pattern = '"[^"]*google\.com[^"]*"'
750 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
751 pattern = input_api.re.compile(base_pattern)
752 problems = [] # items are (filename, line_number, line)
753 for f in input_api.AffectedSourceFiles(FilterFile):
754 for line_num, line in f.ChangedContents():
755 if not comment_pattern.search(line) and pattern.search(line):
756 problems.append((f.LocalPath(), line_num, line))
758 if problems:
759 return [output_api.PresubmitPromptOrNotify(
760 'Most layers below src/chrome/ should not hardcode service URLs.\n'
761 'Are you sure this is correct? (Contact: joi@chromium.org)',
762 [' %s:%d: %s' % (
763 problem[0], problem[1], problem[2]) for problem in problems])]
764 else:
765 return []
768 def _CheckNoAbbreviationInPngFileName(input_api, output_api):
769 """Makes sure there are no abbreviations in the name of PNG files.
771 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
772 errors = []
773 for f in input_api.AffectedFiles(include_deletes=False):
774 if pattern.match(f.LocalPath()):
775 errors.append(' %s' % f.LocalPath())
777 results = []
778 if errors:
779 results.append(output_api.PresubmitError(
780 'The name of PNG files should not have abbreviations. \n'
781 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
782 'Contact oshima@chromium.org if you have questions.', errors))
783 return results
786 def _FilesToCheckForIncomingDeps(re, changed_lines):
787 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
788 a set of DEPS entries that we should look up.
790 For a directory (rather than a specific filename) we fake a path to
791 a specific filename by adding /DEPS. This is chosen as a file that
792 will seldom or never be subject to per-file include_rules.
794 # We ignore deps entries on auto-generated directories.
795 AUTO_GENERATED_DIRS = ['grit', 'jni']
797 # This pattern grabs the path without basename in the first
798 # parentheses, and the basename (if present) in the second. It
799 # relies on the simple heuristic that if there is a basename it will
800 # be a header file ending in ".h".
801 pattern = re.compile(
802 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
803 results = set()
804 for changed_line in changed_lines:
805 m = pattern.match(changed_line)
806 if m:
807 path = m.group(1)
808 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
809 if m.group(2):
810 results.add('%s%s' % (path, m.group(2)))
811 else:
812 results.add('%s/DEPS' % path)
813 return results
816 def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
817 """When a dependency prefixed with + is added to a DEPS file, we
818 want to make sure that the change is reviewed by an OWNER of the
819 target file or directory, to avoid layering violations from being
820 introduced. This check verifies that this happens.
822 changed_lines = set()
823 for f in input_api.AffectedFiles():
824 filename = input_api.os_path.basename(f.LocalPath())
825 if filename == 'DEPS':
826 changed_lines |= set(line.strip()
827 for line_num, line
828 in f.ChangedContents())
829 if not changed_lines:
830 return []
832 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
833 changed_lines)
834 if not virtual_depended_on_files:
835 return []
837 if input_api.is_committing:
838 if input_api.tbr:
839 return [output_api.PresubmitNotifyResult(
840 '--tbr was specified, skipping OWNERS check for DEPS additions')]
841 if not input_api.change.issue:
842 return [output_api.PresubmitError(
843 "DEPS approval by OWNERS check failed: this change has "
844 "no Rietveld issue number, so we can't check it for approvals.")]
845 output = output_api.PresubmitError
846 else:
847 output = output_api.PresubmitNotifyResult
849 owners_db = input_api.owners_db
850 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
851 input_api,
852 owners_db.email_regexp,
853 approval_needed=input_api.is_committing)
855 owner_email = owner_email or input_api.change.author_email
857 reviewers_plus_owner = set(reviewers)
858 if owner_email:
859 reviewers_plus_owner.add(owner_email)
860 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
861 reviewers_plus_owner)
863 # We strip the /DEPS part that was added by
864 # _FilesToCheckForIncomingDeps to fake a path to a file in a
865 # directory.
866 def StripDeps(path):
867 start_deps = path.rfind('/DEPS')
868 if start_deps != -1:
869 return path[:start_deps]
870 else:
871 return path
872 unapproved_dependencies = ["'+%s'," % StripDeps(path)
873 for path in missing_files]
875 if unapproved_dependencies:
876 output_list = [
877 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
878 '\n '.join(sorted(unapproved_dependencies)))]
879 if not input_api.is_committing:
880 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
881 output_list.append(output(
882 'Suggested missing target path OWNERS:\n %s' %
883 '\n '.join(suggested_owners or [])))
884 return output_list
886 return []
889 def _CheckSpamLogging(input_api, output_api):
890 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
891 black_list = (_EXCLUDED_PATHS +
892 _TEST_CODE_EXCLUDED_PATHS +
893 input_api.DEFAULT_BLACK_LIST +
894 (r"^base[\\\/]logging\.h$",
895 r"^base[\\\/]logging\.cc$",
896 r"^cloud_print[\\\/]",
897 r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
898 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
899 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
900 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
901 r"startup_browser_creator\.cc$",
902 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
903 r"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
904 r"logging_native_handler\.cc$",
905 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
906 r"gl_helper_benchmark\.cc$",
907 r"^remoting[\\\/]base[\\\/]logging\.h$",
908 r"^remoting[\\\/]host[\\\/].*",
909 r"^sandbox[\\\/]linux[\\\/].*",
910 r"^tools[\\\/]",
911 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
912 source_file_filter = lambda x: input_api.FilterSourceFile(
913 x, white_list=(file_inclusion_pattern,), black_list=black_list)
915 log_info = []
916 printf = []
918 for f in input_api.AffectedSourceFiles(source_file_filter):
919 contents = input_api.ReadFile(f, 'rb')
920 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
921 log_info.append(f.LocalPath())
922 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
923 log_info.append(f.LocalPath())
925 if re.search(r"\bprintf\(", contents):
926 printf.append(f.LocalPath())
927 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
928 printf.append(f.LocalPath())
930 if log_info:
931 return [output_api.PresubmitError(
932 'These files spam the console log with LOG(INFO):',
933 items=log_info)]
934 if printf:
935 return [output_api.PresubmitError(
936 'These files spam the console log with printf/fprintf:',
937 items=printf)]
938 return []
941 def _CheckForAnonymousVariables(input_api, output_api):
942 """These types are all expected to hold locks while in scope and
943 so should never be anonymous (which causes them to be immediately
944 destroyed)."""
945 they_who_must_be_named = [
946 'base::AutoLock',
947 'base::AutoReset',
948 'base::AutoUnlock',
949 'SkAutoAlphaRestore',
950 'SkAutoBitmapShaderInstall',
951 'SkAutoBlitterChoose',
952 'SkAutoBounderCommit',
953 'SkAutoCallProc',
954 'SkAutoCanvasRestore',
955 'SkAutoCommentBlock',
956 'SkAutoDescriptor',
957 'SkAutoDisableDirectionCheck',
958 'SkAutoDisableOvalCheck',
959 'SkAutoFree',
960 'SkAutoGlyphCache',
961 'SkAutoHDC',
962 'SkAutoLockColors',
963 'SkAutoLockPixels',
964 'SkAutoMalloc',
965 'SkAutoMaskFreeImage',
966 'SkAutoMutexAcquire',
967 'SkAutoPathBoundsUpdate',
968 'SkAutoPDFRelease',
969 'SkAutoRasterClipValidate',
970 'SkAutoRef',
971 'SkAutoTime',
972 'SkAutoTrace',
973 'SkAutoUnref',
975 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
976 # bad: base::AutoLock(lock.get());
977 # not bad: base::AutoLock lock(lock.get());
978 bad_pattern = input_api.re.compile(anonymous)
979 # good: new base::AutoLock(lock.get())
980 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
981 errors = []
983 for f in input_api.AffectedFiles():
984 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
985 continue
986 for linenum, line in f.ChangedContents():
987 if bad_pattern.search(line) and not good_pattern.search(line):
988 errors.append('%s:%d' % (f.LocalPath(), linenum))
990 if errors:
991 return [output_api.PresubmitError(
992 'These lines create anonymous variables that need to be named:',
993 items=errors)]
994 return []
997 def _CheckCygwinShell(input_api, output_api):
998 source_file_filter = lambda x: input_api.FilterSourceFile(
999 x, white_list=(r'.+\.(gyp|gypi)$',))
1000 cygwin_shell = []
1002 for f in input_api.AffectedSourceFiles(source_file_filter):
1003 for linenum, line in f.ChangedContents():
1004 if 'msvs_cygwin_shell' in line:
1005 cygwin_shell.append(f.LocalPath())
1006 break
1008 if cygwin_shell:
1009 return [output_api.PresubmitError(
1010 'These files should not use msvs_cygwin_shell (the default is 0):',
1011 items=cygwin_shell)]
1012 return []
1015 def _CheckUserActionUpdate(input_api, output_api):
1016 """Checks if any new user action has been added."""
1017 if any('actions.xml' == input_api.os_path.basename(f) for f in
1018 input_api.LocalPaths()):
1019 # If actions.xml is already included in the changelist, the PRESUBMIT
1020 # for actions.xml will do a more complete presubmit check.
1021 return []
1023 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm'))
1024 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)'
1025 current_actions = None
1026 for f in input_api.AffectedFiles(file_filter=file_filter):
1027 for line_num, line in f.ChangedContents():
1028 match = input_api.re.search(action_re, line)
1029 if match:
1030 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1031 # loaded only once.
1032 if not current_actions:
1033 with open('tools/metrics/actions/actions.xml') as actions_f:
1034 current_actions = actions_f.read()
1035 # Search for the matched user action name in |current_actions|.
1036 for action_name in match.groups():
1037 action = 'name="{0}"'.format(action_name)
1038 if action not in current_actions:
1039 return [output_api.PresubmitPromptWarning(
1040 'File %s line %d: %s is missing in '
1041 'tools/metrics/actions/actions.xml. Please run '
1042 'tools/metrics/actions/extract_actions.py to update.'
1043 % (f.LocalPath(), line_num, action_name))]
1044 return []
1047 def _CheckJavaStyle(input_api, output_api):
1048 """Runs checkstyle on changed java files and returns errors if any exist."""
1049 original_sys_path = sys.path
1050 try:
1051 sys.path = sys.path + [input_api.os_path.join(
1052 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1053 import checkstyle
1054 finally:
1055 # Restore sys.path to what it was before.
1056 sys.path = original_sys_path
1058 return checkstyle.RunCheckstyle(
1059 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1062 def _CommonChecks(input_api, output_api):
1063 """Checks common to both upload and commit."""
1064 results = []
1065 results.extend(input_api.canned_checks.PanProjectChecks(
1066 input_api, output_api,
1067 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
1068 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
1069 results.extend(
1070 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
1071 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
1072 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
1073 results.extend(_CheckNoNewWStrings(input_api, output_api))
1074 results.extend(_CheckNoDEPSGIT(input_api, output_api))
1075 results.extend(_CheckNoBannedFunctions(input_api, output_api))
1076 results.extend(_CheckNoPragmaOnce(input_api, output_api))
1077 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
1078 results.extend(_CheckUnwantedDependencies(input_api, output_api))
1079 results.extend(_CheckFilePermissions(input_api, output_api))
1080 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
1081 results.extend(_CheckIncludeOrder(input_api, output_api))
1082 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
1083 results.extend(_CheckPatchFiles(input_api, output_api))
1084 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
1085 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
1086 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
1087 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
1088 results.extend(
1089 input_api.canned_checks.CheckChangeHasNoTabs(
1090 input_api,
1091 output_api,
1092 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
1093 results.extend(_CheckSpamLogging(input_api, output_api))
1094 results.extend(_CheckForAnonymousVariables(input_api, output_api))
1095 results.extend(_CheckCygwinShell(input_api, output_api))
1096 results.extend(_CheckUserActionUpdate(input_api, output_api))
1098 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1099 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1100 input_api, output_api,
1101 input_api.PresubmitLocalPath(),
1102 whitelist=[r'^PRESUBMIT_test\.py$']))
1103 return results
1106 def _CheckSubversionConfig(input_api, output_api):
1107 """Verifies the subversion config file is correctly setup.
1109 Checks that autoprops are enabled, returns an error otherwise.
1111 join = input_api.os_path.join
1112 if input_api.platform == 'win32':
1113 appdata = input_api.environ.get('APPDATA', '')
1114 if not appdata:
1115 return [output_api.PresubmitError('%APPDATA% is not configured.')]
1116 path = join(appdata, 'Subversion', 'config')
1117 else:
1118 home = input_api.environ.get('HOME', '')
1119 if not home:
1120 return [output_api.PresubmitError('$HOME is not configured.')]
1121 path = join(home, '.subversion', 'config')
1123 error_msg = (
1124 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1125 'configure your subversion configuration file. This enables automatic\n'
1126 'properties to simplify the project maintenance.\n'
1127 'Pro-tip: just download and install\n'
1128 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
1130 try:
1131 lines = open(path, 'r').read().splitlines()
1132 # Make sure auto-props is enabled and check for 2 Chromium standard
1133 # auto-prop.
1134 if (not '*.cc = svn:eol-style=LF' in lines or
1135 not '*.pdf = svn:mime-type=application/pdf' in lines or
1136 not 'enable-auto-props = yes' in lines):
1137 return [
1138 output_api.PresubmitNotifyResult(
1139 'It looks like you have not configured your subversion config '
1140 'file or it is not up-to-date.\n' + error_msg)
1142 except (OSError, IOError):
1143 return [
1144 output_api.PresubmitNotifyResult(
1145 'Can\'t find your subversion config file.\n' + error_msg)
1147 return []
1150 def _CheckAuthorizedAuthor(input_api, output_api):
1151 """For non-googler/chromites committers, verify the author's email address is
1152 in AUTHORS.
1154 # TODO(maruel): Add it to input_api?
1155 import fnmatch
1157 author = input_api.change.author_email
1158 if not author:
1159 input_api.logging.info('No author, skipping AUTHOR check')
1160 return []
1161 authors_path = input_api.os_path.join(
1162 input_api.PresubmitLocalPath(), 'AUTHORS')
1163 valid_authors = (
1164 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1165 for line in open(authors_path))
1166 valid_authors = [item.group(1).lower() for item in valid_authors if item]
1167 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
1168 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
1169 return [output_api.PresubmitPromptWarning(
1170 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1171 '\n'
1172 'http://www.chromium.org/developers/contributing-code and read the '
1173 '"Legal" section\n'
1174 'If you are a chromite, verify the contributor signed the CLA.') %
1175 author)]
1176 return []
1179 def _CheckPatchFiles(input_api, output_api):
1180 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1181 if f.LocalPath().endswith(('.orig', '.rej'))]
1182 if problems:
1183 return [output_api.PresubmitError(
1184 "Don't commit .rej and .orig files.", problems)]
1185 else:
1186 return []
1189 def _DidYouMeanOSMacro(bad_macro):
1190 try:
1191 return {'A': 'OS_ANDROID',
1192 'B': 'OS_BSD',
1193 'C': 'OS_CHROMEOS',
1194 'F': 'OS_FREEBSD',
1195 'L': 'OS_LINUX',
1196 'M': 'OS_MACOSX',
1197 'N': 'OS_NACL',
1198 'O': 'OS_OPENBSD',
1199 'P': 'OS_POSIX',
1200 'S': 'OS_SOLARIS',
1201 'W': 'OS_WIN'}[bad_macro[3].upper()]
1202 except KeyError:
1203 return ''
1206 def _CheckForInvalidOSMacrosInFile(input_api, f):
1207 """Check for sensible looking, totally invalid OS macros."""
1208 preprocessor_statement = input_api.re.compile(r'^\s*#')
1209 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1210 results = []
1211 for lnum, line in f.ChangedContents():
1212 if preprocessor_statement.search(line):
1213 for match in os_macro.finditer(line):
1214 if not match.group(1) in _VALID_OS_MACROS:
1215 good = _DidYouMeanOSMacro(match.group(1))
1216 did_you_mean = ' (did you mean %s?)' % good if good else ''
1217 results.append(' %s:%d %s%s' % (f.LocalPath(),
1218 lnum,
1219 match.group(1),
1220 did_you_mean))
1221 return results
1224 def _CheckForInvalidOSMacros(input_api, output_api):
1225 """Check all affected files for invalid OS macros."""
1226 bad_macros = []
1227 for f in input_api.AffectedFiles():
1228 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1229 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1231 if not bad_macros:
1232 return []
1234 return [output_api.PresubmitError(
1235 'Possibly invalid OS macro[s] found. Please fix your code\n'
1236 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1239 def CheckChangeOnUpload(input_api, output_api):
1240 results = []
1241 results.extend(_CommonChecks(input_api, output_api))
1242 results.extend(_CheckJavaStyle(input_api, output_api))
1243 return results
1246 def GetDefaultTryConfigs(bots=None):
1247 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1249 To add tests to this list, they MUST be in the the corresponding master's
1250 gatekeeper config. For example, anything on master.chromium would be closed by
1251 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1253 If 'bots' is specified, will only return configurations for bots in that list.
1256 standard_tests = [
1257 'base_unittests',
1258 'browser_tests',
1259 'cacheinvalidation_unittests',
1260 'check_deps',
1261 'check_deps2git',
1262 'content_browsertests',
1263 'content_unittests',
1264 'crypto_unittests',
1265 'gpu_unittests',
1266 'interactive_ui_tests',
1267 'ipc_tests',
1268 'jingle_unittests',
1269 'media_unittests',
1270 'net_unittests',
1271 'ppapi_unittests',
1272 'printing_unittests',
1273 'sql_unittests',
1274 'sync_unit_tests',
1275 'unit_tests',
1276 # Broken in release.
1277 #'url_unittests',
1278 #'webkit_unit_tests',
1281 builders_and_tests = {
1282 # TODO(maruel): Figure out a way to run 'sizes' where people can
1283 # effectively update the perf expectation correctly. This requires a
1284 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1285 # incremental build. Reference:
1286 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1287 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1288 # of this step as a try job failure.
1289 'android_aosp': ['compile'],
1290 'android_clang_dbg': ['slave_steps'],
1291 'android_dbg': ['slave_steps'],
1292 'cros_x86': ['defaulttests'],
1293 'ios_dbg_simulator': [
1294 'compile',
1295 'base_unittests',
1296 'content_unittests',
1297 'crypto_unittests',
1298 'url_unittests',
1299 'net_unittests',
1300 'sql_unittests',
1301 'ui_unittests',
1303 'ios_rel_device': ['compile'],
1304 'linux_asan': ['defaulttests'],
1305 #TODO(stip): Change the name of this builder to reflect that it's release.
1306 'linux_gtk': standard_tests,
1307 'linux_chromeos_asan': ['defaulttests'],
1308 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
1309 'linux_chromium_chromeos_rel': ['defaulttests'],
1310 'linux_chromium_compile_dbg': ['defaulttests'],
1311 'linux_chromium_rel': ['defaulttests'],
1312 'linux_chromium_clang_dbg': ['defaulttests'],
1313 'linux_nacl_sdk_build': ['compile'],
1314 'linux_rel': [
1315 'telemetry_perf_unittests',
1316 'telemetry_unittests',
1318 'mac_chromium_compile_dbg': ['defaulttests'],
1319 'mac_chromium_rel': ['defaulttests'],
1320 'mac_nacl_sdk_build': ['compile'],
1321 'mac_rel': [
1322 'telemetry_perf_unittests',
1323 'telemetry_unittests',
1325 'win': ['compile'],
1326 'win_chromium_compile_dbg': ['defaulttests'],
1327 'win_nacl_sdk_build': ['compile'],
1328 'win_rel': standard_tests + [
1329 'app_list_unittests',
1330 'ash_unittests',
1331 'aura_unittests',
1332 'cc_unittests',
1333 'chrome_elf_unittests',
1334 'chromedriver_unittests',
1335 'components_unittests',
1336 'compositor_unittests',
1337 'events_unittests',
1338 'gfx_unittests',
1339 'google_apis_unittests',
1340 'installer_util_unittests',
1341 'mini_installer_test',
1342 'nacl_integration',
1343 'remoting_unittests',
1344 'sync_integration_tests',
1345 'telemetry_perf_unittests',
1346 'telemetry_unittests',
1347 'views_unittests',
1349 'win_x64_rel': [
1350 'base_unittests',
1354 swarm_enabled_builders = (
1355 'linux_rel',
1356 'mac_rel',
1357 'win_rel',
1360 swarm_enabled_tests = (
1361 'base_unittests',
1362 'browser_tests',
1363 'interactive_ui_tests',
1364 'net_unittests',
1365 'unit_tests',
1368 for bot in builders_and_tests:
1369 if bot in swarm_enabled_builders:
1370 builders_and_tests[bot] = [x + '_swarm' if x in swarm_enabled_tests else x
1371 for x in builders_and_tests[bot]]
1373 if bots:
1374 return {
1375 'tryserver.chromium': dict((bot, set(builders_and_tests[bot]))
1376 for bot in bots)
1378 else:
1379 return {
1380 'tryserver.chromium': dict(
1381 (bot, set(tests))
1382 for bot, tests in builders_and_tests.iteritems())
1386 def CheckChangeOnCommit(input_api, output_api):
1387 results = []
1388 results.extend(_CommonChecks(input_api, output_api))
1389 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1390 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1391 # input_api, output_api, sources))
1392 # Make sure the tree is 'open'.
1393 results.extend(input_api.canned_checks.CheckTreeIsOpen(
1394 input_api,
1395 output_api,
1396 json_url='http://chromium-status.appspot.com/current?format=json'))
1398 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1399 input_api, output_api))
1400 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1401 input_api, output_api))
1402 results.extend(_CheckSubversionConfig(input_api, output_api))
1403 return results
1406 def GetPreferredTryMasters(project, change):
1407 files = change.LocalPaths()
1409 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
1410 return {}
1412 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
1413 return GetDefaultTryConfigs([
1414 'mac_chromium_compile_dbg',
1415 'mac_chromium_rel',
1417 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
1418 return GetDefaultTryConfigs(['win', 'win_rel'])
1419 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
1420 return GetDefaultTryConfigs([
1421 'android_aosp',
1422 'android_clang_dbg',
1423 'android_dbg',
1425 if all(re.search('[/_]ios[/_.]', f) for f in files):
1426 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
1428 builders = [
1429 'android_clang_dbg',
1430 'android_dbg',
1431 'ios_dbg_simulator',
1432 'ios_rel_device',
1433 'linux_chromium_chromeos_rel',
1434 'linux_chromium_clang_dbg',
1435 'linux_chromium_rel',
1436 'mac_chromium_compile_dbg',
1437 'mac_chromium_rel',
1438 'win_chromium_compile_dbg',
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 builders.extend([
1447 'linux_chromeos_asan',
1448 'linux_chromium_chromeos_clang_dbg'
1451 # If there are gyp changes to base, build, or chromeos, run a full cros build
1452 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1453 # files have a much higher chance of breaking the cros build, which is
1454 # differnt from the linux_chromeos build that most chrome developers test
1455 # with.
1456 if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files):
1457 builders.extend(['cros_x86'])
1459 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1460 # unless they're .gyp(i) files as changes to those files can break the gyp
1461 # step on that bot.
1462 if (not all(re.search('^chrome', f) for f in files) or
1463 any(re.search('\.gypi?$', f) for f in files)):
1464 builders.extend(['android_aosp'])
1466 return GetDefaultTryConfigs(builders)