All Chrome Frame policies are valid only through version 32.
[chromium-blink-merge.git] / PRESUBMIT.py
blob940760908d32c3f48130db8085e8d5c358c62e31
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 subprocess
14 import sys
17 _EXCLUDED_PATHS = (
18 r"^breakpad[\\\/].*",
19 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
20 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
21 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
22 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
23 r"^skia[\\\/].*",
24 r"^v8[\\\/].*",
25 r".*MakeFile$",
26 r".+_autogen\.h$",
27 r".+[\\\/]pnacl_shim\.c$",
28 r"^gpu[\\\/]config[\\\/].*_list_json\.cc$",
31 # TestRunner library is temporarily excluded from pan-project checks until
32 # it's transitioned to chromium coding style.
33 _TESTRUNNER_PATHS = (
34 r"^content[\\\/]shell[\\\/]renderer[\\\/]test_runner[\\\/].*",
35 r"^content[\\\/]shell[\\\/]common[\\\/]test_runner[\\\/].*",
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|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 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
526 input_api.change.RepositoryRoot()]
527 for f in input_api.AffectedFiles():
528 args += ['--file', f.LocalPath()]
529 errors = []
530 (errors, stderrdata) = subprocess.Popen(args).communicate()
532 results = []
533 if errors:
534 results.append(output_api.PresubmitError('checkperms.py failed.',
535 errors))
536 return results
539 def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
540 """Makes sure we don't include ui/aura/window_property.h
541 in header files.
543 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
544 errors = []
545 for f in input_api.AffectedFiles():
546 if not f.LocalPath().endswith('.h'):
547 continue
548 for line_num, line in f.ChangedContents():
549 if pattern.match(line):
550 errors.append(' %s:%d' % (f.LocalPath(), line_num))
552 results = []
553 if errors:
554 results.append(output_api.PresubmitError(
555 'Header files should not include ui/aura/window_property.h', errors))
556 return results
559 def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
560 """Checks that the lines in scope occur in the right order.
562 1. C system files in alphabetical order
563 2. C++ system files in alphabetical order
564 3. Project's .h files
567 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
568 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
569 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
571 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
573 state = C_SYSTEM_INCLUDES
575 previous_line = ''
576 previous_line_num = 0
577 problem_linenums = []
578 for line_num, line in scope:
579 if c_system_include_pattern.match(line):
580 if state != C_SYSTEM_INCLUDES:
581 problem_linenums.append((line_num, previous_line_num))
582 elif previous_line and previous_line > line:
583 problem_linenums.append((line_num, previous_line_num))
584 elif cpp_system_include_pattern.match(line):
585 if state == C_SYSTEM_INCLUDES:
586 state = CPP_SYSTEM_INCLUDES
587 elif state == CUSTOM_INCLUDES:
588 problem_linenums.append((line_num, previous_line_num))
589 elif previous_line and previous_line > line:
590 problem_linenums.append((line_num, previous_line_num))
591 elif custom_include_pattern.match(line):
592 if state != CUSTOM_INCLUDES:
593 state = CUSTOM_INCLUDES
594 elif previous_line and previous_line > line:
595 problem_linenums.append((line_num, previous_line_num))
596 else:
597 problem_linenums.append(line_num)
598 previous_line = line
599 previous_line_num = line_num
601 warnings = []
602 for (line_num, previous_line_num) in problem_linenums:
603 if line_num in changed_linenums or previous_line_num in changed_linenums:
604 warnings.append(' %s:%d' % (file_path, line_num))
605 return warnings
608 def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
609 """Checks the #include order for the given file f."""
611 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
612 # Exclude the following includes from the check:
613 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
614 # specific order.
615 # 2) <atlbase.h>, "build/build_config.h"
616 excluded_include_pattern = input_api.re.compile(
617 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
618 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
619 # Match the final or penultimate token if it is xxxtest so we can ignore it
620 # when considering the special first include.
621 test_file_tag_pattern = input_api.re.compile(
622 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
623 if_pattern = input_api.re.compile(
624 r'\s*#\s*(if|elif|else|endif|define|undef).*')
625 # Some files need specialized order of includes; exclude such files from this
626 # check.
627 uncheckable_includes_pattern = input_api.re.compile(
628 r'\s*#include '
629 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
631 contents = f.NewContents()
632 warnings = []
633 line_num = 0
635 # Handle the special first include. If the first include file is
636 # some/path/file.h, the corresponding including file can be some/path/file.cc,
637 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
638 # etc. It's also possible that no special first include exists.
639 # If the included file is some/path/file_platform.h the including file could
640 # also be some/path/file_xxxtest_platform.h.
641 including_file_base_name = test_file_tag_pattern.sub(
642 '', input_api.os_path.basename(f.LocalPath()))
644 for line in contents:
645 line_num += 1
646 if system_include_pattern.match(line):
647 # No special first include -> process the line again along with normal
648 # includes.
649 line_num -= 1
650 break
651 match = custom_include_pattern.match(line)
652 if match:
653 match_dict = match.groupdict()
654 header_basename = test_file_tag_pattern.sub(
655 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
657 if header_basename not in including_file_base_name:
658 # No special first include -> process the line again along with normal
659 # includes.
660 line_num -= 1
661 break
663 # Split into scopes: Each region between #if and #endif is its own scope.
664 scopes = []
665 current_scope = []
666 for line in contents[line_num:]:
667 line_num += 1
668 if uncheckable_includes_pattern.match(line):
669 continue
670 if if_pattern.match(line):
671 scopes.append(current_scope)
672 current_scope = []
673 elif ((system_include_pattern.match(line) or
674 custom_include_pattern.match(line)) and
675 not excluded_include_pattern.match(line)):
676 current_scope.append((line_num, line))
677 scopes.append(current_scope)
679 for scope in scopes:
680 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
681 changed_linenums))
682 return warnings
685 def _CheckIncludeOrder(input_api, output_api):
686 """Checks that the #include order is correct.
688 1. The corresponding header for source files.
689 2. C system files in alphabetical order
690 3. C++ system files in alphabetical order
691 4. Project's .h files in alphabetical order
693 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
694 these rules separately.
697 warnings = []
698 for f in input_api.AffectedFiles():
699 if f.LocalPath().endswith(('.cc', '.h')):
700 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
701 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
703 results = []
704 if warnings:
705 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
706 warnings))
707 return results
710 def _CheckForVersionControlConflictsInFile(input_api, f):
711 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
712 errors = []
713 for line_num, line in f.ChangedContents():
714 if pattern.match(line):
715 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
716 return errors
719 def _CheckForVersionControlConflicts(input_api, output_api):
720 """Usually this is not intentional and will cause a compile failure."""
721 errors = []
722 for f in input_api.AffectedFiles():
723 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
725 results = []
726 if errors:
727 results.append(output_api.PresubmitError(
728 'Version control conflict markers found, please resolve.', errors))
729 return results
732 def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
733 def FilterFile(affected_file):
734 """Filter function for use with input_api.AffectedSourceFiles,
735 below. This filters out everything except non-test files from
736 top-level directories that generally speaking should not hard-code
737 service URLs (e.g. src/android_webview/, src/content/ and others).
739 return input_api.FilterSourceFile(
740 affected_file,
741 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
742 black_list=(_EXCLUDED_PATHS +
743 _TEST_CODE_EXCLUDED_PATHS +
744 input_api.DEFAULT_BLACK_LIST))
746 base_pattern = '"[^"]*google\.com[^"]*"'
747 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
748 pattern = input_api.re.compile(base_pattern)
749 problems = [] # items are (filename, line_number, line)
750 for f in input_api.AffectedSourceFiles(FilterFile):
751 for line_num, line in f.ChangedContents():
752 if not comment_pattern.search(line) and pattern.search(line):
753 problems.append((f.LocalPath(), line_num, line))
755 if problems:
756 return [output_api.PresubmitPromptOrNotify(
757 'Most layers below src/chrome/ should not hardcode service URLs.\n'
758 'Are you sure this is correct? (Contact: joi@chromium.org)',
759 [' %s:%d: %s' % (
760 problem[0], problem[1], problem[2]) for problem in problems])]
761 else:
762 return []
765 def _CheckNoAbbreviationInPngFileName(input_api, output_api):
766 """Makes sure there are no abbreviations in the name of PNG files.
768 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
769 errors = []
770 for f in input_api.AffectedFiles(include_deletes=False):
771 if pattern.match(f.LocalPath()):
772 errors.append(' %s' % f.LocalPath())
774 results = []
775 if errors:
776 results.append(output_api.PresubmitError(
777 'The name of PNG files should not have abbreviations. \n'
778 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
779 'Contact oshima@chromium.org if you have questions.', errors))
780 return results
783 def _FilesToCheckForIncomingDeps(re, changed_lines):
784 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
785 a set of DEPS entries that we should look up.
787 For a directory (rather than a specific filename) we fake a path to
788 a specific filename by adding /DEPS. This is chosen as a file that
789 will seldom or never be subject to per-file include_rules.
791 # We ignore deps entries on auto-generated directories.
792 AUTO_GENERATED_DIRS = ['grit', 'jni']
794 # This pattern grabs the path without basename in the first
795 # parentheses, and the basename (if present) in the second. It
796 # relies on the simple heuristic that if there is a basename it will
797 # be a header file ending in ".h".
798 pattern = re.compile(
799 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
800 results = set()
801 for changed_line in changed_lines:
802 m = pattern.match(changed_line)
803 if m:
804 path = m.group(1)
805 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
806 if m.group(2):
807 results.add('%s%s' % (path, m.group(2)))
808 else:
809 results.add('%s/DEPS' % path)
810 return results
813 def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
814 """When a dependency prefixed with + is added to a DEPS file, we
815 want to make sure that the change is reviewed by an OWNER of the
816 target file or directory, to avoid layering violations from being
817 introduced. This check verifies that this happens.
819 changed_lines = set()
820 for f in input_api.AffectedFiles():
821 filename = input_api.os_path.basename(f.LocalPath())
822 if filename == 'DEPS':
823 changed_lines |= set(line.strip()
824 for line_num, line
825 in f.ChangedContents())
826 if not changed_lines:
827 return []
829 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
830 changed_lines)
831 if not virtual_depended_on_files:
832 return []
834 if input_api.is_committing:
835 if input_api.tbr:
836 return [output_api.PresubmitNotifyResult(
837 '--tbr was specified, skipping OWNERS check for DEPS additions')]
838 if not input_api.change.issue:
839 return [output_api.PresubmitError(
840 "DEPS approval by OWNERS check failed: this change has "
841 "no Rietveld issue number, so we can't check it for approvals.")]
842 output = output_api.PresubmitError
843 else:
844 output = output_api.PresubmitNotifyResult
846 owners_db = input_api.owners_db
847 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
848 input_api,
849 owners_db.email_regexp,
850 approval_needed=input_api.is_committing)
852 owner_email = owner_email or input_api.change.author_email
854 reviewers_plus_owner = set(reviewers)
855 if owner_email:
856 reviewers_plus_owner.add(owner_email)
857 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
858 reviewers_plus_owner)
860 # We strip the /DEPS part that was added by
861 # _FilesToCheckForIncomingDeps to fake a path to a file in a
862 # directory.
863 def StripDeps(path):
864 start_deps = path.rfind('/DEPS')
865 if start_deps != -1:
866 return path[:start_deps]
867 else:
868 return path
869 unapproved_dependencies = ["'+%s'," % StripDeps(path)
870 for path in missing_files]
872 if unapproved_dependencies:
873 output_list = [
874 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
875 '\n '.join(sorted(unapproved_dependencies)))]
876 if not input_api.is_committing:
877 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
878 output_list.append(output(
879 'Suggested missing target path OWNERS:\n %s' %
880 '\n '.join(suggested_owners or [])))
881 return output_list
883 return []
886 def _CheckSpamLogging(input_api, output_api):
887 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
888 black_list = (_EXCLUDED_PATHS +
889 _TEST_CODE_EXCLUDED_PATHS +
890 input_api.DEFAULT_BLACK_LIST +
891 (r"^base[\\\/]logging\.h$",
892 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
893 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
894 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
895 r"startup_browser_creator\.cc$",
896 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
897 r"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
898 r"logging_native_handler\.cc$",
899 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
900 r"gl_helper_benchmark\.cc$",
901 r"^remoting[\\\/]base[\\\/]logging\.h$",
902 r"^remoting[\\\/]host[\\\/].*",
903 r"^sandbox[\\\/]linux[\\\/].*",
904 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
905 source_file_filter = lambda x: input_api.FilterSourceFile(
906 x, white_list=(file_inclusion_pattern,), black_list=black_list)
908 log_info = []
909 printf = []
911 for f in input_api.AffectedSourceFiles(source_file_filter):
912 contents = input_api.ReadFile(f, 'rb')
913 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
914 log_info.append(f.LocalPath())
915 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
916 log_info.append(f.LocalPath())
918 if re.search(r"\bprintf\(", contents):
919 printf.append(f.LocalPath())
920 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
921 printf.append(f.LocalPath())
923 if log_info:
924 return [output_api.PresubmitError(
925 'These files spam the console log with LOG(INFO):',
926 items=log_info)]
927 if printf:
928 return [output_api.PresubmitError(
929 'These files spam the console log with printf/fprintf:',
930 items=printf)]
931 return []
934 def _CheckForAnonymousVariables(input_api, output_api):
935 """These types are all expected to hold locks while in scope and
936 so should never be anonymous (which causes them to be immediately
937 destroyed)."""
938 they_who_must_be_named = [
939 'base::AutoLock',
940 'base::AutoReset',
941 'base::AutoUnlock',
942 'SkAutoAlphaRestore',
943 'SkAutoBitmapShaderInstall',
944 'SkAutoBlitterChoose',
945 'SkAutoBounderCommit',
946 'SkAutoCallProc',
947 'SkAutoCanvasRestore',
948 'SkAutoCommentBlock',
949 'SkAutoDescriptor',
950 'SkAutoDisableDirectionCheck',
951 'SkAutoDisableOvalCheck',
952 'SkAutoFree',
953 'SkAutoGlyphCache',
954 'SkAutoHDC',
955 'SkAutoLockColors',
956 'SkAutoLockPixels',
957 'SkAutoMalloc',
958 'SkAutoMaskFreeImage',
959 'SkAutoMutexAcquire',
960 'SkAutoPathBoundsUpdate',
961 'SkAutoPDFRelease',
962 'SkAutoRasterClipValidate',
963 'SkAutoRef',
964 'SkAutoTime',
965 'SkAutoTrace',
966 'SkAutoUnref',
968 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
969 # bad: base::AutoLock(lock.get());
970 # not bad: base::AutoLock lock(lock.get());
971 bad_pattern = input_api.re.compile(anonymous)
972 # good: new base::AutoLock(lock.get())
973 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
974 errors = []
976 for f in input_api.AffectedFiles():
977 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
978 continue
979 for linenum, line in f.ChangedContents():
980 if bad_pattern.search(line) and not good_pattern.search(line):
981 errors.append('%s:%d' % (f.LocalPath(), linenum))
983 if errors:
984 return [output_api.PresubmitError(
985 'These lines create anonymous variables that need to be named:',
986 items=errors)]
987 return []
990 def _CheckCygwinShell(input_api, output_api):
991 source_file_filter = lambda x: input_api.FilterSourceFile(
992 x, white_list=(r'.+\.(gyp|gypi)$',))
993 cygwin_shell = []
995 for f in input_api.AffectedSourceFiles(source_file_filter):
996 for linenum, line in f.ChangedContents():
997 if 'msvs_cygwin_shell' in line:
998 cygwin_shell.append(f.LocalPath())
999 break
1001 if cygwin_shell:
1002 return [output_api.PresubmitError(
1003 'These files should not use msvs_cygwin_shell (the default is 0):',
1004 items=cygwin_shell)]
1005 return []
1008 def _CheckJavaStyle(input_api, output_api):
1009 """Runs checkstyle on changed java files and returns errors if any exist."""
1010 original_sys_path = sys.path
1011 try:
1012 sys.path = sys.path + [input_api.os_path.join(
1013 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1014 import checkstyle
1015 finally:
1016 # Restore sys.path to what it was before.
1017 sys.path = original_sys_path
1019 return checkstyle.RunCheckstyle(
1020 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1023 def _CommonChecks(input_api, output_api):
1024 """Checks common to both upload and commit."""
1025 results = []
1026 results.extend(input_api.canned_checks.PanProjectChecks(
1027 input_api, output_api,
1028 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
1029 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
1030 results.extend(
1031 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
1032 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
1033 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
1034 results.extend(_CheckNoNewWStrings(input_api, output_api))
1035 results.extend(_CheckNoDEPSGIT(input_api, output_api))
1036 results.extend(_CheckNoBannedFunctions(input_api, output_api))
1037 results.extend(_CheckNoPragmaOnce(input_api, output_api))
1038 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
1039 results.extend(_CheckUnwantedDependencies(input_api, output_api))
1040 results.extend(_CheckFilePermissions(input_api, output_api))
1041 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
1042 results.extend(_CheckIncludeOrder(input_api, output_api))
1043 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
1044 results.extend(_CheckPatchFiles(input_api, output_api))
1045 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
1046 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
1047 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
1048 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
1049 results.extend(
1050 input_api.canned_checks.CheckChangeHasNoTabs(
1051 input_api,
1052 output_api,
1053 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
1054 results.extend(_CheckSpamLogging(input_api, output_api))
1055 results.extend(_CheckForAnonymousVariables(input_api, output_api))
1056 results.extend(_CheckCygwinShell(input_api, output_api))
1057 results.extend(_CheckJavaStyle(input_api, output_api))
1059 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1060 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1061 input_api, output_api,
1062 input_api.PresubmitLocalPath(),
1063 whitelist=[r'^PRESUBMIT_test\.py$']))
1064 return results
1067 def _CheckSubversionConfig(input_api, output_api):
1068 """Verifies the subversion config file is correctly setup.
1070 Checks that autoprops are enabled, returns an error otherwise.
1072 join = input_api.os_path.join
1073 if input_api.platform == 'win32':
1074 appdata = input_api.environ.get('APPDATA', '')
1075 if not appdata:
1076 return [output_api.PresubmitError('%APPDATA% is not configured.')]
1077 path = join(appdata, 'Subversion', 'config')
1078 else:
1079 home = input_api.environ.get('HOME', '')
1080 if not home:
1081 return [output_api.PresubmitError('$HOME is not configured.')]
1082 path = join(home, '.subversion', 'config')
1084 error_msg = (
1085 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1086 'configure your subversion configuration file. This enables automatic\n'
1087 'properties to simplify the project maintenance.\n'
1088 'Pro-tip: just download and install\n'
1089 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
1091 try:
1092 lines = open(path, 'r').read().splitlines()
1093 # Make sure auto-props is enabled and check for 2 Chromium standard
1094 # auto-prop.
1095 if (not '*.cc = svn:eol-style=LF' in lines or
1096 not '*.pdf = svn:mime-type=application/pdf' in lines or
1097 not 'enable-auto-props = yes' in lines):
1098 return [
1099 output_api.PresubmitNotifyResult(
1100 'It looks like you have not configured your subversion config '
1101 'file or it is not up-to-date.\n' + error_msg)
1103 except (OSError, IOError):
1104 return [
1105 output_api.PresubmitNotifyResult(
1106 'Can\'t find your subversion config file.\n' + error_msg)
1108 return []
1111 def _CheckAuthorizedAuthor(input_api, output_api):
1112 """For non-googler/chromites committers, verify the author's email address is
1113 in AUTHORS.
1115 # TODO(maruel): Add it to input_api?
1116 import fnmatch
1118 author = input_api.change.author_email
1119 if not author:
1120 input_api.logging.info('No author, skipping AUTHOR check')
1121 return []
1122 authors_path = input_api.os_path.join(
1123 input_api.PresubmitLocalPath(), 'AUTHORS')
1124 valid_authors = (
1125 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1126 for line in open(authors_path))
1127 valid_authors = [item.group(1).lower() for item in valid_authors if item]
1128 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
1129 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
1130 return [output_api.PresubmitPromptWarning(
1131 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1132 '\n'
1133 'http://www.chromium.org/developers/contributing-code and read the '
1134 '"Legal" section\n'
1135 'If you are a chromite, verify the contributor signed the CLA.') %
1136 author)]
1137 return []
1140 def _CheckPatchFiles(input_api, output_api):
1141 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1142 if f.LocalPath().endswith(('.orig', '.rej'))]
1143 if problems:
1144 return [output_api.PresubmitError(
1145 "Don't commit .rej and .orig files.", problems)]
1146 else:
1147 return []
1150 def _DidYouMeanOSMacro(bad_macro):
1151 try:
1152 return {'A': 'OS_ANDROID',
1153 'B': 'OS_BSD',
1154 'C': 'OS_CHROMEOS',
1155 'F': 'OS_FREEBSD',
1156 'L': 'OS_LINUX',
1157 'M': 'OS_MACOSX',
1158 'N': 'OS_NACL',
1159 'O': 'OS_OPENBSD',
1160 'P': 'OS_POSIX',
1161 'S': 'OS_SOLARIS',
1162 'W': 'OS_WIN'}[bad_macro[3].upper()]
1163 except KeyError:
1164 return ''
1167 def _CheckForInvalidOSMacrosInFile(input_api, f):
1168 """Check for sensible looking, totally invalid OS macros."""
1169 preprocessor_statement = input_api.re.compile(r'^\s*#')
1170 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1171 results = []
1172 for lnum, line in f.ChangedContents():
1173 if preprocessor_statement.search(line):
1174 for match in os_macro.finditer(line):
1175 if not match.group(1) in _VALID_OS_MACROS:
1176 good = _DidYouMeanOSMacro(match.group(1))
1177 did_you_mean = ' (did you mean %s?)' % good if good else ''
1178 results.append(' %s:%d %s%s' % (f.LocalPath(),
1179 lnum,
1180 match.group(1),
1181 did_you_mean))
1182 return results
1185 def _CheckForInvalidOSMacros(input_api, output_api):
1186 """Check all affected files for invalid OS macros."""
1187 bad_macros = []
1188 for f in input_api.AffectedFiles():
1189 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1190 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1192 if not bad_macros:
1193 return []
1195 return [output_api.PresubmitError(
1196 'Possibly invalid OS macro[s] found. Please fix your code\n'
1197 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1200 def CheckChangeOnUpload(input_api, output_api):
1201 results = []
1202 results.extend(_CommonChecks(input_api, output_api))
1203 return results
1206 def GetDefaultTryConfigs(bots=None):
1207 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1209 To add tests to this list, they MUST be in the the corresponding master's
1210 gatekeeper config. For example, anything on master.chromium would be closed by
1211 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1213 If 'bots' is specified, will only return configurations for bots in that list.
1216 standard_tests = [
1217 'base_unittests',
1218 'browser_tests',
1219 'cacheinvalidation_unittests',
1220 'check_deps',
1221 'check_deps2git',
1222 'content_browsertests',
1223 'content_unittests',
1224 'crypto_unittests',
1225 #'gfx_unittests',
1226 'gpu_unittests',
1227 'interactive_ui_tests',
1228 'ipc_tests',
1229 'jingle_unittests',
1230 'media_unittests',
1231 'net_unittests',
1232 'ppapi_unittests',
1233 'printing_unittests',
1234 'sql_unittests',
1235 'sync_unit_tests',
1236 'unit_tests',
1237 # Broken in release.
1238 #'url_unittests',
1239 #'webkit_unit_tests',
1242 linux_aura_tests = [
1243 'app_list_unittests',
1244 'aura_unittests',
1245 'browser_tests',
1246 'compositor_unittests',
1247 'content_browsertests',
1248 'content_unittests',
1249 'events_unittests',
1250 'interactive_ui_tests',
1251 'unit_tests',
1253 builders_and_tests = {
1254 # TODO(maruel): Figure out a way to run 'sizes' where people can
1255 # effectively update the perf expectation correctly. This requires a
1256 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1257 # incremental build. Reference:
1258 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1259 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1260 # of this step as a try job failure.
1261 'android_aosp': ['compile'],
1262 'android_clang_dbg': ['slave_steps'],
1263 'android_dbg': ['slave_steps'],
1264 'cros_x86': ['defaulttests'],
1265 'ios_dbg_simulator': [
1266 'compile',
1267 'base_unittests',
1268 'content_unittests',
1269 'crypto_unittests',
1270 'url_unittests',
1271 'net_unittests',
1272 'sql_unittests',
1273 'ui_unittests',
1275 'ios_rel_device': ['compile'],
1276 'linux_asan': ['defaulttests'],
1277 #TODO(stip): Change the name of this builder to reflect that it's release.
1278 'linux_aura': linux_aura_tests,
1279 'linux_chromeos_asan': ['defaulttests'],
1280 'linux_chromeos_clang': ['compile'],
1281 # Note: It is a Release builder even if its name convey otherwise.
1282 'linux_chromeos': standard_tests + [
1283 'app_list_unittests',
1284 'aura_unittests',
1285 'ash_unittests',
1286 'chromeos_unittests',
1287 'components_unittests',
1288 'dbus_unittests',
1289 'device_unittests',
1290 'events_unittests',
1291 'google_apis_unittests',
1292 'sandbox_linux_unittests',
1294 'linux_chromium_dbg': ['defaulttests'],
1295 'linux_chromium_rel': ['defaulttests'],
1296 'linux_clang': ['compile'],
1297 'linux_nacl_sdk_build': ['compile'],
1298 'linux_rel': standard_tests + [
1299 'cc_unittests',
1300 'chromedriver_unittests',
1301 'components_unittests',
1302 'google_apis_unittests',
1303 'nacl_integration',
1304 'remoting_unittests',
1305 'sandbox_linux_unittests',
1306 'sync_integration_tests',
1308 'mac': ['compile'],
1309 'mac_chromium_dbg': ['defaulttests'],
1310 'mac_chromium_rel': ['defaulttests'],
1311 'mac_nacl_sdk_build': ['compile'],
1312 'mac_rel': standard_tests + [
1313 'app_list_unittests',
1314 'cc_unittests',
1315 'chromedriver_unittests',
1316 'components_unittests',
1317 'google_apis_unittests',
1318 'message_center_unittests',
1319 'nacl_integration',
1320 'remoting_unittests',
1321 'sync_integration_tests',
1322 'telemetry_unittests',
1324 'win': ['compile'],
1325 'win_nacl_sdk_build': ['compile'],
1326 'win_rel': standard_tests + [
1327 'app_list_unittests',
1328 'ash_unittests',
1329 'aura_unittests',
1330 'cc_unittests',
1331 'chrome_elf_unittests',
1332 'chromedriver_unittests',
1333 'components_unittests',
1334 'compositor_unittests',
1335 'events_unittests',
1336 'google_apis_unittests',
1337 'installer_util_unittests',
1338 'mini_installer_test',
1339 'nacl_integration',
1340 'remoting_unittests',
1341 'sync_integration_tests',
1342 'telemetry_unittests',
1343 'views_unittests',
1345 'win_x64_rel': [
1346 'base_unittests',
1350 swarm_enabled_builders = (
1351 'linux_rel',
1352 'mac_rel',
1353 'win_rel',
1356 swarm_enabled_tests = (
1357 'base_unittests',
1358 'browser_tests',
1359 'interactive_ui_tests',
1360 'net_unittests',
1361 'unit_tests',
1364 for bot in builders_and_tests:
1365 if bot in swarm_enabled_builders:
1366 builders_and_tests[bot] = [x + '_swarm' if x in swarm_enabled_tests else x
1367 for x in builders_and_tests[bot]]
1369 if bots:
1370 return [(bot, set(builders_and_tests[bot])) for bot in bots]
1371 else:
1372 return [(bot, set(tests)) for bot, tests in builders_and_tests.iteritems()]
1375 def CheckChangeOnCommit(input_api, output_api):
1376 results = []
1377 results.extend(_CommonChecks(input_api, output_api))
1378 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1379 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1380 # input_api, output_api, sources))
1381 # Make sure the tree is 'open'.
1382 results.extend(input_api.canned_checks.CheckTreeIsOpen(
1383 input_api,
1384 output_api,
1385 json_url='http://chromium-status.appspot.com/current?format=json'))
1386 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
1387 output_api, 'http://codereview.chromium.org',
1388 ('win_rel', 'linux_rel', 'mac_rel, win:compile'),
1389 'tryserver@chromium.org'))
1391 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1392 input_api, output_api))
1393 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1394 input_api, output_api))
1395 results.extend(_CheckSubversionConfig(input_api, output_api))
1396 return results
1399 def GetPreferredTrySlaves(project, change):
1400 files = change.LocalPaths()
1402 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
1403 return []
1405 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
1406 return GetDefaultTryConfigs(['mac', 'mac_rel'])
1407 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
1408 return GetDefaultTryConfigs(['win', 'win_rel'])
1409 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
1410 return GetDefaultTryConfigs([
1411 'android_aosp',
1412 'android_clang_dbg',
1413 'android_dbg',
1415 if all(re.search('[/_]ios[/_.]', f) for f in files):
1416 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
1418 trybots = GetDefaultTryConfigs([
1419 'android_clang_dbg',
1420 'android_dbg',
1421 'ios_dbg_simulator',
1422 'ios_rel_device',
1423 'linux_aura',
1424 'linux_asan',
1425 'linux_chromeos',
1426 'linux_clang',
1427 'linux_nacl_sdk_build',
1428 'linux_rel',
1429 'mac',
1430 'mac_nacl_sdk_build',
1431 'mac_rel',
1432 'win',
1433 'win_nacl_sdk_build',
1434 'win_rel',
1435 'win_x64_rel',
1438 # Match things like path/aura/file.cc and path/file_aura.cc.
1439 # Same for chromeos.
1440 if any(re.search('[/_](aura|chromeos)', f) for f in files):
1441 trybots.extend(GetDefaultTryConfigs([
1442 'linux_chromeos_asan', 'linux_chromeos_clang']))
1444 # If there are gyp changes to base, build, or chromeos, run a full cros build
1445 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1446 # files have a much higher chance of breaking the cros build, which is
1447 # differnt from the linux_chromeos build that most chrome developers test
1448 # with.
1449 if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files):
1450 trybots.extend(GetDefaultTryConfigs(['cros_x86']))
1452 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1453 # unless they're .gyp(i) files as changes to those files can break the gyp
1454 # step on that bot.
1455 if (not all(re.search('^chrome', f) for f in files) or
1456 any(re.search('\.gypi?$', f) for f in files)):
1457 trybots.extend(GetDefaultTryConfigs(['android_aosp']))
1459 return trybots