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.
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[\\\/].*",
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.
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
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
= (
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',
84 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
86 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
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',
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',
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',
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',
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',
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',
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.
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.',
163 'New code should not use ScopedAllowIO. Post a task to the blocking',
164 'pool or the FILE thread instead.',
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$",
178 'The use of SkRefPtr is prohibited. ',
179 'Please use skia::RefPtr instead.'
187 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
188 'Please use skia::RefPtr instead.'
196 'The use of SkAutoTUnref is dangerous because it implicitly ',
197 'converts to a raw pointer. Please use skia::RefPtr instead.'
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.'
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'
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',
231 # Files that #define IGNORE_EINTR.
232 r
'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
233 r
'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
239 'Do not introduce new v8::Extensions into the code base, use',
240 'gin::Wrappable instead. See http://crbug.com/334679',
244 r
'extensions[/\\]renderer[/\\]safe_builtins\.*',
251 # Please keep sorted.
255 'OS_CAT', # For testing.
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(
294 white_list
=(file_inclusion_pattern
, ),
295 black_list
=black_list
)
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
)):
305 '%s:%d\n %s' % (local_path
, line_number
, line
.strip()))
308 return [output_api
.PresubmitPromptOrNotify(_TEST_ONLY_WARNING
, problems
)]
313 def _CheckNoIOStreamInHeaders(input_api
, output_api
):
314 """Checks to make sure no .h files include <iostream>."""
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'):
321 contents
= input_api
.ReadFile(f
)
322 if pattern
.search(contents
):
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',
334 def _CheckNoUNIT_TESTInSourceFiles(input_api
, output_api
):
335 """Checks to make sure no source files use UNIT_TEST"""
337 for f
in input_api
.AffectedFiles():
338 if (not f
.LocalPath().endswith(('.cc', '.mm'))):
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
))
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."""
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'))):
360 for line_num
, line
in f
.ChangedContents():
361 if 'presubmit: allow wstring' in line
:
363 elif not allowWString
and 'wstring' in line
:
364 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
371 return [output_api
.PresubmitPromptWarning('New code should not use wstrings.'
372 ' If you are calling a cross-platform API that accepts a wstring, '
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'
385 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
386 'for more information')]
390 def _CheckNoBannedFunctions(input_api
, output_api
):
391 """Make sure that banned functions are not used."""
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 if func_name
in line
:
403 problems
.append(' %s:%d:' % (f
.LocalPath(), line_num
))
404 for message_line
in message
:
405 problems
.append(' %s' % message_line
)
407 file_filter
= lambda f
: f
.LocalPath().endswith(('.cc', '.mm', '.h'))
408 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
409 for line_num
, line
in f
.ChangedContents():
410 for func_name
, message
, error
, excluded_paths
in _BANNED_CPP_FUNCTIONS
:
411 def IsBlacklisted(affected_file
, blacklist
):
412 local_path
= affected_file
.LocalPath()
413 for item
in blacklist
:
414 if input_api
.re
.match(item
, local_path
):
417 if IsBlacklisted(f
, excluded_paths
):
420 if func_name
[0:1] == '/':
421 regex
= func_name
[1:]
422 if input_api
.re
.search(regex
, line
):
424 elif func_name
in line
:
430 problems
.append(' %s:%d:' % (f
.LocalPath(), line_num
))
431 for message_line
in message
:
432 problems
.append(' %s' % message_line
)
436 result
.append(output_api
.PresubmitPromptWarning(
437 'Banned functions were used.\n' + '\n'.join(warnings
)))
439 result
.append(output_api
.PresubmitError(
440 'Banned functions were used.\n' + '\n'.join(errors
)))
444 def _CheckNoPragmaOnce(input_api
, output_api
):
445 """Make sure that banned functions are not used."""
447 pattern
= input_api
.re
.compile(r
'^#pragma\s+once',
448 input_api
.re
.MULTILINE
)
449 for f
in input_api
.AffectedSourceFiles(input_api
.FilterSourceFile
):
450 if not f
.LocalPath().endswith('.h'):
452 contents
= input_api
.ReadFile(f
)
453 if pattern
.search(contents
):
457 return [output_api
.PresubmitError(
458 'Do not use #pragma once in header files.\n'
459 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
464 def _CheckNoTrinaryTrueFalse(input_api
, output_api
):
465 """Checks to make sure we don't introduce use of foo ? true : false."""
467 pattern
= input_api
.re
.compile(r
'\?\s*(true|false)\s*:\s*(true|false)')
468 for f
in input_api
.AffectedFiles():
469 if not f
.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
472 for line_num
, line
in f
.ChangedContents():
473 if pattern
.match(line
):
474 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
478 return [output_api
.PresubmitPromptWarning(
479 'Please consider avoiding the "? true : false" pattern if possible.\n' +
480 '\n'.join(problems
))]
483 def _CheckUnwantedDependencies(input_api
, output_api
):
484 """Runs checkdeps on #include statements added in this
485 change. Breaking - rules is an error, breaking ! rules is a
488 # We need to wait until we have an input_api object and use this
489 # roundabout construct to import checkdeps because this file is
490 # eval-ed and thus doesn't have __file__.
491 original_sys_path
= sys
.path
493 sys
.path
= sys
.path
+ [input_api
.os_path
.join(
494 input_api
.PresubmitLocalPath(), 'tools', 'checkdeps')]
496 from cpp_checker
import CppChecker
497 from rules
import Rule
499 # Restore sys.path to what it was before.
500 sys
.path
= original_sys_path
503 for f
in input_api
.AffectedFiles():
504 if not CppChecker
.IsCppFile(f
.LocalPath()):
507 changed_lines
= [line
for line_num
, line
in f
.ChangedContents()]
508 added_includes
.append([f
.LocalPath(), changed_lines
])
510 deps_checker
= checkdeps
.DepsChecker(input_api
.PresubmitLocalPath())
512 error_descriptions
= []
513 warning_descriptions
= []
514 for path
, rule_type
, rule_description
in deps_checker
.CheckAddedCppIncludes(
516 description_with_path
= '%s\n %s' % (path
, rule_description
)
517 if rule_type
== Rule
.DISALLOW
:
518 error_descriptions
.append(description_with_path
)
520 warning_descriptions
.append(description_with_path
)
523 if error_descriptions
:
524 results
.append(output_api
.PresubmitError(
525 'You added one or more #includes that violate checkdeps rules.',
527 if warning_descriptions
:
528 results
.append(output_api
.PresubmitPromptOrNotify(
529 'You added one or more #includes of files that are temporarily\n'
530 'allowed but being removed. Can you avoid introducing the\n'
531 '#include? See relevant DEPS file(s) for details and contacts.',
532 warning_descriptions
))
536 def _CheckFilePermissions(input_api
, output_api
):
537 """Check that all files have their permissions properly set."""
538 if input_api
.platform
== 'win32':
540 args
= [sys
.executable
, 'tools/checkperms/checkperms.py', '--root',
541 input_api
.change
.RepositoryRoot()]
542 for f
in input_api
.AffectedFiles():
543 args
+= ['--file', f
.LocalPath()]
544 checkperms
= input_api
.subprocess
.Popen(args
,
545 stdout
=input_api
.subprocess
.PIPE
)
546 errors
= checkperms
.communicate()[0].strip()
548 return [output_api
.PresubmitError('checkperms.py failed.',
549 errors
.splitlines())]
553 def _CheckNoAuraWindowPropertyHInHeaders(input_api
, output_api
):
554 """Makes sure we don't include ui/aura/window_property.h
557 pattern
= input_api
.re
.compile(r
'^#include\s*"ui/aura/window_property.h"')
559 for f
in input_api
.AffectedFiles():
560 if not f
.LocalPath().endswith('.h'):
562 for line_num
, line
in f
.ChangedContents():
563 if pattern
.match(line
):
564 errors
.append(' %s:%d' % (f
.LocalPath(), line_num
))
568 results
.append(output_api
.PresubmitError(
569 'Header files should not include ui/aura/window_property.h', errors
))
573 def _CheckIncludeOrderForScope(scope
, input_api
, file_path
, changed_linenums
):
574 """Checks that the lines in scope occur in the right order.
576 1. C system files in alphabetical order
577 2. C++ system files in alphabetical order
578 3. Project's .h files
581 c_system_include_pattern
= input_api
.re
.compile(r
'\s*#include <.*\.h>')
582 cpp_system_include_pattern
= input_api
.re
.compile(r
'\s*#include <.*>')
583 custom_include_pattern
= input_api
.re
.compile(r
'\s*#include ".*')
585 C_SYSTEM_INCLUDES
, CPP_SYSTEM_INCLUDES
, CUSTOM_INCLUDES
= range(3)
587 state
= C_SYSTEM_INCLUDES
590 previous_line_num
= 0
591 problem_linenums
= []
592 for line_num
, line
in scope
:
593 if c_system_include_pattern
.match(line
):
594 if state
!= C_SYSTEM_INCLUDES
:
595 problem_linenums
.append((line_num
, previous_line_num
))
596 elif previous_line
and previous_line
> line
:
597 problem_linenums
.append((line_num
, previous_line_num
))
598 elif cpp_system_include_pattern
.match(line
):
599 if state
== C_SYSTEM_INCLUDES
:
600 state
= CPP_SYSTEM_INCLUDES
601 elif state
== CUSTOM_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 custom_include_pattern
.match(line
):
606 if state
!= CUSTOM_INCLUDES
:
607 state
= CUSTOM_INCLUDES
608 elif previous_line
and previous_line
> line
:
609 problem_linenums
.append((line_num
, previous_line_num
))
611 problem_linenums
.append(line_num
)
613 previous_line_num
= line_num
616 for (line_num
, previous_line_num
) in problem_linenums
:
617 if line_num
in changed_linenums
or previous_line_num
in changed_linenums
:
618 warnings
.append(' %s:%d' % (file_path
, line_num
))
622 def _CheckIncludeOrderInFile(input_api
, f
, changed_linenums
):
623 """Checks the #include order for the given file f."""
625 system_include_pattern
= input_api
.re
.compile(r
'\s*#include \<.*')
626 # Exclude the following includes from the check:
627 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
629 # 2) <atlbase.h>, "build/build_config.h"
630 excluded_include_pattern
= input_api
.re
.compile(
631 r
'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
632 custom_include_pattern
= input_api
.re
.compile(r
'\s*#include "(?P<FILE>.*)"')
633 # Match the final or penultimate token if it is xxxtest so we can ignore it
634 # when considering the special first include.
635 test_file_tag_pattern
= input_api
.re
.compile(
636 r
'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
637 if_pattern
= input_api
.re
.compile(
638 r
'\s*#\s*(if|elif|else|endif|define|undef).*')
639 # Some files need specialized order of includes; exclude such files from this
641 uncheckable_includes_pattern
= input_api
.re
.compile(
643 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
645 contents
= f
.NewContents()
649 # Handle the special first include. If the first include file is
650 # some/path/file.h, the corresponding including file can be some/path/file.cc,
651 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
652 # etc. It's also possible that no special first include exists.
653 # If the included file is some/path/file_platform.h the including file could
654 # also be some/path/file_xxxtest_platform.h.
655 including_file_base_name
= test_file_tag_pattern
.sub(
656 '', input_api
.os_path
.basename(f
.LocalPath()))
658 for line
in contents
:
660 if system_include_pattern
.match(line
):
661 # No special first include -> process the line again along with normal
665 match
= custom_include_pattern
.match(line
)
667 match_dict
= match
.groupdict()
668 header_basename
= test_file_tag_pattern
.sub(
669 '', input_api
.os_path
.basename(match_dict
['FILE'])).replace('.h', '')
671 if header_basename
not in including_file_base_name
:
672 # No special first include -> process the line again along with normal
677 # Split into scopes: Each region between #if and #endif is its own scope.
680 for line
in contents
[line_num
:]:
682 if uncheckable_includes_pattern
.match(line
):
684 if if_pattern
.match(line
):
685 scopes
.append(current_scope
)
687 elif ((system_include_pattern
.match(line
) or
688 custom_include_pattern
.match(line
)) and
689 not excluded_include_pattern
.match(line
)):
690 current_scope
.append((line_num
, line
))
691 scopes
.append(current_scope
)
694 warnings
.extend(_CheckIncludeOrderForScope(scope
, input_api
, f
.LocalPath(),
699 def _CheckIncludeOrder(input_api
, output_api
):
700 """Checks that the #include order is correct.
702 1. The corresponding header for source files.
703 2. C system files in alphabetical order
704 3. C++ system files in alphabetical order
705 4. Project's .h files in alphabetical order
707 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
708 these rules separately.
712 for f
in input_api
.AffectedFiles():
713 if f
.LocalPath().endswith(('.cc', '.h')):
714 changed_linenums
= set(line_num
for line_num
, _
in f
.ChangedContents())
715 warnings
.extend(_CheckIncludeOrderInFile(input_api
, f
, changed_linenums
))
719 results
.append(output_api
.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING
,
724 def _CheckForVersionControlConflictsInFile(input_api
, f
):
725 pattern
= input_api
.re
.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
727 for line_num
, line
in f
.ChangedContents():
728 if pattern
.match(line
):
729 errors
.append(' %s:%d %s' % (f
.LocalPath(), line_num
, line
))
733 def _CheckForVersionControlConflicts(input_api
, output_api
):
734 """Usually this is not intentional and will cause a compile failure."""
736 for f
in input_api
.AffectedFiles():
737 errors
.extend(_CheckForVersionControlConflictsInFile(input_api
, f
))
741 results
.append(output_api
.PresubmitError(
742 'Version control conflict markers found, please resolve.', errors
))
746 def _CheckHardcodedGoogleHostsInLowerLayers(input_api
, output_api
):
747 def FilterFile(affected_file
):
748 """Filter function for use with input_api.AffectedSourceFiles,
749 below. This filters out everything except non-test files from
750 top-level directories that generally speaking should not hard-code
751 service URLs (e.g. src/android_webview/, src/content/ and others).
753 return input_api
.FilterSourceFile(
755 white_list
=(r
'^(android_webview|base|content|net)[\\\/].*', ),
756 black_list
=(_EXCLUDED_PATHS
+
757 _TEST_CODE_EXCLUDED_PATHS
+
758 input_api
.DEFAULT_BLACK_LIST
))
760 base_pattern
= '"[^"]*google\.com[^"]*"'
761 comment_pattern
= input_api
.re
.compile('//.*%s' % base_pattern
)
762 pattern
= input_api
.re
.compile(base_pattern
)
763 problems
= [] # items are (filename, line_number, line)
764 for f
in input_api
.AffectedSourceFiles(FilterFile
):
765 for line_num
, line
in f
.ChangedContents():
766 if not comment_pattern
.search(line
) and pattern
.search(line
):
767 problems
.append((f
.LocalPath(), line_num
, line
))
770 return [output_api
.PresubmitPromptOrNotify(
771 'Most layers below src/chrome/ should not hardcode service URLs.\n'
772 'Are you sure this is correct?',
774 problem
[0], problem
[1], problem
[2]) for problem
in problems
])]
779 def _CheckNoAbbreviationInPngFileName(input_api
, output_api
):
780 """Makes sure there are no abbreviations in the name of PNG files.
782 pattern
= input_api
.re
.compile(r
'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
784 for f
in input_api
.AffectedFiles(include_deletes
=False):
785 if pattern
.match(f
.LocalPath()):
786 errors
.append(' %s' % f
.LocalPath())
790 results
.append(output_api
.PresubmitError(
791 'The name of PNG files should not have abbreviations. \n'
792 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
793 'Contact oshima@chromium.org if you have questions.', errors
))
797 def _FilesToCheckForIncomingDeps(re
, changed_lines
):
798 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
799 a set of DEPS entries that we should look up.
801 For a directory (rather than a specific filename) we fake a path to
802 a specific filename by adding /DEPS. This is chosen as a file that
803 will seldom or never be subject to per-file include_rules.
805 # We ignore deps entries on auto-generated directories.
806 AUTO_GENERATED_DIRS
= ['grit', 'jni']
808 # This pattern grabs the path without basename in the first
809 # parentheses, and the basename (if present) in the second. It
810 # relies on the simple heuristic that if there is a basename it will
811 # be a header file ending in ".h".
812 pattern
= re
.compile(
813 r
"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
815 for changed_line
in changed_lines
:
816 m
= pattern
.match(changed_line
)
819 if path
.split('/')[0] not in AUTO_GENERATED_DIRS
:
821 results
.add('%s%s' % (path
, m
.group(2)))
823 results
.add('%s/DEPS' % path
)
827 def _CheckAddedDepsHaveTargetApprovals(input_api
, output_api
):
828 """When a dependency prefixed with + is added to a DEPS file, we
829 want to make sure that the change is reviewed by an OWNER of the
830 target file or directory, to avoid layering violations from being
831 introduced. This check verifies that this happens.
833 changed_lines
= set()
834 for f
in input_api
.AffectedFiles():
835 filename
= input_api
.os_path
.basename(f
.LocalPath())
836 if filename
== 'DEPS':
837 changed_lines |
= set(line
.strip()
839 in f
.ChangedContents())
840 if not changed_lines
:
843 virtual_depended_on_files
= _FilesToCheckForIncomingDeps(input_api
.re
,
845 if not virtual_depended_on_files
:
848 if input_api
.is_committing
:
850 return [output_api
.PresubmitNotifyResult(
851 '--tbr was specified, skipping OWNERS check for DEPS additions')]
852 if not input_api
.change
.issue
:
853 return [output_api
.PresubmitError(
854 "DEPS approval by OWNERS check failed: this change has "
855 "no Rietveld issue number, so we can't check it for approvals.")]
856 output
= output_api
.PresubmitError
858 output
= output_api
.PresubmitNotifyResult
860 owners_db
= input_api
.owners_db
861 owner_email
, reviewers
= input_api
.canned_checks
._RietveldOwnerAndReviewers
(
863 owners_db
.email_regexp
,
864 approval_needed
=input_api
.is_committing
)
866 owner_email
= owner_email
or input_api
.change
.author_email
868 reviewers_plus_owner
= set(reviewers
)
870 reviewers_plus_owner
.add(owner_email
)
871 missing_files
= owners_db
.files_not_covered_by(virtual_depended_on_files
,
872 reviewers_plus_owner
)
874 # We strip the /DEPS part that was added by
875 # _FilesToCheckForIncomingDeps to fake a path to a file in a
878 start_deps
= path
.rfind('/DEPS')
880 return path
[:start_deps
]
883 unapproved_dependencies
= ["'+%s'," % StripDeps(path
)
884 for path
in missing_files
]
886 if unapproved_dependencies
:
888 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
889 '\n '.join(sorted(unapproved_dependencies
)))]
890 if not input_api
.is_committing
:
891 suggested_owners
= owners_db
.reviewers_for(missing_files
, owner_email
)
892 output_list
.append(output(
893 'Suggested missing target path OWNERS:\n %s' %
894 '\n '.join(suggested_owners
or [])))
900 def _CheckSpamLogging(input_api
, output_api
):
901 file_inclusion_pattern
= r
'.+%s' % _IMPLEMENTATION_EXTENSIONS
902 black_list
= (_EXCLUDED_PATHS
+
903 _TEST_CODE_EXCLUDED_PATHS
+
904 input_api
.DEFAULT_BLACK_LIST
+
905 (r
"^base[\\\/]logging\.h$",
906 r
"^base[\\\/]logging\.cc$",
907 r
"^cloud_print[\\\/]",
908 r
"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
909 r
"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
910 r
"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
911 r
"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
912 r
"startup_browser_creator\.cc$",
913 r
"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
914 r
"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
915 r
"logging_native_handler\.cc$",
916 r
"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
917 r
"gl_helper_benchmark\.cc$",
918 r
"^native_client_sdk[\\\/]",
919 r
"^remoting[\\\/]base[\\\/]logging\.h$",
920 r
"^remoting[\\\/]host[\\\/].*",
921 r
"^sandbox[\\\/]linux[\\\/].*",
923 r
"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
924 source_file_filter
= lambda x
: input_api
.FilterSourceFile(
925 x
, white_list
=(file_inclusion_pattern
,), black_list
=black_list
)
930 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
931 contents
= input_api
.ReadFile(f
, 'rb')
932 if re
.search(r
"\bD?LOG\s*\(\s*INFO\s*\)", contents
):
933 log_info
.append(f
.LocalPath())
934 elif re
.search(r
"\bD?LOG_IF\s*\(\s*INFO\s*,", contents
):
935 log_info
.append(f
.LocalPath())
937 if re
.search(r
"\bprintf\(", contents
):
938 printf
.append(f
.LocalPath())
939 elif re
.search(r
"\bfprintf\((stdout|stderr)", contents
):
940 printf
.append(f
.LocalPath())
943 return [output_api
.PresubmitError(
944 'These files spam the console log with LOG(INFO):',
947 return [output_api
.PresubmitError(
948 'These files spam the console log with printf/fprintf:',
953 def _CheckForAnonymousVariables(input_api
, output_api
):
954 """These types are all expected to hold locks while in scope and
955 so should never be anonymous (which causes them to be immediately
957 they_who_must_be_named
= [
961 'SkAutoAlphaRestore',
962 'SkAutoBitmapShaderInstall',
963 'SkAutoBlitterChoose',
964 'SkAutoBounderCommit',
966 'SkAutoCanvasRestore',
967 'SkAutoCommentBlock',
969 'SkAutoDisableDirectionCheck',
970 'SkAutoDisableOvalCheck',
977 'SkAutoMaskFreeImage',
978 'SkAutoMutexAcquire',
979 'SkAutoPathBoundsUpdate',
981 'SkAutoRasterClipValidate',
987 anonymous
= r
'(%s)\s*[({]' % '|'.join(they_who_must_be_named
)
988 # bad: base::AutoLock(lock.get());
989 # not bad: base::AutoLock lock(lock.get());
990 bad_pattern
= input_api
.re
.compile(anonymous
)
991 # good: new base::AutoLock(lock.get())
992 good_pattern
= input_api
.re
.compile(r
'\bnew\s*' + anonymous
)
995 for f
in input_api
.AffectedFiles():
996 if not f
.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
998 for linenum
, line
in f
.ChangedContents():
999 if bad_pattern
.search(line
) and not good_pattern
.search(line
):
1000 errors
.append('%s:%d' % (f
.LocalPath(), linenum
))
1003 return [output_api
.PresubmitError(
1004 'These lines create anonymous variables that need to be named:',
1009 def _CheckCygwinShell(input_api
, output_api
):
1010 source_file_filter
= lambda x
: input_api
.FilterSourceFile(
1011 x
, white_list
=(r
'.+\.(gyp|gypi)$',))
1014 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
1015 for linenum
, line
in f
.ChangedContents():
1016 if 'msvs_cygwin_shell' in line
:
1017 cygwin_shell
.append(f
.LocalPath())
1021 return [output_api
.PresubmitError(
1022 'These files should not use msvs_cygwin_shell (the default is 0):',
1023 items
=cygwin_shell
)]
1027 def _CheckUserActionUpdate(input_api
, output_api
):
1028 """Checks if any new user action has been added."""
1029 if any('actions.xml' == input_api
.os_path
.basename(f
) for f
in
1030 input_api
.LocalPaths()):
1031 # If actions.xml is already included in the changelist, the PRESUBMIT
1032 # for actions.xml will do a more complete presubmit check.
1035 file_filter
= lambda f
: f
.LocalPath().endswith(('.cc', '.mm'))
1036 action_re
= r
'[^a-zA-Z]UserMetricsAction\("([^"]*)'
1037 current_actions
= None
1038 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
1039 for line_num
, line
in f
.ChangedContents():
1040 match
= input_api
.re
.search(action_re
, line
)
1042 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1044 if not current_actions
:
1045 with
open('tools/metrics/actions/actions.xml') as actions_f
:
1046 current_actions
= actions_f
.read()
1047 # Search for the matched user action name in |current_actions|.
1048 for action_name
in match
.groups():
1049 action
= 'name="{0}"'.format(action_name
)
1050 if action
not in current_actions
:
1051 return [output_api
.PresubmitPromptWarning(
1052 'File %s line %d: %s is missing in '
1053 'tools/metrics/actions/actions.xml. Please run '
1054 'tools/metrics/actions/extract_actions.py to update.'
1055 % (f
.LocalPath(), line_num
, action_name
))]
1059 def _CheckJavaStyle(input_api
, output_api
):
1060 """Runs checkstyle on changed java files and returns errors if any exist."""
1061 original_sys_path
= sys
.path
1063 sys
.path
= sys
.path
+ [input_api
.os_path
.join(
1064 input_api
.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1067 # Restore sys.path to what it was before.
1068 sys
.path
= original_sys_path
1070 return checkstyle
.RunCheckstyle(
1071 input_api
, output_api
, 'tools/android/checkstyle/chromium-style-5.0.xml')
1074 def _CommonChecks(input_api
, output_api
):
1075 """Checks common to both upload and commit."""
1077 results
.extend(input_api
.canned_checks
.PanProjectChecks(
1078 input_api
, output_api
,
1079 excluded_paths
=_EXCLUDED_PATHS
+ _TESTRUNNER_PATHS
))
1080 results
.extend(_CheckAuthorizedAuthor(input_api
, output_api
))
1082 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api
, output_api
))
1083 results
.extend(_CheckNoIOStreamInHeaders(input_api
, output_api
))
1084 results
.extend(_CheckNoUNIT_TESTInSourceFiles(input_api
, output_api
))
1085 results
.extend(_CheckNoNewWStrings(input_api
, output_api
))
1086 results
.extend(_CheckNoDEPSGIT(input_api
, output_api
))
1087 results
.extend(_CheckNoBannedFunctions(input_api
, output_api
))
1088 results
.extend(_CheckNoPragmaOnce(input_api
, output_api
))
1089 results
.extend(_CheckNoTrinaryTrueFalse(input_api
, output_api
))
1090 results
.extend(_CheckUnwantedDependencies(input_api
, output_api
))
1091 results
.extend(_CheckFilePermissions(input_api
, output_api
))
1092 results
.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api
, output_api
))
1093 results
.extend(_CheckIncludeOrder(input_api
, output_api
))
1094 results
.extend(_CheckForVersionControlConflicts(input_api
, output_api
))
1095 results
.extend(_CheckPatchFiles(input_api
, output_api
))
1096 results
.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api
, output_api
))
1097 results
.extend(_CheckNoAbbreviationInPngFileName(input_api
, output_api
))
1098 results
.extend(_CheckForInvalidOSMacros(input_api
, output_api
))
1099 results
.extend(_CheckAddedDepsHaveTargetApprovals(input_api
, output_api
))
1101 input_api
.canned_checks
.CheckChangeHasNoTabs(
1104 source_file_filter
=lambda x
: x
.LocalPath().endswith('.grd')))
1105 results
.extend(_CheckSpamLogging(input_api
, output_api
))
1106 results
.extend(_CheckForAnonymousVariables(input_api
, output_api
))
1107 results
.extend(_CheckCygwinShell(input_api
, output_api
))
1108 results
.extend(_CheckUserActionUpdate(input_api
, output_api
))
1110 if any('PRESUBMIT.py' == f
.LocalPath() for f
in input_api
.AffectedFiles()):
1111 results
.extend(input_api
.canned_checks
.RunUnitTestsInDirectory(
1112 input_api
, output_api
,
1113 input_api
.PresubmitLocalPath(),
1114 whitelist
=[r
'^PRESUBMIT_test\.py$']))
1118 def _CheckSubversionConfig(input_api
, output_api
):
1119 """Verifies the subversion config file is correctly setup.
1121 Checks that autoprops are enabled, returns an error otherwise.
1123 join
= input_api
.os_path
.join
1124 if input_api
.platform
== 'win32':
1125 appdata
= input_api
.environ
.get('APPDATA', '')
1127 return [output_api
.PresubmitError('%APPDATA% is not configured.')]
1128 path
= join(appdata
, 'Subversion', 'config')
1130 home
= input_api
.environ
.get('HOME', '')
1132 return [output_api
.PresubmitError('$HOME is not configured.')]
1133 path
= join(home
, '.subversion', 'config')
1136 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1137 'configure your subversion configuration file. This enables automatic\n'
1138 'properties to simplify the project maintenance.\n'
1139 'Pro-tip: just download and install\n'
1140 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
1143 lines
= open(path
, 'r').read().splitlines()
1144 # Make sure auto-props is enabled and check for 2 Chromium standard
1146 if (not '*.cc = svn:eol-style=LF' in lines
or
1147 not '*.pdf = svn:mime-type=application/pdf' in lines
or
1148 not 'enable-auto-props = yes' in lines
):
1150 output_api
.PresubmitNotifyResult(
1151 'It looks like you have not configured your subversion config '
1152 'file or it is not up-to-date.\n' + error_msg
)
1154 except (OSError, IOError):
1156 output_api
.PresubmitNotifyResult(
1157 'Can\'t find your subversion config file.\n' + error_msg
)
1162 def _CheckAuthorizedAuthor(input_api
, output_api
):
1163 """For non-googler/chromites committers, verify the author's email address is
1166 # TODO(maruel): Add it to input_api?
1169 author
= input_api
.change
.author_email
1171 input_api
.logging
.info('No author, skipping AUTHOR check')
1173 authors_path
= input_api
.os_path
.join(
1174 input_api
.PresubmitLocalPath(), 'AUTHORS')
1176 input_api
.re
.match(r
'[^#]+\s+\<(.+?)\>\s*$', line
)
1177 for line
in open(authors_path
))
1178 valid_authors
= [item
.group(1).lower() for item
in valid_authors
if item
]
1179 if not any(fnmatch
.fnmatch(author
.lower(), valid
) for valid
in valid_authors
):
1180 input_api
.logging
.info('Valid authors are %s', ', '.join(valid_authors
))
1181 return [output_api
.PresubmitPromptWarning(
1182 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1184 'http://www.chromium.org/developers/contributing-code and read the '
1186 'If you are a chromite, verify the contributor signed the CLA.') %
1191 def _CheckPatchFiles(input_api
, output_api
):
1192 problems
= [f
.LocalPath() for f
in input_api
.AffectedFiles()
1193 if f
.LocalPath().endswith(('.orig', '.rej'))]
1195 return [output_api
.PresubmitError(
1196 "Don't commit .rej and .orig files.", problems
)]
1201 def _DidYouMeanOSMacro(bad_macro
):
1203 return {'A': 'OS_ANDROID',
1213 'W': 'OS_WIN'}[bad_macro
[3].upper()]
1218 def _CheckForInvalidOSMacrosInFile(input_api
, f
):
1219 """Check for sensible looking, totally invalid OS macros."""
1220 preprocessor_statement
= input_api
.re
.compile(r
'^\s*#')
1221 os_macro
= input_api
.re
.compile(r
'defined\((OS_[^)]+)\)')
1223 for lnum
, line
in f
.ChangedContents():
1224 if preprocessor_statement
.search(line
):
1225 for match
in os_macro
.finditer(line
):
1226 if not match
.group(1) in _VALID_OS_MACROS
:
1227 good
= _DidYouMeanOSMacro(match
.group(1))
1228 did_you_mean
= ' (did you mean %s?)' % good
if good
else ''
1229 results
.append(' %s:%d %s%s' % (f
.LocalPath(),
1236 def _CheckForInvalidOSMacros(input_api
, output_api
):
1237 """Check all affected files for invalid OS macros."""
1239 for f
in input_api
.AffectedFiles():
1240 if not f
.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1241 bad_macros
.extend(_CheckForInvalidOSMacrosInFile(input_api
, f
))
1246 return [output_api
.PresubmitError(
1247 'Possibly invalid OS macro[s] found. Please fix your code\n'
1248 'or add your macro to src/PRESUBMIT.py.', bad_macros
)]
1251 def CheckChangeOnUpload(input_api
, output_api
):
1253 results
.extend(_CommonChecks(input_api
, output_api
))
1254 results
.extend(_CheckJavaStyle(input_api
, output_api
))
1258 def GetDefaultTryConfigs(bots
=None):
1259 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1261 To add tests to this list, they MUST be in the the corresponding master's
1262 gatekeeper config. For example, anything on master.chromium would be closed by
1263 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1265 If 'bots' is specified, will only return configurations for bots in that list.
1271 'cacheinvalidation_unittests',
1274 'content_browsertests',
1275 'content_unittests',
1278 'interactive_ui_tests',
1284 'printing_unittests',
1288 # Broken in release.
1290 #'webkit_unit_tests',
1293 builders_and_tests
= {
1294 # TODO(maruel): Figure out a way to run 'sizes' where people can
1295 # effectively update the perf expectation correctly. This requires a
1296 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1297 # incremental build. Reference:
1298 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1299 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1300 # of this step as a try job failure.
1301 'android_aosp': ['compile'],
1302 'android_clang_dbg': ['slave_steps'],
1303 'android_dbg': ['slave_steps'],
1304 'cros_x86': ['defaulttests'],
1305 'ios_dbg_simulator': [
1308 'content_unittests',
1315 'ios_rel_device': ['compile'],
1316 'linux_asan': ['compile'],
1317 'mac_asan': ['compile'],
1318 #TODO(stip): Change the name of this builder to reflect that it's release.
1319 'linux_gtk': standard_tests
,
1320 'linux_chromeos_asan': ['compile'],
1321 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
1322 'linux_chromium_chromeos_rel': ['defaulttests'],
1323 'linux_chromium_compile_dbg': ['defaulttests'],
1324 'linux_chromium_rel': ['defaulttests'],
1325 'linux_chromium_clang_dbg': ['defaulttests'],
1326 'linux_nacl_sdk_build': ['compile'],
1328 'telemetry_perf_unittests',
1329 'telemetry_unittests',
1331 'mac_chromium_compile_dbg': ['defaulttests'],
1332 'mac_chromium_rel': ['defaulttests'],
1333 'mac_nacl_sdk_build': ['compile'],
1335 'telemetry_perf_unittests',
1336 'telemetry_unittests',
1339 'win_chromium_compile_dbg': ['defaulttests'],
1340 'win_chromium_dbg': ['defaulttests'],
1341 'win_chromium_rel': ['defaulttests'],
1342 'win_chromium_x64_rel': ['defaulttests'],
1343 'win_nacl_sdk_build': ['compile'],
1344 'win_rel': standard_tests
+ [
1345 'app_list_unittests',
1349 'chrome_elf_unittests',
1350 'chromedriver_unittests',
1351 'components_unittests',
1352 'compositor_unittests',
1355 'google_apis_unittests',
1356 'installer_util_unittests',
1357 'mini_installer_test',
1359 'remoting_unittests',
1360 'sync_integration_tests',
1361 'telemetry_perf_unittests',
1362 'telemetry_unittests',
1370 swarm_enabled_builders
= (
1371 # http://crbug.com/354263
1377 swarm_enabled_tests
= (
1380 'interactive_ui_tests',
1385 for bot
in builders_and_tests
:
1386 if bot
in swarm_enabled_builders
:
1387 builders_and_tests
[bot
] = [x
+ '_swarm' if x
in swarm_enabled_tests
else x
1388 for x
in builders_and_tests
[bot
]]
1392 'tryserver.chromium': dict((bot
, set(builders_and_tests
[bot
]))
1397 'tryserver.chromium': dict(
1399 for bot
, tests
in builders_and_tests
.iteritems())
1403 def CheckChangeOnCommit(input_api
, output_api
):
1405 results
.extend(_CommonChecks(input_api
, output_api
))
1406 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1407 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1408 # input_api, output_api, sources))
1409 # Make sure the tree is 'open'.
1410 results
.extend(input_api
.canned_checks
.CheckTreeIsOpen(
1413 json_url
='http://chromium-status.appspot.com/current?format=json'))
1415 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
1416 input_api
, output_api
))
1417 results
.extend(input_api
.canned_checks
.CheckChangeHasDescription(
1418 input_api
, output_api
))
1419 results
.extend(_CheckSubversionConfig(input_api
, output_api
))
1423 def GetPreferredTryMasters(project
, change
):
1424 files
= change
.LocalPaths()
1426 if not files
or all(re
.search(r
'[\\/]OWNERS$', f
) for f
in files
):
1429 if all(re
.search('\.(m|mm)$|(^|[/_])mac[/_.]', f
) for f
in files
):
1430 return GetDefaultTryConfigs([
1431 'mac_chromium_compile_dbg',
1434 if all(re
.search('(^|[/_])win[/_.]', f
) for f
in files
):
1435 return GetDefaultTryConfigs(['win_chromium_dbg', 'win_chromium_rel'])
1436 if all(re
.search('(^|[/_])android[/_.]', f
) for f
in files
):
1437 return GetDefaultTryConfigs([
1439 'android_clang_dbg',
1442 if all(re
.search('[/_]ios[/_.]', f
) for f
in files
):
1443 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
1446 'android_clang_dbg',
1448 'ios_dbg_simulator',
1450 'linux_chromium_chromeos_rel',
1451 'linux_chromium_clang_dbg',
1452 'linux_chromium_rel',
1453 'mac_chromium_compile_dbg',
1455 'win_chromium_compile_dbg',
1457 'win_chromium_x64_rel',
1460 # Match things like path/aura/file.cc and path/file_aura.cc.
1461 # Same for chromeos.
1462 if any(re
.search('[/_](aura|chromeos)', f
) for f
in files
):
1464 'linux_chromeos_asan',
1465 'linux_chromium_chromeos_clang_dbg'
1468 # If there are gyp changes to base, build, or chromeos, run a full cros build
1469 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1470 # files have a much higher chance of breaking the cros build, which is
1471 # differnt from the linux_chromeos build that most chrome developers test
1473 if any(re
.search('^(base|build|chromeos).*\.gypi?$', f
) for f
in files
):
1474 builders
.extend(['cros_x86'])
1476 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1477 # unless they're .gyp(i) files as changes to those files can break the gyp
1479 if (not all(re
.search('^chrome', f
) for f
in files
) or
1480 any(re
.search('\.gypi?$', f
) for f
in files
)):
1481 builders
.extend(['android_aosp'])
1483 return GetDefaultTryConfigs(builders
)