Get rid of all component builds specific .isolate.
[chromium-blink-merge.git] / PRESUBMIT.py
blob71e3a28d3a0699d72ff78a6d2d260628eccd9ebd
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Top-level presubmit script for Chromium.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl.
9 """
12 import re
13 import sys
16 _EXCLUDED_PATHS = (
17 r"^breakpad[\\\/].*",
18 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
19 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
20 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
21 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
22 r"^skia[\\\/].*",
23 r"^v8[\\\/].*",
24 r".*MakeFile$",
25 r".+_autogen\.h$",
26 r".+[\\\/]pnacl_shim\.c$",
27 r"^gpu[\\\/]config[\\\/].*_list_json\.cc$",
28 r"^chrome[\\\/]browser[\\\/]resources[\\\/]pdf[\\\/]index.js"
31 # TestRunner and NetscapePlugIn library is temporarily excluded from pan-project
32 # checks until it's transitioned to chromium coding style.
33 _TESTRUNNER_PATHS = (
34 r"^content[\\\/]shell[\\\/]renderer[\\\/]test_runner[\\\/].*",
35 r"^content[\\\/]shell[\\\/]common[\\\/]test_runner[\\\/].*",
36 r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*",
39 # Fragment of a regular expression that matches C++ and Objective-C++
40 # implementation files.
41 _IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
43 # Regular expression that matches code only used for test binaries
44 # (best effort).
45 _TEST_CODE_EXCLUDED_PATHS = (
46 r'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
47 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
48 r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
49 _IMPLEMENTATION_EXTENSIONS,
50 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
51 r'.*[/\\](test|tool(s)?)[/\\].*',
52 # content_shell is used for running layout tests.
53 r'content[/\\]shell[/\\].*',
54 # At request of folks maintaining this folder.
55 r'chrome[/\\]browser[/\\]automation[/\\].*',
56 # Non-production example code.
57 r'mojo[/\\]examples[/\\].*',
60 _TEST_ONLY_WARNING = (
61 'You might be calling functions intended only for testing from\n'
62 'production code. It is OK to ignore this warning if you know what\n'
63 'you are doing, as the heuristics used to detect the situation are\n'
64 'not perfect. The commit queue will not block on this warning.')
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"^mojo[\\\/]system[\\\/]raw_shared_buffer_posix\.cc$",
173 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
177 'SkRefPtr',
179 'The use of SkRefPtr is prohibited. ',
180 'Please use skia::RefPtr instead.'
182 True,
186 'SkAutoRef',
188 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
189 'Please use skia::RefPtr instead.'
191 True,
195 'SkAutoTUnref',
197 'The use of SkAutoTUnref is dangerous because it implicitly ',
198 'converts to a raw pointer. Please use skia::RefPtr instead.'
200 True,
204 'SkAutoUnref',
206 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
207 'because it implicitly converts to a raw pointer. ',
208 'Please use skia::RefPtr instead.'
210 True,
214 r'/HANDLE_EINTR\(.*close',
216 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
217 'descriptor will be closed, and it is incorrect to retry the close.',
218 'Either call close directly and ignore its return value, or wrap close',
219 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
221 True,
225 r'/IGNORE_EINTR\((?!.*close)',
227 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
228 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
230 True,
232 # Files that #define IGNORE_EINTR.
233 r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
234 r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
238 r'/v8::Extension\(',
240 'Do not introduce new v8::Extensions into the code base, use',
241 'gin::Wrappable instead. See http://crbug.com/334679',
243 True,
249 _VALID_OS_MACROS = (
250 # Please keep sorted.
251 'OS_ANDROID',
252 'OS_ANDROID_HOST',
253 'OS_BSD',
254 'OS_CAT', # For testing.
255 'OS_CHROMEOS',
256 'OS_FREEBSD',
257 'OS_IOS',
258 'OS_LINUX',
259 'OS_MACOSX',
260 'OS_NACL',
261 'OS_OPENBSD',
262 'OS_POSIX',
263 'OS_QNX',
264 'OS_SOLARIS',
265 'OS_WIN',
269 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
270 """Attempts to prevent use of functions intended only for testing in
271 non-testing code. For now this is just a best-effort implementation
272 that ignores header files and may have some false positives. A
273 better implementation would probably need a proper C++ parser.
275 # We only scan .cc files and the like, as the declaration of
276 # for-testing functions in header files are hard to distinguish from
277 # calls to such functions without a proper C++ parser.
278 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
280 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
281 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
282 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
283 exclusion_pattern = input_api.re.compile(
284 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
285 base_function_pattern, base_function_pattern))
287 def FilterFile(affected_file):
288 black_list = (_EXCLUDED_PATHS +
289 _TEST_CODE_EXCLUDED_PATHS +
290 input_api.DEFAULT_BLACK_LIST)
291 return input_api.FilterSourceFile(
292 affected_file,
293 white_list=(file_inclusion_pattern, ),
294 black_list=black_list)
296 problems = []
297 for f in input_api.AffectedSourceFiles(FilterFile):
298 local_path = f.LocalPath()
299 for line_number, line in f.ChangedContents():
300 if (inclusion_pattern.search(line) and
301 not comment_pattern.search(line) and
302 not exclusion_pattern.search(line)):
303 problems.append(
304 '%s:%d\n %s' % (local_path, line_number, line.strip()))
306 if problems:
307 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
308 else:
309 return []
312 def _CheckNoIOStreamInHeaders(input_api, output_api):
313 """Checks to make sure no .h files include <iostream>."""
314 files = []
315 pattern = input_api.re.compile(r'^#include\s*<iostream>',
316 input_api.re.MULTILINE)
317 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
318 if not f.LocalPath().endswith('.h'):
319 continue
320 contents = input_api.ReadFile(f)
321 if pattern.search(contents):
322 files.append(f)
324 if len(files):
325 return [ output_api.PresubmitError(
326 'Do not #include <iostream> in header files, since it inserts static '
327 'initialization into every file including the header. Instead, '
328 '#include <ostream>. See http://crbug.com/94794',
329 files) ]
330 return []
333 def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
334 """Checks to make sure no source files use UNIT_TEST"""
335 problems = []
336 for f in input_api.AffectedFiles():
337 if (not f.LocalPath().endswith(('.cc', '.mm'))):
338 continue
340 for line_num, line in f.ChangedContents():
341 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
342 problems.append(' %s:%d' % (f.LocalPath(), line_num))
344 if not problems:
345 return []
346 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
347 '\n'.join(problems))]
350 def _CheckNoNewWStrings(input_api, output_api):
351 """Checks to make sure we don't introduce use of wstrings."""
352 problems = []
353 for f in input_api.AffectedFiles():
354 if (not f.LocalPath().endswith(('.cc', '.h')) or
355 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
356 continue
358 allowWString = False
359 for line_num, line in f.ChangedContents():
360 if 'presubmit: allow wstring' in line:
361 allowWString = True
362 elif not allowWString and 'wstring' in line:
363 problems.append(' %s:%d' % (f.LocalPath(), line_num))
364 allowWString = False
365 else:
366 allowWString = False
368 if not problems:
369 return []
370 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
371 ' If you are calling a cross-platform API that accepts a wstring, '
372 'fix the API.\n' +
373 '\n'.join(problems))]
376 def _CheckNoDEPSGIT(input_api, output_api):
377 """Make sure .DEPS.git is never modified manually."""
378 if any(f.LocalPath().endswith('.DEPS.git') for f in
379 input_api.AffectedFiles()):
380 return [output_api.PresubmitError(
381 'Never commit changes to .DEPS.git. This file is maintained by an\n'
382 'automated system based on what\'s in DEPS and your changes will be\n'
383 'overwritten.\n'
384 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
385 'for more information')]
386 return []
389 def _CheckNoBannedFunctions(input_api, output_api):
390 """Make sure that banned functions are not used."""
391 warnings = []
392 errors = []
394 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.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 in _BANNED_OBJC_FUNCTIONS:
398 if func_name in line:
399 problems = warnings;
400 if error:
401 problems = errors;
402 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
403 for message_line in message:
404 problems.append(' %s' % message_line)
406 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
407 for f in input_api.AffectedFiles(file_filter=file_filter):
408 for line_num, line in f.ChangedContents():
409 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
410 def IsBlacklisted(affected_file, blacklist):
411 local_path = affected_file.LocalPath()
412 for item in blacklist:
413 if input_api.re.match(item, local_path):
414 return True
415 return False
416 if IsBlacklisted(f, excluded_paths):
417 continue
418 matched = False
419 if func_name[0:1] == '/':
420 regex = func_name[1:]
421 if input_api.re.search(regex, line):
422 matched = True
423 elif func_name in line:
424 matched = True
425 if matched:
426 problems = warnings;
427 if error:
428 problems = errors;
429 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
430 for message_line in message:
431 problems.append(' %s' % message_line)
433 result = []
434 if (warnings):
435 result.append(output_api.PresubmitPromptWarning(
436 'Banned functions were used.\n' + '\n'.join(warnings)))
437 if (errors):
438 result.append(output_api.PresubmitError(
439 'Banned functions were used.\n' + '\n'.join(errors)))
440 return result
443 def _CheckNoPragmaOnce(input_api, output_api):
444 """Make sure that banned functions are not used."""
445 files = []
446 pattern = input_api.re.compile(r'^#pragma\s+once',
447 input_api.re.MULTILINE)
448 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
449 if not f.LocalPath().endswith('.h'):
450 continue
451 contents = input_api.ReadFile(f)
452 if pattern.search(contents):
453 files.append(f)
455 if files:
456 return [output_api.PresubmitError(
457 'Do not use #pragma once in header files.\n'
458 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
459 files)]
460 return []
463 def _CheckNoTrinaryTrueFalse(input_api, output_api):
464 """Checks to make sure we don't introduce use of foo ? true : false."""
465 problems = []
466 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
467 for f in input_api.AffectedFiles():
468 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
469 continue
471 for line_num, line in f.ChangedContents():
472 if pattern.match(line):
473 problems.append(' %s:%d' % (f.LocalPath(), line_num))
475 if not problems:
476 return []
477 return [output_api.PresubmitPromptWarning(
478 'Please consider avoiding the "? true : false" pattern if possible.\n' +
479 '\n'.join(problems))]
482 def _CheckUnwantedDependencies(input_api, output_api):
483 """Runs checkdeps on #include statements added in this
484 change. Breaking - rules is an error, breaking ! rules is a
485 warning.
487 # We need to wait until we have an input_api object and use this
488 # roundabout construct to import checkdeps because this file is
489 # eval-ed and thus doesn't have __file__.
490 original_sys_path = sys.path
491 try:
492 sys.path = sys.path + [input_api.os_path.join(
493 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
494 import checkdeps
495 from cpp_checker import CppChecker
496 from rules import Rule
497 finally:
498 # Restore sys.path to what it was before.
499 sys.path = original_sys_path
501 added_includes = []
502 for f in input_api.AffectedFiles():
503 if not CppChecker.IsCppFile(f.LocalPath()):
504 continue
506 changed_lines = [line for line_num, line in f.ChangedContents()]
507 added_includes.append([f.LocalPath(), changed_lines])
509 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
511 error_descriptions = []
512 warning_descriptions = []
513 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
514 added_includes):
515 description_with_path = '%s\n %s' % (path, rule_description)
516 if rule_type == Rule.DISALLOW:
517 error_descriptions.append(description_with_path)
518 else:
519 warning_descriptions.append(description_with_path)
521 results = []
522 if error_descriptions:
523 results.append(output_api.PresubmitError(
524 'You added one or more #includes that violate checkdeps rules.',
525 error_descriptions))
526 if warning_descriptions:
527 results.append(output_api.PresubmitPromptOrNotify(
528 'You added one or more #includes of files that are temporarily\n'
529 'allowed but being removed. Can you avoid introducing the\n'
530 '#include? See relevant DEPS file(s) for details and contacts.',
531 warning_descriptions))
532 return results
535 def _CheckFilePermissions(input_api, output_api):
536 """Check that all files have their permissions properly set."""
537 if input_api.platform == 'win32':
538 return []
539 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
540 input_api.change.RepositoryRoot()]
541 for f in input_api.AffectedFiles():
542 args += ['--file', f.LocalPath()]
543 checkperms = input_api.subprocess.Popen(args,
544 stdout=input_api.subprocess.PIPE)
545 errors = checkperms.communicate()[0].strip()
546 if errors:
547 return [output_api.PresubmitError('checkperms.py failed.',
548 errors.splitlines())]
549 return []
552 def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
553 """Makes sure we don't include ui/aura/window_property.h
554 in header files.
556 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
557 errors = []
558 for f in input_api.AffectedFiles():
559 if not f.LocalPath().endswith('.h'):
560 continue
561 for line_num, line in f.ChangedContents():
562 if pattern.match(line):
563 errors.append(' %s:%d' % (f.LocalPath(), line_num))
565 results = []
566 if errors:
567 results.append(output_api.PresubmitError(
568 'Header files should not include ui/aura/window_property.h', errors))
569 return results
572 def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
573 """Checks that the lines in scope occur in the right order.
575 1. C system files in alphabetical order
576 2. C++ system files in alphabetical order
577 3. Project's .h files
580 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
581 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
582 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
584 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
586 state = C_SYSTEM_INCLUDES
588 previous_line = ''
589 previous_line_num = 0
590 problem_linenums = []
591 for line_num, line in scope:
592 if c_system_include_pattern.match(line):
593 if state != C_SYSTEM_INCLUDES:
594 problem_linenums.append((line_num, previous_line_num))
595 elif previous_line and previous_line > line:
596 problem_linenums.append((line_num, previous_line_num))
597 elif cpp_system_include_pattern.match(line):
598 if state == C_SYSTEM_INCLUDES:
599 state = CPP_SYSTEM_INCLUDES
600 elif state == CUSTOM_INCLUDES:
601 problem_linenums.append((line_num, previous_line_num))
602 elif previous_line and previous_line > line:
603 problem_linenums.append((line_num, previous_line_num))
604 elif custom_include_pattern.match(line):
605 if state != CUSTOM_INCLUDES:
606 state = CUSTOM_INCLUDES
607 elif previous_line and previous_line > line:
608 problem_linenums.append((line_num, previous_line_num))
609 else:
610 problem_linenums.append(line_num)
611 previous_line = line
612 previous_line_num = line_num
614 warnings = []
615 for (line_num, previous_line_num) in problem_linenums:
616 if line_num in changed_linenums or previous_line_num in changed_linenums:
617 warnings.append(' %s:%d' % (file_path, line_num))
618 return warnings
621 def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
622 """Checks the #include order for the given file f."""
624 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
625 # Exclude the following includes from the check:
626 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
627 # specific order.
628 # 2) <atlbase.h>, "build/build_config.h"
629 excluded_include_pattern = input_api.re.compile(
630 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
631 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
632 # Match the final or penultimate token if it is xxxtest so we can ignore it
633 # when considering the special first include.
634 test_file_tag_pattern = input_api.re.compile(
635 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
636 if_pattern = input_api.re.compile(
637 r'\s*#\s*(if|elif|else|endif|define|undef).*')
638 # Some files need specialized order of includes; exclude such files from this
639 # check.
640 uncheckable_includes_pattern = input_api.re.compile(
641 r'\s*#include '
642 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
644 contents = f.NewContents()
645 warnings = []
646 line_num = 0
648 # Handle the special first include. If the first include file is
649 # some/path/file.h, the corresponding including file can be some/path/file.cc,
650 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
651 # etc. It's also possible that no special first include exists.
652 # If the included file is some/path/file_platform.h the including file could
653 # also be some/path/file_xxxtest_platform.h.
654 including_file_base_name = test_file_tag_pattern.sub(
655 '', input_api.os_path.basename(f.LocalPath()))
657 for line in contents:
658 line_num += 1
659 if system_include_pattern.match(line):
660 # No special first include -> process the line again along with normal
661 # includes.
662 line_num -= 1
663 break
664 match = custom_include_pattern.match(line)
665 if match:
666 match_dict = match.groupdict()
667 header_basename = test_file_tag_pattern.sub(
668 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
670 if header_basename not in including_file_base_name:
671 # No special first include -> process the line again along with normal
672 # includes.
673 line_num -= 1
674 break
676 # Split into scopes: Each region between #if and #endif is its own scope.
677 scopes = []
678 current_scope = []
679 for line in contents[line_num:]:
680 line_num += 1
681 if uncheckable_includes_pattern.match(line):
682 continue
683 if if_pattern.match(line):
684 scopes.append(current_scope)
685 current_scope = []
686 elif ((system_include_pattern.match(line) or
687 custom_include_pattern.match(line)) and
688 not excluded_include_pattern.match(line)):
689 current_scope.append((line_num, line))
690 scopes.append(current_scope)
692 for scope in scopes:
693 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
694 changed_linenums))
695 return warnings
698 def _CheckIncludeOrder(input_api, output_api):
699 """Checks that the #include order is correct.
701 1. The corresponding header for source files.
702 2. C system files in alphabetical order
703 3. C++ system files in alphabetical order
704 4. Project's .h files in alphabetical order
706 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
707 these rules separately.
710 warnings = []
711 for f in input_api.AffectedFiles():
712 if f.LocalPath().endswith(('.cc', '.h')):
713 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
714 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
716 results = []
717 if warnings:
718 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
719 warnings))
720 return results
723 def _CheckForVersionControlConflictsInFile(input_api, f):
724 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
725 errors = []
726 for line_num, line in f.ChangedContents():
727 if pattern.match(line):
728 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
729 return errors
732 def _CheckForVersionControlConflicts(input_api, output_api):
733 """Usually this is not intentional and will cause a compile failure."""
734 errors = []
735 for f in input_api.AffectedFiles():
736 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
738 results = []
739 if errors:
740 results.append(output_api.PresubmitError(
741 'Version control conflict markers found, please resolve.', errors))
742 return results
745 def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
746 def FilterFile(affected_file):
747 """Filter function for use with input_api.AffectedSourceFiles,
748 below. This filters out everything except non-test files from
749 top-level directories that generally speaking should not hard-code
750 service URLs (e.g. src/android_webview/, src/content/ and others).
752 return input_api.FilterSourceFile(
753 affected_file,
754 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
755 black_list=(_EXCLUDED_PATHS +
756 _TEST_CODE_EXCLUDED_PATHS +
757 input_api.DEFAULT_BLACK_LIST))
759 base_pattern = '"[^"]*google\.com[^"]*"'
760 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
761 pattern = input_api.re.compile(base_pattern)
762 problems = [] # items are (filename, line_number, line)
763 for f in input_api.AffectedSourceFiles(FilterFile):
764 for line_num, line in f.ChangedContents():
765 if not comment_pattern.search(line) and pattern.search(line):
766 problems.append((f.LocalPath(), line_num, line))
768 if problems:
769 return [output_api.PresubmitPromptOrNotify(
770 'Most layers below src/chrome/ should not hardcode service URLs.\n'
771 'Are you sure this is correct?',
772 [' %s:%d: %s' % (
773 problem[0], problem[1], problem[2]) for problem in problems])]
774 else:
775 return []
778 def _CheckNoAbbreviationInPngFileName(input_api, output_api):
779 """Makes sure there are no abbreviations in the name of PNG files.
781 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
782 errors = []
783 for f in input_api.AffectedFiles(include_deletes=False):
784 if pattern.match(f.LocalPath()):
785 errors.append(' %s' % f.LocalPath())
787 results = []
788 if errors:
789 results.append(output_api.PresubmitError(
790 'The name of PNG files should not have abbreviations. \n'
791 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
792 'Contact oshima@chromium.org if you have questions.', errors))
793 return results
796 def _FilesToCheckForIncomingDeps(re, changed_lines):
797 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
798 a set of DEPS entries that we should look up.
800 For a directory (rather than a specific filename) we fake a path to
801 a specific filename by adding /DEPS. This is chosen as a file that
802 will seldom or never be subject to per-file include_rules.
804 # We ignore deps entries on auto-generated directories.
805 AUTO_GENERATED_DIRS = ['grit', 'jni']
807 # This pattern grabs the path without basename in the first
808 # parentheses, and the basename (if present) in the second. It
809 # relies on the simple heuristic that if there is a basename it will
810 # be a header file ending in ".h".
811 pattern = re.compile(
812 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
813 results = set()
814 for changed_line in changed_lines:
815 m = pattern.match(changed_line)
816 if m:
817 path = m.group(1)
818 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
819 if m.group(2):
820 results.add('%s%s' % (path, m.group(2)))
821 else:
822 results.add('%s/DEPS' % path)
823 return results
826 def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
827 """When a dependency prefixed with + is added to a DEPS file, we
828 want to make sure that the change is reviewed by an OWNER of the
829 target file or directory, to avoid layering violations from being
830 introduced. This check verifies that this happens.
832 changed_lines = set()
833 for f in input_api.AffectedFiles():
834 filename = input_api.os_path.basename(f.LocalPath())
835 if filename == 'DEPS':
836 changed_lines |= set(line.strip()
837 for line_num, line
838 in f.ChangedContents())
839 if not changed_lines:
840 return []
842 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
843 changed_lines)
844 if not virtual_depended_on_files:
845 return []
847 if input_api.is_committing:
848 if input_api.tbr:
849 return [output_api.PresubmitNotifyResult(
850 '--tbr was specified, skipping OWNERS check for DEPS additions')]
851 if not input_api.change.issue:
852 return [output_api.PresubmitError(
853 "DEPS approval by OWNERS check failed: this change has "
854 "no Rietveld issue number, so we can't check it for approvals.")]
855 output = output_api.PresubmitError
856 else:
857 output = output_api.PresubmitNotifyResult
859 owners_db = input_api.owners_db
860 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
861 input_api,
862 owners_db.email_regexp,
863 approval_needed=input_api.is_committing)
865 owner_email = owner_email or input_api.change.author_email
867 reviewers_plus_owner = set(reviewers)
868 if owner_email:
869 reviewers_plus_owner.add(owner_email)
870 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
871 reviewers_plus_owner)
873 # We strip the /DEPS part that was added by
874 # _FilesToCheckForIncomingDeps to fake a path to a file in a
875 # directory.
876 def StripDeps(path):
877 start_deps = path.rfind('/DEPS')
878 if start_deps != -1:
879 return path[:start_deps]
880 else:
881 return path
882 unapproved_dependencies = ["'+%s'," % StripDeps(path)
883 for path in missing_files]
885 if unapproved_dependencies:
886 output_list = [
887 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
888 '\n '.join(sorted(unapproved_dependencies)))]
889 if not input_api.is_committing:
890 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
891 output_list.append(output(
892 'Suggested missing target path OWNERS:\n %s' %
893 '\n '.join(suggested_owners or [])))
894 return output_list
896 return []
899 def _CheckSpamLogging(input_api, output_api):
900 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
901 black_list = (_EXCLUDED_PATHS +
902 _TEST_CODE_EXCLUDED_PATHS +
903 input_api.DEFAULT_BLACK_LIST +
904 (r"^base[\\\/]logging\.h$",
905 r"^base[\\\/]logging\.cc$",
906 r"^cloud_print[\\\/]",
907 r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
908 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
909 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
910 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
911 r"startup_browser_creator\.cc$",
912 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
913 r"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
914 r"logging_native_handler\.cc$",
915 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
916 r"gl_helper_benchmark\.cc$",
917 r"^native_client_sdk[\\\/]",
918 r"^remoting[\\\/]base[\\\/]logging\.h$",
919 r"^remoting[\\\/]host[\\\/].*",
920 r"^sandbox[\\\/]linux[\\\/].*",
921 r"^tools[\\\/]",
922 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
923 source_file_filter = lambda x: input_api.FilterSourceFile(
924 x, white_list=(file_inclusion_pattern,), black_list=black_list)
926 log_info = []
927 printf = []
929 for f in input_api.AffectedSourceFiles(source_file_filter):
930 contents = input_api.ReadFile(f, 'rb')
931 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
932 log_info.append(f.LocalPath())
933 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
934 log_info.append(f.LocalPath())
936 if re.search(r"\bprintf\(", contents):
937 printf.append(f.LocalPath())
938 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
939 printf.append(f.LocalPath())
941 if log_info:
942 return [output_api.PresubmitError(
943 'These files spam the console log with LOG(INFO):',
944 items=log_info)]
945 if printf:
946 return [output_api.PresubmitError(
947 'These files spam the console log with printf/fprintf:',
948 items=printf)]
949 return []
952 def _CheckForAnonymousVariables(input_api, output_api):
953 """These types are all expected to hold locks while in scope and
954 so should never be anonymous (which causes them to be immediately
955 destroyed)."""
956 they_who_must_be_named = [
957 'base::AutoLock',
958 'base::AutoReset',
959 'base::AutoUnlock',
960 'SkAutoAlphaRestore',
961 'SkAutoBitmapShaderInstall',
962 'SkAutoBlitterChoose',
963 'SkAutoBounderCommit',
964 'SkAutoCallProc',
965 'SkAutoCanvasRestore',
966 'SkAutoCommentBlock',
967 'SkAutoDescriptor',
968 'SkAutoDisableDirectionCheck',
969 'SkAutoDisableOvalCheck',
970 'SkAutoFree',
971 'SkAutoGlyphCache',
972 'SkAutoHDC',
973 'SkAutoLockColors',
974 'SkAutoLockPixels',
975 'SkAutoMalloc',
976 'SkAutoMaskFreeImage',
977 'SkAutoMutexAcquire',
978 'SkAutoPathBoundsUpdate',
979 'SkAutoPDFRelease',
980 'SkAutoRasterClipValidate',
981 'SkAutoRef',
982 'SkAutoTime',
983 'SkAutoTrace',
984 'SkAutoUnref',
986 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
987 # bad: base::AutoLock(lock.get());
988 # not bad: base::AutoLock lock(lock.get());
989 bad_pattern = input_api.re.compile(anonymous)
990 # good: new base::AutoLock(lock.get())
991 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
992 errors = []
994 for f in input_api.AffectedFiles():
995 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
996 continue
997 for linenum, line in f.ChangedContents():
998 if bad_pattern.search(line) and not good_pattern.search(line):
999 errors.append('%s:%d' % (f.LocalPath(), linenum))
1001 if errors:
1002 return [output_api.PresubmitError(
1003 'These lines create anonymous variables that need to be named:',
1004 items=errors)]
1005 return []
1008 def _CheckCygwinShell(input_api, output_api):
1009 source_file_filter = lambda x: input_api.FilterSourceFile(
1010 x, white_list=(r'.+\.(gyp|gypi)$',))
1011 cygwin_shell = []
1013 for f in input_api.AffectedSourceFiles(source_file_filter):
1014 for linenum, line in f.ChangedContents():
1015 if 'msvs_cygwin_shell' in line:
1016 cygwin_shell.append(f.LocalPath())
1017 break
1019 if cygwin_shell:
1020 return [output_api.PresubmitError(
1021 'These files should not use msvs_cygwin_shell (the default is 0):',
1022 items=cygwin_shell)]
1023 return []
1026 def _CheckUserActionUpdate(input_api, output_api):
1027 """Checks if any new user action has been added."""
1028 if any('actions.xml' == input_api.os_path.basename(f) for f in
1029 input_api.LocalPaths()):
1030 # If actions.xml is already included in the changelist, the PRESUBMIT
1031 # for actions.xml will do a more complete presubmit check.
1032 return []
1034 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm'))
1035 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)'
1036 current_actions = None
1037 for f in input_api.AffectedFiles(file_filter=file_filter):
1038 for line_num, line in f.ChangedContents():
1039 match = input_api.re.search(action_re, line)
1040 if match:
1041 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1042 # loaded only once.
1043 if not current_actions:
1044 with open('tools/metrics/actions/actions.xml') as actions_f:
1045 current_actions = actions_f.read()
1046 # Search for the matched user action name in |current_actions|.
1047 for action_name in match.groups():
1048 action = 'name="{0}"'.format(action_name)
1049 if action not in current_actions:
1050 return [output_api.PresubmitPromptWarning(
1051 'File %s line %d: %s is missing in '
1052 'tools/metrics/actions/actions.xml. Please run '
1053 'tools/metrics/actions/extract_actions.py to update.'
1054 % (f.LocalPath(), line_num, action_name))]
1055 return []
1058 def _CheckJavaStyle(input_api, output_api):
1059 """Runs checkstyle on changed java files and returns errors if any exist."""
1060 original_sys_path = sys.path
1061 try:
1062 sys.path = sys.path + [input_api.os_path.join(
1063 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1064 import checkstyle
1065 finally:
1066 # Restore sys.path to what it was before.
1067 sys.path = original_sys_path
1069 return checkstyle.RunCheckstyle(
1070 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1073 def _CommonChecks(input_api, output_api):
1074 """Checks common to both upload and commit."""
1075 results = []
1076 results.extend(input_api.canned_checks.PanProjectChecks(
1077 input_api, output_api,
1078 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
1079 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
1080 results.extend(
1081 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
1082 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
1083 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
1084 results.extend(_CheckNoNewWStrings(input_api, output_api))
1085 results.extend(_CheckNoDEPSGIT(input_api, output_api))
1086 results.extend(_CheckNoBannedFunctions(input_api, output_api))
1087 results.extend(_CheckNoPragmaOnce(input_api, output_api))
1088 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
1089 results.extend(_CheckUnwantedDependencies(input_api, output_api))
1090 results.extend(_CheckFilePermissions(input_api, output_api))
1091 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
1092 results.extend(_CheckIncludeOrder(input_api, output_api))
1093 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
1094 results.extend(_CheckPatchFiles(input_api, output_api))
1095 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
1096 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
1097 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
1098 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
1099 results.extend(
1100 input_api.canned_checks.CheckChangeHasNoTabs(
1101 input_api,
1102 output_api,
1103 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
1104 results.extend(_CheckSpamLogging(input_api, output_api))
1105 results.extend(_CheckForAnonymousVariables(input_api, output_api))
1106 results.extend(_CheckCygwinShell(input_api, output_api))
1107 results.extend(_CheckUserActionUpdate(input_api, output_api))
1109 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1110 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1111 input_api, output_api,
1112 input_api.PresubmitLocalPath(),
1113 whitelist=[r'^PRESUBMIT_test\.py$']))
1114 return results
1117 def _CheckSubversionConfig(input_api, output_api):
1118 """Verifies the subversion config file is correctly setup.
1120 Checks that autoprops are enabled, returns an error otherwise.
1122 join = input_api.os_path.join
1123 if input_api.platform == 'win32':
1124 appdata = input_api.environ.get('APPDATA', '')
1125 if not appdata:
1126 return [output_api.PresubmitError('%APPDATA% is not configured.')]
1127 path = join(appdata, 'Subversion', 'config')
1128 else:
1129 home = input_api.environ.get('HOME', '')
1130 if not home:
1131 return [output_api.PresubmitError('$HOME is not configured.')]
1132 path = join(home, '.subversion', 'config')
1134 error_msg = (
1135 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1136 'configure your subversion configuration file. This enables automatic\n'
1137 'properties to simplify the project maintenance.\n'
1138 'Pro-tip: just download and install\n'
1139 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
1141 try:
1142 lines = open(path, 'r').read().splitlines()
1143 # Make sure auto-props is enabled and check for 2 Chromium standard
1144 # auto-prop.
1145 if (not '*.cc = svn:eol-style=LF' in lines or
1146 not '*.pdf = svn:mime-type=application/pdf' in lines or
1147 not 'enable-auto-props = yes' in lines):
1148 return [
1149 output_api.PresubmitNotifyResult(
1150 'It looks like you have not configured your subversion config '
1151 'file or it is not up-to-date.\n' + error_msg)
1153 except (OSError, IOError):
1154 return [
1155 output_api.PresubmitNotifyResult(
1156 'Can\'t find your subversion config file.\n' + error_msg)
1158 return []
1161 def _CheckAuthorizedAuthor(input_api, output_api):
1162 """For non-googler/chromites committers, verify the author's email address is
1163 in AUTHORS.
1165 # TODO(maruel): Add it to input_api?
1166 import fnmatch
1168 author = input_api.change.author_email
1169 if not author:
1170 input_api.logging.info('No author, skipping AUTHOR check')
1171 return []
1172 authors_path = input_api.os_path.join(
1173 input_api.PresubmitLocalPath(), 'AUTHORS')
1174 valid_authors = (
1175 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1176 for line in open(authors_path))
1177 valid_authors = [item.group(1).lower() for item in valid_authors if item]
1178 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
1179 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
1180 return [output_api.PresubmitPromptWarning(
1181 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1182 '\n'
1183 'http://www.chromium.org/developers/contributing-code and read the '
1184 '"Legal" section\n'
1185 'If you are a chromite, verify the contributor signed the CLA.') %
1186 author)]
1187 return []
1190 def _CheckPatchFiles(input_api, output_api):
1191 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1192 if f.LocalPath().endswith(('.orig', '.rej'))]
1193 if problems:
1194 return [output_api.PresubmitError(
1195 "Don't commit .rej and .orig files.", problems)]
1196 else:
1197 return []
1200 def _DidYouMeanOSMacro(bad_macro):
1201 try:
1202 return {'A': 'OS_ANDROID',
1203 'B': 'OS_BSD',
1204 'C': 'OS_CHROMEOS',
1205 'F': 'OS_FREEBSD',
1206 'L': 'OS_LINUX',
1207 'M': 'OS_MACOSX',
1208 'N': 'OS_NACL',
1209 'O': 'OS_OPENBSD',
1210 'P': 'OS_POSIX',
1211 'S': 'OS_SOLARIS',
1212 'W': 'OS_WIN'}[bad_macro[3].upper()]
1213 except KeyError:
1214 return ''
1217 def _CheckForInvalidOSMacrosInFile(input_api, f):
1218 """Check for sensible looking, totally invalid OS macros."""
1219 preprocessor_statement = input_api.re.compile(r'^\s*#')
1220 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1221 results = []
1222 for lnum, line in f.ChangedContents():
1223 if preprocessor_statement.search(line):
1224 for match in os_macro.finditer(line):
1225 if not match.group(1) in _VALID_OS_MACROS:
1226 good = _DidYouMeanOSMacro(match.group(1))
1227 did_you_mean = ' (did you mean %s?)' % good if good else ''
1228 results.append(' %s:%d %s%s' % (f.LocalPath(),
1229 lnum,
1230 match.group(1),
1231 did_you_mean))
1232 return results
1235 def _CheckForInvalidOSMacros(input_api, output_api):
1236 """Check all affected files for invalid OS macros."""
1237 bad_macros = []
1238 for f in input_api.AffectedFiles():
1239 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1240 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1242 if not bad_macros:
1243 return []
1245 return [output_api.PresubmitError(
1246 'Possibly invalid OS macro[s] found. Please fix your code\n'
1247 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1250 def CheckChangeOnUpload(input_api, output_api):
1251 results = []
1252 results.extend(_CommonChecks(input_api, output_api))
1253 results.extend(_CheckJavaStyle(input_api, output_api))
1254 return results
1257 def GetDefaultTryConfigs(bots=None):
1258 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1260 To add tests to this list, they MUST be in the the corresponding master's
1261 gatekeeper config. For example, anything on master.chromium would be closed by
1262 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1264 If 'bots' is specified, will only return configurations for bots in that list.
1267 standard_tests = [
1268 'base_unittests',
1269 'browser_tests',
1270 'cacheinvalidation_unittests',
1271 'check_deps',
1272 'check_deps2git',
1273 'content_browsertests',
1274 'content_unittests',
1275 'crypto_unittests',
1276 'gpu_unittests',
1277 'interactive_ui_tests',
1278 'ipc_tests',
1279 'jingle_unittests',
1280 'media_unittests',
1281 'net_unittests',
1282 'ppapi_unittests',
1283 'printing_unittests',
1284 'sql_unittests',
1285 'sync_unit_tests',
1286 'unit_tests',
1287 # Broken in release.
1288 #'url_unittests',
1289 #'webkit_unit_tests',
1292 builders_and_tests = {
1293 # TODO(maruel): Figure out a way to run 'sizes' where people can
1294 # effectively update the perf expectation correctly. This requires a
1295 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1296 # incremental build. Reference:
1297 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1298 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1299 # of this step as a try job failure.
1300 'android_aosp': ['compile'],
1301 'android_clang_dbg': ['slave_steps'],
1302 'android_dbg': ['slave_steps'],
1303 'cros_x86': ['defaulttests'],
1304 'ios_dbg_simulator': [
1305 'compile',
1306 'base_unittests',
1307 'content_unittests',
1308 'crypto_unittests',
1309 'url_unittests',
1310 'net_unittests',
1311 'sql_unittests',
1312 'ui_unittests',
1314 'ios_rel_device': ['compile'],
1315 'linux_asan': ['compile'],
1316 'mac_asan': ['compile'],
1317 #TODO(stip): Change the name of this builder to reflect that it's release.
1318 'linux_gtk': standard_tests,
1319 'linux_chromeos_asan': ['compile'],
1320 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
1321 'linux_chromium_chromeos_rel': ['defaulttests'],
1322 'linux_chromium_compile_dbg': ['defaulttests'],
1323 'linux_chromium_rel': ['defaulttests'],
1324 'linux_chromium_clang_dbg': ['defaulttests'],
1325 'linux_nacl_sdk_build': ['compile'],
1326 'linux_rel': [
1327 'telemetry_perf_unittests',
1328 'telemetry_unittests',
1330 'mac_chromium_compile_dbg': ['defaulttests'],
1331 'mac_chromium_rel': ['defaulttests'],
1332 'mac_nacl_sdk_build': ['compile'],
1333 'mac_rel': [
1334 'telemetry_perf_unittests',
1335 'telemetry_unittests',
1337 'win': ['compile'],
1338 'win_chromium_compile_dbg': ['defaulttests'],
1339 'win_nacl_sdk_build': ['compile'],
1340 'win_rel': standard_tests + [
1341 'app_list_unittests',
1342 'ash_unittests',
1343 'aura_unittests',
1344 'cc_unittests',
1345 'chrome_elf_unittests',
1346 'chromedriver_unittests',
1347 'components_unittests',
1348 'compositor_unittests',
1349 'events_unittests',
1350 'gfx_unittests',
1351 'google_apis_unittests',
1352 'installer_util_unittests',
1353 'mini_installer_test',
1354 'nacl_integration',
1355 'remoting_unittests',
1356 'sync_integration_tests',
1357 'telemetry_perf_unittests',
1358 'telemetry_unittests',
1359 'views_unittests',
1361 'win_x64_rel': [
1362 'base_unittests',
1366 swarm_enabled_builders = (
1367 # http://crbug.com/354263
1368 # 'linux_rel',
1369 # 'mac_rel',
1370 # 'win_rel',
1373 swarm_enabled_tests = (
1374 'base_unittests',
1375 'browser_tests',
1376 'interactive_ui_tests',
1377 'net_unittests',
1378 'unit_tests',
1381 for bot in builders_and_tests:
1382 if bot in swarm_enabled_builders:
1383 builders_and_tests[bot] = [x + '_swarm' if x in swarm_enabled_tests else x
1384 for x in builders_and_tests[bot]]
1386 if bots:
1387 return {
1388 'tryserver.chromium': dict((bot, set(builders_and_tests[bot]))
1389 for bot in bots)
1391 else:
1392 return {
1393 'tryserver.chromium': dict(
1394 (bot, set(tests))
1395 for bot, tests in builders_and_tests.iteritems())
1399 def CheckChangeOnCommit(input_api, output_api):
1400 results = []
1401 results.extend(_CommonChecks(input_api, output_api))
1402 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1403 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1404 # input_api, output_api, sources))
1405 # Make sure the tree is 'open'.
1406 results.extend(input_api.canned_checks.CheckTreeIsOpen(
1407 input_api,
1408 output_api,
1409 json_url='http://chromium-status.appspot.com/current?format=json'))
1411 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1412 input_api, output_api))
1413 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1414 input_api, output_api))
1415 results.extend(_CheckSubversionConfig(input_api, output_api))
1416 return results
1419 def GetPreferredTryMasters(project, change):
1420 files = change.LocalPaths()
1422 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
1423 return {}
1425 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
1426 return GetDefaultTryConfigs([
1427 'mac_chromium_compile_dbg',
1428 'mac_chromium_rel',
1430 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
1431 return GetDefaultTryConfigs(['win', 'win_rel'])
1432 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
1433 return GetDefaultTryConfigs([
1434 'android_aosp',
1435 'android_clang_dbg',
1436 'android_dbg',
1438 if all(re.search('[/_]ios[/_.]', f) for f in files):
1439 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
1441 builders = [
1442 'android_clang_dbg',
1443 'android_dbg',
1444 'ios_dbg_simulator',
1445 'ios_rel_device',
1446 'linux_chromium_chromeos_rel',
1447 'linux_chromium_clang_dbg',
1448 'linux_chromium_rel',
1449 'mac_chromium_compile_dbg',
1450 'mac_chromium_rel',
1451 'win_chromium_compile_dbg',
1452 'win_rel',
1453 'win_x64_rel',
1456 # Match things like path/aura/file.cc and path/file_aura.cc.
1457 # Same for chromeos.
1458 if any(re.search('[/_](aura|chromeos)', f) for f in files):
1459 builders.extend([
1460 'linux_chromeos_asan',
1461 'linux_chromium_chromeos_clang_dbg'
1464 # If there are gyp changes to base, build, or chromeos, run a full cros build
1465 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1466 # files have a much higher chance of breaking the cros build, which is
1467 # differnt from the linux_chromeos build that most chrome developers test
1468 # with.
1469 if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files):
1470 builders.extend(['cros_x86'])
1472 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1473 # unless they're .gyp(i) files as changes to those files can break the gyp
1474 # step on that bot.
1475 if (not all(re.search('^chrome', f) for f in files) or
1476 any(re.search('\.gypi?$', f) for f in files)):
1477 builders.extend(['android_aosp'])
1479 return GetDefaultTryConfigs(builders)