Reland Double-Click on a Tab Close causes Maximize
[chromium-blink-merge.git] / PRESUBMIT.py
blobb87d26ba1b5921aac7cbe02feb09a50c5e3738fe
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[\\\/]tools[\\\/]plugin[\\\/].*",
38 # Fragment of a regular expression that matches C++ and Objective-C++
39 # implementation files.
40 _IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
42 # Regular expression that matches code only used for test binaries
43 # (best effort).
44 _TEST_CODE_EXCLUDED_PATHS = (
45 r'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
46 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
47 r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
48 _IMPLEMENTATION_EXTENSIONS,
49 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
50 r'.*[/\\](test|tool(s)?)[/\\].*',
51 # content_shell is used for running layout tests.
52 r'content[/\\]shell[/\\].*',
53 # At request of folks maintaining this folder.
54 r'chrome[/\\]browser[/\\]automation[/\\].*',
55 # Non-production example code.
56 r'mojo[/\\]examples[/\\].*',
59 _TEST_ONLY_WARNING = (
60 'You might be calling functions intended only for testing from\n'
61 'production code. It is OK to ignore this warning if you know what\n'
62 'you are doing, as the heuristics used to detect the situation are\n'
63 'not perfect. The commit queue will not block on this warning.')
66 _INCLUDE_ORDER_WARNING = (
67 'Your #include order seems to be broken. Send mail to\n'
68 'marja@chromium.org if this is not the case.')
71 _BANNED_OBJC_FUNCTIONS = (
73 'addTrackingRect:',
75 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
76 'prohibited. Please use CrTrackingArea instead.',
77 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
79 False,
82 r'/NSTrackingArea\W',
84 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
85 'instead.',
86 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
88 False,
91 'convertPointFromBase:',
93 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
94 'Please use |convertPoint:(point) fromView:nil| instead.',
95 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
97 True,
100 'convertPointToBase:',
102 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
103 'Please use |convertPoint:(point) toView:nil| instead.',
104 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
106 True,
109 'convertRectFromBase:',
111 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
112 'Please use |convertRect:(point) fromView:nil| instead.',
113 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
115 True,
118 'convertRectToBase:',
120 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
121 'Please use |convertRect:(point) toView:nil| instead.',
122 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
124 True,
127 'convertSizeFromBase:',
129 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
130 'Please use |convertSize:(point) fromView:nil| instead.',
131 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
133 True,
136 'convertSizeToBase:',
138 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
139 'Please use |convertSize:(point) toView:nil| instead.',
140 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
142 True,
147 _BANNED_CPP_FUNCTIONS = (
148 # Make sure that gtest's FRIEND_TEST() macro is not used; the
149 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
150 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
152 'FRIEND_TEST(',
154 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
155 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
157 False,
161 'ScopedAllowIO',
163 'New code should not use ScopedAllowIO. Post a task to the blocking',
164 'pool or the FILE thread instead.',
166 True,
168 r"^components[\\\/]breakpad[\\\/]app[\\\/]breakpad_mac\.mm$",
169 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
170 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
171 r"^mojo[\\\/]system[\\\/]raw_shared_buffer_posix\.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$',
237 r'/v8::Extension\(',
239 'Do not introduce new v8::Extensions into the code base, use',
240 'gin::Wrappable instead. See http://crbug.com/334679',
242 True,
244 r'extensions[/\\]renderer[/\\]safe_builtins\.*',
250 _VALID_OS_MACROS = (
251 # Please keep sorted.
252 'OS_ANDROID',
253 'OS_ANDROID_HOST',
254 'OS_BSD',
255 'OS_CAT', # For testing.
256 'OS_CHROMEOS',
257 'OS_FREEBSD',
258 'OS_IOS',
259 'OS_LINUX',
260 'OS_MACOSX',
261 'OS_NACL',
262 'OS_OPENBSD',
263 'OS_POSIX',
264 'OS_QNX',
265 'OS_SOLARIS',
266 'OS_WIN',
270 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
271 """Attempts to prevent use of functions intended only for testing in
272 non-testing code. For now this is just a best-effort implementation
273 that ignores header files and may have some false positives. A
274 better implementation would probably need a proper C++ parser.
276 # We only scan .cc files and the like, as the declaration of
277 # for-testing functions in header files are hard to distinguish from
278 # calls to such functions without a proper C++ parser.
279 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
281 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
282 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
283 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
284 exclusion_pattern = input_api.re.compile(
285 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
286 base_function_pattern, base_function_pattern))
288 def FilterFile(affected_file):
289 black_list = (_EXCLUDED_PATHS +
290 _TEST_CODE_EXCLUDED_PATHS +
291 input_api.DEFAULT_BLACK_LIST)
292 return input_api.FilterSourceFile(
293 affected_file,
294 white_list=(file_inclusion_pattern, ),
295 black_list=black_list)
297 problems = []
298 for f in input_api.AffectedSourceFiles(FilterFile):
299 local_path = f.LocalPath()
300 for line_number, line in f.ChangedContents():
301 if (inclusion_pattern.search(line) and
302 not comment_pattern.search(line) and
303 not exclusion_pattern.search(line)):
304 problems.append(
305 '%s:%d\n %s' % (local_path, line_number, line.strip()))
307 if problems:
308 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
309 else:
310 return []
313 def _CheckNoIOStreamInHeaders(input_api, output_api):
314 """Checks to make sure no .h files include <iostream>."""
315 files = []
316 pattern = input_api.re.compile(r'^#include\s*<iostream>',
317 input_api.re.MULTILINE)
318 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
319 if not f.LocalPath().endswith('.h'):
320 continue
321 contents = input_api.ReadFile(f)
322 if pattern.search(contents):
323 files.append(f)
325 if len(files):
326 return [ output_api.PresubmitError(
327 'Do not #include <iostream> in header files, since it inserts static '
328 'initialization into every file including the header. Instead, '
329 '#include <ostream>. See http://crbug.com/94794',
330 files) ]
331 return []
334 def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
335 """Checks to make sure no source files use UNIT_TEST"""
336 problems = []
337 for f in input_api.AffectedFiles():
338 if (not f.LocalPath().endswith(('.cc', '.mm'))):
339 continue
341 for line_num, line in f.ChangedContents():
342 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
343 problems.append(' %s:%d' % (f.LocalPath(), line_num))
345 if not problems:
346 return []
347 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
348 '\n'.join(problems))]
351 def _CheckNoNewWStrings(input_api, output_api):
352 """Checks to make sure we don't introduce use of wstrings."""
353 problems = []
354 for f in input_api.AffectedFiles():
355 if (not f.LocalPath().endswith(('.cc', '.h')) or
356 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
357 continue
359 allowWString = False
360 for line_num, line in f.ChangedContents():
361 if 'presubmit: allow wstring' in line:
362 allowWString = True
363 elif not allowWString and 'wstring' in line:
364 problems.append(' %s:%d' % (f.LocalPath(), line_num))
365 allowWString = False
366 else:
367 allowWString = False
369 if not problems:
370 return []
371 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
372 ' If you are calling a cross-platform API that accepts a wstring, '
373 'fix the API.\n' +
374 '\n'.join(problems))]
377 def _CheckNoDEPSGIT(input_api, output_api):
378 """Make sure .DEPS.git is never modified manually."""
379 if any(f.LocalPath().endswith('.DEPS.git') for f in
380 input_api.AffectedFiles()):
381 return [output_api.PresubmitError(
382 'Never commit changes to .DEPS.git. This file is maintained by an\n'
383 'automated system based on what\'s in DEPS and your changes will be\n'
384 'overwritten.\n'
385 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
386 'for more information')]
387 return []
390 def _CheckNoBannedFunctions(input_api, output_api):
391 """Make sure that banned functions are not used."""
392 warnings = []
393 errors = []
395 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
396 for f in input_api.AffectedFiles(file_filter=file_filter):
397 for line_num, line in f.ChangedContents():
398 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
399 matched = False
400 if func_name[0:1] == '/':
401 regex = func_name[1:]
402 if input_api.re.search(regex, line):
403 matched = True
404 elif func_name in line:
405 matched = True
406 if matched:
407 problems = warnings;
408 if error:
409 problems = errors;
410 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
411 for message_line in message:
412 problems.append(' %s' % message_line)
414 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
415 for f in input_api.AffectedFiles(file_filter=file_filter):
416 for line_num, line in f.ChangedContents():
417 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
418 def IsBlacklisted(affected_file, blacklist):
419 local_path = affected_file.LocalPath()
420 for item in blacklist:
421 if input_api.re.match(item, local_path):
422 return True
423 return False
424 if IsBlacklisted(f, excluded_paths):
425 continue
426 matched = False
427 if func_name[0:1] == '/':
428 regex = func_name[1:]
429 if input_api.re.search(regex, line):
430 matched = True
431 elif func_name in line:
432 matched = True
433 if matched:
434 problems = warnings;
435 if error:
436 problems = errors;
437 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
438 for message_line in message:
439 problems.append(' %s' % message_line)
441 result = []
442 if (warnings):
443 result.append(output_api.PresubmitPromptWarning(
444 'Banned functions were used.\n' + '\n'.join(warnings)))
445 if (errors):
446 result.append(output_api.PresubmitError(
447 'Banned functions were used.\n' + '\n'.join(errors)))
448 return result
451 def _CheckNoPragmaOnce(input_api, output_api):
452 """Make sure that banned functions are not used."""
453 files = []
454 pattern = input_api.re.compile(r'^#pragma\s+once',
455 input_api.re.MULTILINE)
456 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
457 if not f.LocalPath().endswith('.h'):
458 continue
459 contents = input_api.ReadFile(f)
460 if pattern.search(contents):
461 files.append(f)
463 if files:
464 return [output_api.PresubmitError(
465 'Do not use #pragma once in header files.\n'
466 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
467 files)]
468 return []
471 def _CheckNoTrinaryTrueFalse(input_api, output_api):
472 """Checks to make sure we don't introduce use of foo ? true : false."""
473 problems = []
474 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
475 for f in input_api.AffectedFiles():
476 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
477 continue
479 for line_num, line in f.ChangedContents():
480 if pattern.match(line):
481 problems.append(' %s:%d' % (f.LocalPath(), line_num))
483 if not problems:
484 return []
485 return [output_api.PresubmitPromptWarning(
486 'Please consider avoiding the "? true : false" pattern if possible.\n' +
487 '\n'.join(problems))]
490 def _CheckUnwantedDependencies(input_api, output_api):
491 """Runs checkdeps on #include statements added in this
492 change. Breaking - rules is an error, breaking ! rules is a
493 warning.
495 # We need to wait until we have an input_api object and use this
496 # roundabout construct to import checkdeps because this file is
497 # eval-ed and thus doesn't have __file__.
498 original_sys_path = sys.path
499 try:
500 sys.path = sys.path + [input_api.os_path.join(
501 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
502 import checkdeps
503 from cpp_checker import CppChecker
504 from rules import Rule
505 finally:
506 # Restore sys.path to what it was before.
507 sys.path = original_sys_path
509 added_includes = []
510 for f in input_api.AffectedFiles():
511 if not CppChecker.IsCppFile(f.LocalPath()):
512 continue
514 changed_lines = [line for line_num, line in f.ChangedContents()]
515 added_includes.append([f.LocalPath(), changed_lines])
517 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
519 error_descriptions = []
520 warning_descriptions = []
521 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
522 added_includes):
523 description_with_path = '%s\n %s' % (path, rule_description)
524 if rule_type == Rule.DISALLOW:
525 error_descriptions.append(description_with_path)
526 else:
527 warning_descriptions.append(description_with_path)
529 results = []
530 if error_descriptions:
531 results.append(output_api.PresubmitError(
532 'You added one or more #includes that violate checkdeps rules.',
533 error_descriptions))
534 if warning_descriptions:
535 results.append(output_api.PresubmitPromptOrNotify(
536 'You added one or more #includes of files that are temporarily\n'
537 'allowed but being removed. Can you avoid introducing the\n'
538 '#include? See relevant DEPS file(s) for details and contacts.',
539 warning_descriptions))
540 return results
543 def _CheckFilePermissions(input_api, output_api):
544 """Check that all files have their permissions properly set."""
545 if input_api.platform == 'win32':
546 return []
547 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
548 input_api.change.RepositoryRoot()]
549 for f in input_api.AffectedFiles():
550 args += ['--file', f.LocalPath()]
551 checkperms = input_api.subprocess.Popen(args,
552 stdout=input_api.subprocess.PIPE)
553 errors = checkperms.communicate()[0].strip()
554 if errors:
555 return [output_api.PresubmitError('checkperms.py failed.',
556 errors.splitlines())]
557 return []
560 def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
561 """Makes sure we don't include ui/aura/window_property.h
562 in header files.
564 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
565 errors = []
566 for f in input_api.AffectedFiles():
567 if not f.LocalPath().endswith('.h'):
568 continue
569 for line_num, line in f.ChangedContents():
570 if pattern.match(line):
571 errors.append(' %s:%d' % (f.LocalPath(), line_num))
573 results = []
574 if errors:
575 results.append(output_api.PresubmitError(
576 'Header files should not include ui/aura/window_property.h', errors))
577 return results
580 def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
581 """Checks that the lines in scope occur in the right order.
583 1. C system files in alphabetical order
584 2. C++ system files in alphabetical order
585 3. Project's .h files
588 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
589 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
590 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
592 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
594 state = C_SYSTEM_INCLUDES
596 previous_line = ''
597 previous_line_num = 0
598 problem_linenums = []
599 for line_num, line in scope:
600 if c_system_include_pattern.match(line):
601 if state != C_SYSTEM_INCLUDES:
602 problem_linenums.append((line_num, previous_line_num))
603 elif previous_line and previous_line > line:
604 problem_linenums.append((line_num, previous_line_num))
605 elif cpp_system_include_pattern.match(line):
606 if state == C_SYSTEM_INCLUDES:
607 state = CPP_SYSTEM_INCLUDES
608 elif state == CUSTOM_INCLUDES:
609 problem_linenums.append((line_num, previous_line_num))
610 elif previous_line and previous_line > line:
611 problem_linenums.append((line_num, previous_line_num))
612 elif custom_include_pattern.match(line):
613 if state != CUSTOM_INCLUDES:
614 state = CUSTOM_INCLUDES
615 elif previous_line and previous_line > line:
616 problem_linenums.append((line_num, previous_line_num))
617 else:
618 problem_linenums.append(line_num)
619 previous_line = line
620 previous_line_num = line_num
622 warnings = []
623 for (line_num, previous_line_num) in problem_linenums:
624 if line_num in changed_linenums or previous_line_num in changed_linenums:
625 warnings.append(' %s:%d' % (file_path, line_num))
626 return warnings
629 def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
630 """Checks the #include order for the given file f."""
632 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
633 # Exclude the following includes from the check:
634 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
635 # specific order.
636 # 2) <atlbase.h>, "build/build_config.h"
637 excluded_include_pattern = input_api.re.compile(
638 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
639 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
640 # Match the final or penultimate token if it is xxxtest so we can ignore it
641 # when considering the special first include.
642 test_file_tag_pattern = input_api.re.compile(
643 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
644 if_pattern = input_api.re.compile(
645 r'\s*#\s*(if|elif|else|endif|define|undef).*')
646 # Some files need specialized order of includes; exclude such files from this
647 # check.
648 uncheckable_includes_pattern = input_api.re.compile(
649 r'\s*#include '
650 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
652 contents = f.NewContents()
653 warnings = []
654 line_num = 0
656 # Handle the special first include. If the first include file is
657 # some/path/file.h, the corresponding including file can be some/path/file.cc,
658 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
659 # etc. It's also possible that no special first include exists.
660 # If the included file is some/path/file_platform.h the including file could
661 # also be some/path/file_xxxtest_platform.h.
662 including_file_base_name = test_file_tag_pattern.sub(
663 '', input_api.os_path.basename(f.LocalPath()))
665 for line in contents:
666 line_num += 1
667 if system_include_pattern.match(line):
668 # No special first include -> process the line again along with normal
669 # includes.
670 line_num -= 1
671 break
672 match = custom_include_pattern.match(line)
673 if match:
674 match_dict = match.groupdict()
675 header_basename = test_file_tag_pattern.sub(
676 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
678 if header_basename not in including_file_base_name:
679 # No special first include -> process the line again along with normal
680 # includes.
681 line_num -= 1
682 break
684 # Split into scopes: Each region between #if and #endif is its own scope.
685 scopes = []
686 current_scope = []
687 for line in contents[line_num:]:
688 line_num += 1
689 if uncheckable_includes_pattern.match(line):
690 continue
691 if if_pattern.match(line):
692 scopes.append(current_scope)
693 current_scope = []
694 elif ((system_include_pattern.match(line) or
695 custom_include_pattern.match(line)) and
696 not excluded_include_pattern.match(line)):
697 current_scope.append((line_num, line))
698 scopes.append(current_scope)
700 for scope in scopes:
701 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
702 changed_linenums))
703 return warnings
706 def _CheckIncludeOrder(input_api, output_api):
707 """Checks that the #include order is correct.
709 1. The corresponding header for source files.
710 2. C system files in alphabetical order
711 3. C++ system files in alphabetical order
712 4. Project's .h files in alphabetical order
714 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
715 these rules separately.
718 warnings = []
719 for f in input_api.AffectedFiles():
720 if f.LocalPath().endswith(('.cc', '.h')):
721 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
722 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
724 results = []
725 if warnings:
726 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
727 warnings))
728 return results
731 def _CheckForVersionControlConflictsInFile(input_api, f):
732 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
733 errors = []
734 for line_num, line in f.ChangedContents():
735 if pattern.match(line):
736 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
737 return errors
740 def _CheckForVersionControlConflicts(input_api, output_api):
741 """Usually this is not intentional and will cause a compile failure."""
742 errors = []
743 for f in input_api.AffectedFiles():
744 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
746 results = []
747 if errors:
748 results.append(output_api.PresubmitError(
749 'Version control conflict markers found, please resolve.', errors))
750 return results
753 def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
754 def FilterFile(affected_file):
755 """Filter function for use with input_api.AffectedSourceFiles,
756 below. This filters out everything except non-test files from
757 top-level directories that generally speaking should not hard-code
758 service URLs (e.g. src/android_webview/, src/content/ and others).
760 return input_api.FilterSourceFile(
761 affected_file,
762 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
763 black_list=(_EXCLUDED_PATHS +
764 _TEST_CODE_EXCLUDED_PATHS +
765 input_api.DEFAULT_BLACK_LIST))
767 base_pattern = '"[^"]*google\.com[^"]*"'
768 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
769 pattern = input_api.re.compile(base_pattern)
770 problems = [] # items are (filename, line_number, line)
771 for f in input_api.AffectedSourceFiles(FilterFile):
772 for line_num, line in f.ChangedContents():
773 if not comment_pattern.search(line) and pattern.search(line):
774 problems.append((f.LocalPath(), line_num, line))
776 if problems:
777 return [output_api.PresubmitPromptOrNotify(
778 'Most layers below src/chrome/ should not hardcode service URLs.\n'
779 'Are you sure this is correct?',
780 [' %s:%d: %s' % (
781 problem[0], problem[1], problem[2]) for problem in problems])]
782 else:
783 return []
786 def _CheckNoAbbreviationInPngFileName(input_api, output_api):
787 """Makes sure there are no abbreviations in the name of PNG files.
789 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
790 errors = []
791 for f in input_api.AffectedFiles(include_deletes=False):
792 if pattern.match(f.LocalPath()):
793 errors.append(' %s' % f.LocalPath())
795 results = []
796 if errors:
797 results.append(output_api.PresubmitError(
798 'The name of PNG files should not have abbreviations. \n'
799 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
800 'Contact oshima@chromium.org if you have questions.', errors))
801 return results
804 def _FilesToCheckForIncomingDeps(re, changed_lines):
805 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
806 a set of DEPS entries that we should look up.
808 For a directory (rather than a specific filename) we fake a path to
809 a specific filename by adding /DEPS. This is chosen as a file that
810 will seldom or never be subject to per-file include_rules.
812 # We ignore deps entries on auto-generated directories.
813 AUTO_GENERATED_DIRS = ['grit', 'jni']
815 # This pattern grabs the path without basename in the first
816 # parentheses, and the basename (if present) in the second. It
817 # relies on the simple heuristic that if there is a basename it will
818 # be a header file ending in ".h".
819 pattern = re.compile(
820 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
821 results = set()
822 for changed_line in changed_lines:
823 m = pattern.match(changed_line)
824 if m:
825 path = m.group(1)
826 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
827 if m.group(2):
828 results.add('%s%s' % (path, m.group(2)))
829 else:
830 results.add('%s/DEPS' % path)
831 return results
834 def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
835 """When a dependency prefixed with + is added to a DEPS file, we
836 want to make sure that the change is reviewed by an OWNER of the
837 target file or directory, to avoid layering violations from being
838 introduced. This check verifies that this happens.
840 changed_lines = set()
841 for f in input_api.AffectedFiles():
842 filename = input_api.os_path.basename(f.LocalPath())
843 if filename == 'DEPS':
844 changed_lines |= set(line.strip()
845 for line_num, line
846 in f.ChangedContents())
847 if not changed_lines:
848 return []
850 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
851 changed_lines)
852 if not virtual_depended_on_files:
853 return []
855 if input_api.is_committing:
856 if input_api.tbr:
857 return [output_api.PresubmitNotifyResult(
858 '--tbr was specified, skipping OWNERS check for DEPS additions')]
859 if not input_api.change.issue:
860 return [output_api.PresubmitError(
861 "DEPS approval by OWNERS check failed: this change has "
862 "no Rietveld issue number, so we can't check it for approvals.")]
863 output = output_api.PresubmitError
864 else:
865 output = output_api.PresubmitNotifyResult
867 owners_db = input_api.owners_db
868 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
869 input_api,
870 owners_db.email_regexp,
871 approval_needed=input_api.is_committing)
873 owner_email = owner_email or input_api.change.author_email
875 reviewers_plus_owner = set(reviewers)
876 if owner_email:
877 reviewers_plus_owner.add(owner_email)
878 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
879 reviewers_plus_owner)
881 # We strip the /DEPS part that was added by
882 # _FilesToCheckForIncomingDeps to fake a path to a file in a
883 # directory.
884 def StripDeps(path):
885 start_deps = path.rfind('/DEPS')
886 if start_deps != -1:
887 return path[:start_deps]
888 else:
889 return path
890 unapproved_dependencies = ["'+%s'," % StripDeps(path)
891 for path in missing_files]
893 if unapproved_dependencies:
894 output_list = [
895 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
896 '\n '.join(sorted(unapproved_dependencies)))]
897 if not input_api.is_committing:
898 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
899 output_list.append(output(
900 'Suggested missing target path OWNERS:\n %s' %
901 '\n '.join(suggested_owners or [])))
902 return output_list
904 return []
907 def _CheckSpamLogging(input_api, output_api):
908 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
909 black_list = (_EXCLUDED_PATHS +
910 _TEST_CODE_EXCLUDED_PATHS +
911 input_api.DEFAULT_BLACK_LIST +
912 (r"^base[\\\/]logging\.h$",
913 r"^base[\\\/]logging\.cc$",
914 r"^cloud_print[\\\/]",
915 r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
916 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
917 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
918 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
919 r"startup_browser_creator\.cc$",
920 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
921 r"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
922 r"logging_native_handler\.cc$",
923 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
924 r"gl_helper_benchmark\.cc$",
925 r"^native_client_sdk[\\\/]",
926 r"^remoting[\\\/]base[\\\/]logging\.h$",
927 r"^remoting[\\\/]host[\\\/].*",
928 r"^sandbox[\\\/]linux[\\\/].*",
929 r"^tools[\\\/]",
930 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
931 source_file_filter = lambda x: input_api.FilterSourceFile(
932 x, white_list=(file_inclusion_pattern,), black_list=black_list)
934 log_info = []
935 printf = []
937 for f in input_api.AffectedSourceFiles(source_file_filter):
938 contents = input_api.ReadFile(f, 'rb')
939 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
940 log_info.append(f.LocalPath())
941 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
942 log_info.append(f.LocalPath())
944 if re.search(r"\bprintf\(", contents):
945 printf.append(f.LocalPath())
946 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
947 printf.append(f.LocalPath())
949 if log_info:
950 return [output_api.PresubmitError(
951 'These files spam the console log with LOG(INFO):',
952 items=log_info)]
953 if printf:
954 return [output_api.PresubmitError(
955 'These files spam the console log with printf/fprintf:',
956 items=printf)]
957 return []
960 def _CheckForAnonymousVariables(input_api, output_api):
961 """These types are all expected to hold locks while in scope and
962 so should never be anonymous (which causes them to be immediately
963 destroyed)."""
964 they_who_must_be_named = [
965 'base::AutoLock',
966 'base::AutoReset',
967 'base::AutoUnlock',
968 'SkAutoAlphaRestore',
969 'SkAutoBitmapShaderInstall',
970 'SkAutoBlitterChoose',
971 'SkAutoBounderCommit',
972 'SkAutoCallProc',
973 'SkAutoCanvasRestore',
974 'SkAutoCommentBlock',
975 'SkAutoDescriptor',
976 'SkAutoDisableDirectionCheck',
977 'SkAutoDisableOvalCheck',
978 'SkAutoFree',
979 'SkAutoGlyphCache',
980 'SkAutoHDC',
981 'SkAutoLockColors',
982 'SkAutoLockPixels',
983 'SkAutoMalloc',
984 'SkAutoMaskFreeImage',
985 'SkAutoMutexAcquire',
986 'SkAutoPathBoundsUpdate',
987 'SkAutoPDFRelease',
988 'SkAutoRasterClipValidate',
989 'SkAutoRef',
990 'SkAutoTime',
991 'SkAutoTrace',
992 'SkAutoUnref',
994 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
995 # bad: base::AutoLock(lock.get());
996 # not bad: base::AutoLock lock(lock.get());
997 bad_pattern = input_api.re.compile(anonymous)
998 # good: new base::AutoLock(lock.get())
999 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
1000 errors = []
1002 for f in input_api.AffectedFiles():
1003 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
1004 continue
1005 for linenum, line in f.ChangedContents():
1006 if bad_pattern.search(line) and not good_pattern.search(line):
1007 errors.append('%s:%d' % (f.LocalPath(), linenum))
1009 if errors:
1010 return [output_api.PresubmitError(
1011 'These lines create anonymous variables that need to be named:',
1012 items=errors)]
1013 return []
1016 def _CheckCygwinShell(input_api, output_api):
1017 source_file_filter = lambda x: input_api.FilterSourceFile(
1018 x, white_list=(r'.+\.(gyp|gypi)$',))
1019 cygwin_shell = []
1021 for f in input_api.AffectedSourceFiles(source_file_filter):
1022 for linenum, line in f.ChangedContents():
1023 if 'msvs_cygwin_shell' in line:
1024 cygwin_shell.append(f.LocalPath())
1025 break
1027 if cygwin_shell:
1028 return [output_api.PresubmitError(
1029 'These files should not use msvs_cygwin_shell (the default is 0):',
1030 items=cygwin_shell)]
1031 return []
1034 def _CheckUserActionUpdate(input_api, output_api):
1035 """Checks if any new user action has been added."""
1036 if any('actions.xml' == input_api.os_path.basename(f) for f in
1037 input_api.LocalPaths()):
1038 # If actions.xml is already included in the changelist, the PRESUBMIT
1039 # for actions.xml will do a more complete presubmit check.
1040 return []
1042 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm'))
1043 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)'
1044 current_actions = None
1045 for f in input_api.AffectedFiles(file_filter=file_filter):
1046 for line_num, line in f.ChangedContents():
1047 match = input_api.re.search(action_re, line)
1048 if match:
1049 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1050 # loaded only once.
1051 if not current_actions:
1052 with open('tools/metrics/actions/actions.xml') as actions_f:
1053 current_actions = actions_f.read()
1054 # Search for the matched user action name in |current_actions|.
1055 for action_name in match.groups():
1056 action = 'name="{0}"'.format(action_name)
1057 if action not in current_actions:
1058 return [output_api.PresubmitPromptWarning(
1059 'File %s line %d: %s is missing in '
1060 'tools/metrics/actions/actions.xml. Please run '
1061 'tools/metrics/actions/extract_actions.py to update.'
1062 % (f.LocalPath(), line_num, action_name))]
1063 return []
1066 def _CheckJavaStyle(input_api, output_api):
1067 """Runs checkstyle on changed java files and returns errors if any exist."""
1068 original_sys_path = sys.path
1069 try:
1070 sys.path = sys.path + [input_api.os_path.join(
1071 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1072 import checkstyle
1073 finally:
1074 # Restore sys.path to what it was before.
1075 sys.path = original_sys_path
1077 return checkstyle.RunCheckstyle(
1078 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1081 def _CommonChecks(input_api, output_api):
1082 """Checks common to both upload and commit."""
1083 results = []
1084 results.extend(input_api.canned_checks.PanProjectChecks(
1085 input_api, output_api,
1086 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
1087 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
1088 results.extend(
1089 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
1090 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
1091 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
1092 results.extend(_CheckNoNewWStrings(input_api, output_api))
1093 results.extend(_CheckNoDEPSGIT(input_api, output_api))
1094 results.extend(_CheckNoBannedFunctions(input_api, output_api))
1095 results.extend(_CheckNoPragmaOnce(input_api, output_api))
1096 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
1097 results.extend(_CheckUnwantedDependencies(input_api, output_api))
1098 results.extend(_CheckFilePermissions(input_api, output_api))
1099 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
1100 results.extend(_CheckIncludeOrder(input_api, output_api))
1101 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
1102 results.extend(_CheckPatchFiles(input_api, output_api))
1103 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
1104 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
1105 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
1106 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
1107 results.extend(
1108 input_api.canned_checks.CheckChangeHasNoTabs(
1109 input_api,
1110 output_api,
1111 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
1112 results.extend(_CheckSpamLogging(input_api, output_api))
1113 results.extend(_CheckForAnonymousVariables(input_api, output_api))
1114 results.extend(_CheckCygwinShell(input_api, output_api))
1115 results.extend(_CheckUserActionUpdate(input_api, output_api))
1117 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1118 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1119 input_api, output_api,
1120 input_api.PresubmitLocalPath(),
1121 whitelist=[r'^PRESUBMIT_test\.py$']))
1122 return results
1125 def _CheckSubversionConfig(input_api, output_api):
1126 """Verifies the subversion config file is correctly setup.
1128 Checks that autoprops are enabled, returns an error otherwise.
1130 join = input_api.os_path.join
1131 if input_api.platform == 'win32':
1132 appdata = input_api.environ.get('APPDATA', '')
1133 if not appdata:
1134 return [output_api.PresubmitError('%APPDATA% is not configured.')]
1135 path = join(appdata, 'Subversion', 'config')
1136 else:
1137 home = input_api.environ.get('HOME', '')
1138 if not home:
1139 return [output_api.PresubmitError('$HOME is not configured.')]
1140 path = join(home, '.subversion', 'config')
1142 error_msg = (
1143 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1144 'configure your subversion configuration file. This enables automatic\n'
1145 'properties to simplify the project maintenance.\n'
1146 'Pro-tip: just download and install\n'
1147 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
1149 try:
1150 lines = open(path, 'r').read().splitlines()
1151 # Make sure auto-props is enabled and check for 2 Chromium standard
1152 # auto-prop.
1153 if (not '*.cc = svn:eol-style=LF' in lines or
1154 not '*.pdf = svn:mime-type=application/pdf' in lines or
1155 not 'enable-auto-props = yes' in lines):
1156 return [
1157 output_api.PresubmitNotifyResult(
1158 'It looks like you have not configured your subversion config '
1159 'file or it is not up-to-date.\n' + error_msg)
1161 except (OSError, IOError):
1162 return [
1163 output_api.PresubmitNotifyResult(
1164 'Can\'t find your subversion config file.\n' + error_msg)
1166 return []
1169 def _CheckAuthorizedAuthor(input_api, output_api):
1170 """For non-googler/chromites committers, verify the author's email address is
1171 in AUTHORS.
1173 # TODO(maruel): Add it to input_api?
1174 import fnmatch
1176 author = input_api.change.author_email
1177 if not author:
1178 input_api.logging.info('No author, skipping AUTHOR check')
1179 return []
1180 authors_path = input_api.os_path.join(
1181 input_api.PresubmitLocalPath(), 'AUTHORS')
1182 valid_authors = (
1183 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1184 for line in open(authors_path))
1185 valid_authors = [item.group(1).lower() for item in valid_authors if item]
1186 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
1187 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
1188 return [output_api.PresubmitPromptWarning(
1189 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1190 '\n'
1191 'http://www.chromium.org/developers/contributing-code and read the '
1192 '"Legal" section\n'
1193 'If you are a chromite, verify the contributor signed the CLA.') %
1194 author)]
1195 return []
1198 def _CheckPatchFiles(input_api, output_api):
1199 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1200 if f.LocalPath().endswith(('.orig', '.rej'))]
1201 if problems:
1202 return [output_api.PresubmitError(
1203 "Don't commit .rej and .orig files.", problems)]
1204 else:
1205 return []
1208 def _DidYouMeanOSMacro(bad_macro):
1209 try:
1210 return {'A': 'OS_ANDROID',
1211 'B': 'OS_BSD',
1212 'C': 'OS_CHROMEOS',
1213 'F': 'OS_FREEBSD',
1214 'L': 'OS_LINUX',
1215 'M': 'OS_MACOSX',
1216 'N': 'OS_NACL',
1217 'O': 'OS_OPENBSD',
1218 'P': 'OS_POSIX',
1219 'S': 'OS_SOLARIS',
1220 'W': 'OS_WIN'}[bad_macro[3].upper()]
1221 except KeyError:
1222 return ''
1225 def _CheckForInvalidOSMacrosInFile(input_api, f):
1226 """Check for sensible looking, totally invalid OS macros."""
1227 preprocessor_statement = input_api.re.compile(r'^\s*#')
1228 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1229 results = []
1230 for lnum, line in f.ChangedContents():
1231 if preprocessor_statement.search(line):
1232 for match in os_macro.finditer(line):
1233 if not match.group(1) in _VALID_OS_MACROS:
1234 good = _DidYouMeanOSMacro(match.group(1))
1235 did_you_mean = ' (did you mean %s?)' % good if good else ''
1236 results.append(' %s:%d %s%s' % (f.LocalPath(),
1237 lnum,
1238 match.group(1),
1239 did_you_mean))
1240 return results
1243 def _CheckForInvalidOSMacros(input_api, output_api):
1244 """Check all affected files for invalid OS macros."""
1245 bad_macros = []
1246 for f in input_api.AffectedFiles():
1247 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1248 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1250 if not bad_macros:
1251 return []
1253 return [output_api.PresubmitError(
1254 'Possibly invalid OS macro[s] found. Please fix your code\n'
1255 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1258 def CheckChangeOnUpload(input_api, output_api):
1259 results = []
1260 results.extend(_CommonChecks(input_api, output_api))
1261 results.extend(_CheckJavaStyle(input_api, output_api))
1262 return results
1265 def GetDefaultTryConfigs(bots=None):
1266 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1268 To add tests to this list, they MUST be in the the corresponding master's
1269 gatekeeper config. For example, anything on master.chromium would be closed by
1270 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1272 If 'bots' is specified, will only return configurations for bots in that list.
1275 standard_tests = [
1276 'base_unittests',
1277 'browser_tests',
1278 'cacheinvalidation_unittests',
1279 'check_deps',
1280 'check_deps2git',
1281 'content_browsertests',
1282 'content_unittests',
1283 'crypto_unittests',
1284 'gpu_unittests',
1285 'interactive_ui_tests',
1286 'ipc_tests',
1287 'jingle_unittests',
1288 'media_unittests',
1289 'net_unittests',
1290 'ppapi_unittests',
1291 'printing_unittests',
1292 'sql_unittests',
1293 'sync_unit_tests',
1294 'unit_tests',
1295 # Broken in release.
1296 #'url_unittests',
1297 #'webkit_unit_tests',
1300 builders_and_tests = {
1301 # TODO(maruel): Figure out a way to run 'sizes' where people can
1302 # effectively update the perf expectation correctly. This requires a
1303 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1304 # incremental build. Reference:
1305 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1306 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1307 # of this step as a try job failure.
1308 'android_aosp': ['compile'],
1309 'android_clang_dbg': ['slave_steps'],
1310 'android_dbg': ['slave_steps'],
1311 'cros_x86': ['defaulttests'],
1312 'ios_dbg_simulator': [
1313 'compile',
1314 'base_unittests',
1315 'content_unittests',
1316 'crypto_unittests',
1317 'url_unittests',
1318 'net_unittests',
1319 'sql_unittests',
1320 'ui_unittests',
1322 'ios_rel_device': ['compile'],
1323 'linux_asan': ['compile'],
1324 'mac_asan': ['compile'],
1325 #TODO(stip): Change the name of this builder to reflect that it's release.
1326 'linux_gtk': standard_tests,
1327 'linux_chromeos_asan': ['compile'],
1328 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
1329 'linux_chromium_chromeos_rel': ['defaulttests'],
1330 'linux_chromium_compile_dbg': ['defaulttests'],
1331 'linux_chromium_rel': ['defaulttests'],
1332 'linux_chromium_clang_dbg': ['defaulttests'],
1333 'linux_nacl_sdk_build': ['compile'],
1334 'linux_rel': [
1335 'telemetry_perf_unittests',
1336 'telemetry_unittests',
1338 'mac_chromium_compile_dbg': ['defaulttests'],
1339 'mac_chromium_rel': ['defaulttests'],
1340 'mac_nacl_sdk_build': ['compile'],
1341 'mac_rel': [
1342 'telemetry_perf_unittests',
1343 'telemetry_unittests',
1345 'win': ['compile'],
1346 'win_chromium_compile_dbg': ['defaulttests'],
1347 'win_chromium_dbg': ['defaulttests'],
1348 'win_chromium_rel': ['defaulttests'],
1349 'win_chromium_x64_rel': ['defaulttests'],
1350 'win_nacl_sdk_build': ['compile'],
1351 'win_rel': standard_tests + [
1352 'app_list_unittests',
1353 'ash_unittests',
1354 'aura_unittests',
1355 'cc_unittests',
1356 'chrome_elf_unittests',
1357 'chromedriver_unittests',
1358 'components_unittests',
1359 'compositor_unittests',
1360 'events_unittests',
1361 'gfx_unittests',
1362 'google_apis_unittests',
1363 'installer_util_unittests',
1364 'mini_installer_test',
1365 'nacl_integration',
1366 'remoting_unittests',
1367 'sync_integration_tests',
1368 'telemetry_perf_unittests',
1369 'telemetry_unittests',
1370 'views_unittests',
1372 'win_x64_rel': [
1373 'base_unittests',
1377 swarm_enabled_builders = (
1378 # http://crbug.com/354263
1379 # 'linux_rel',
1380 # 'mac_rel',
1381 # 'win_rel',
1384 swarm_enabled_tests = (
1385 'base_unittests',
1386 'browser_tests',
1387 'interactive_ui_tests',
1388 'net_unittests',
1389 'unit_tests',
1392 for bot in builders_and_tests:
1393 if bot in swarm_enabled_builders:
1394 builders_and_tests[bot] = [x + '_swarm' if x in swarm_enabled_tests else x
1395 for x in builders_and_tests[bot]]
1397 if bots:
1398 return {
1399 'tryserver.chromium': dict((bot, set(builders_and_tests[bot]))
1400 for bot in bots)
1402 else:
1403 return {
1404 'tryserver.chromium': dict(
1405 (bot, set(tests))
1406 for bot, tests in builders_and_tests.iteritems())
1410 def CheckChangeOnCommit(input_api, output_api):
1411 results = []
1412 results.extend(_CommonChecks(input_api, output_api))
1413 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1414 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1415 # input_api, output_api, sources))
1416 # Make sure the tree is 'open'.
1417 results.extend(input_api.canned_checks.CheckTreeIsOpen(
1418 input_api,
1419 output_api,
1420 json_url='http://chromium-status.appspot.com/current?format=json'))
1422 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1423 input_api, output_api))
1424 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1425 input_api, output_api))
1426 results.extend(_CheckSubversionConfig(input_api, output_api))
1427 return results
1430 def GetPreferredTryMasters(project, change):
1431 files = change.LocalPaths()
1433 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
1434 return {}
1436 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
1437 return GetDefaultTryConfigs([
1438 'mac_chromium_compile_dbg',
1439 'mac_chromium_rel',
1441 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
1442 return GetDefaultTryConfigs(['win_chromium_dbg', 'win_chromium_rel'])
1443 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
1444 return GetDefaultTryConfigs([
1445 'android_aosp',
1446 'android_clang_dbg',
1447 'android_dbg',
1449 if all(re.search('[/_]ios[/_.]', f) for f in files):
1450 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
1452 builders = [
1453 'android_clang_dbg',
1454 'android_dbg',
1455 'ios_dbg_simulator',
1456 'ios_rel_device',
1457 'linux_chromium_chromeos_rel',
1458 'linux_chromium_clang_dbg',
1459 'linux_chromium_rel',
1460 'mac_chromium_compile_dbg',
1461 'mac_chromium_rel',
1462 'win_chromium_compile_dbg',
1463 'win_chromium_rel',
1464 'win_chromium_x64_rel',
1467 # Match things like path/aura/file.cc and path/file_aura.cc.
1468 # Same for chromeos.
1469 if any(re.search('[/_](aura|chromeos)', f) for f in files):
1470 builders.extend([
1471 'linux_chromeos_asan',
1472 'linux_chromium_chromeos_clang_dbg'
1475 # If there are gyp changes to base, build, or chromeos, run a full cros build
1476 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1477 # files have a much higher chance of breaking the cros build, which is
1478 # differnt from the linux_chromeos build that most chrome developers test
1479 # with.
1480 if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files):
1481 builders.extend(['cros_x86'])
1483 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1484 # unless they're .gyp(i) files as changes to those files can break the gyp
1485 # step on that bot.
1486 if (not all(re.search('^chrome', f) for f in files) or
1487 any(re.search('\.gypi?$', f) for f in files)):
1488 builders.extend(['android_aosp'])
1490 return GetDefaultTryConfigs(builders)