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