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