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[\\\/]common[\\\/]test_runner[\\\/].*",
36 r
"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*",
39 # Fragment of a regular expression that matches C++ and Objective-C++
40 # implementation files.
41 _IMPLEMENTATION_EXTENSIONS
= r
'\.(cc|cpp|cxx|mm)$'
43 # Regular expression that matches code only used for test binaries
45 _TEST_CODE_EXCLUDED_PATHS
= (
46 r
'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS
,
47 r
'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS
,
48 r
'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
49 _IMPLEMENTATION_EXTENSIONS
,
50 r
'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS
,
51 r
'.*[/\\](test|tool(s)?)[/\\].*',
52 # content_shell is used for running layout tests.
53 r
'content[/\\]shell[/\\].*',
54 # At request of folks maintaining this folder.
55 r
'chrome[/\\]browser[/\\]automation[/\\].*',
56 # Non-production example code.
57 r
'mojo[/\\]examples[/\\].*',
60 _TEST_ONLY_WARNING
= (
61 'You might be calling functions intended only for testing from\n'
62 'production code. It is OK to ignore this warning if you know what\n'
63 'you are doing, as the heuristics used to detect the situation are\n'
64 'not perfect. The commit queue will not block on this warning.\n'
65 'Email joi@chromium.org if you have questions.')
68 _INCLUDE_ORDER_WARNING
= (
69 'Your #include order seems to be broken. Send mail to\n'
70 'marja@chromium.org if this is not the case.')
73 _BANNED_OBJC_FUNCTIONS
= (
77 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
78 'prohibited. Please use CrTrackingArea instead.',
79 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
86 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
88 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
93 'convertPointFromBase:',
95 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
96 'Please use |convertPoint:(point) fromView:nil| instead.',
97 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
102 'convertPointToBase:',
104 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
105 'Please use |convertPoint:(point) toView:nil| instead.',
106 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
111 'convertRectFromBase:',
113 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
114 'Please use |convertRect:(point) fromView:nil| instead.',
115 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
120 'convertRectToBase:',
122 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
123 'Please use |convertRect:(point) toView:nil| instead.',
124 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
129 'convertSizeFromBase:',
131 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
132 'Please use |convertSize:(point) fromView:nil| instead.',
133 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
138 'convertSizeToBase:',
140 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
141 'Please use |convertSize:(point) toView:nil| instead.',
142 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
149 _BANNED_CPP_FUNCTIONS
= (
150 # Make sure that gtest's FRIEND_TEST() macro is not used; the
151 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
152 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
156 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
157 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
165 'New code should not use ScopedAllowIO. Post a task to the blocking',
166 'pool or the FILE thread instead.',
170 r
"^components[\\\/]breakpad[\\\/]app[\\\/]breakpad_mac\.mm$",
171 r
"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
172 r
"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
173 r
"^mojo[\\\/]system[\\\/]raw_shared_buffer_posix\.cc$",
174 r
"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
180 'The use of SkRefPtr is prohibited. ',
181 'Please use skia::RefPtr instead.'
189 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
190 'Please use skia::RefPtr instead.'
198 'The use of SkAutoTUnref is dangerous because it implicitly ',
199 'converts to a raw pointer. Please use skia::RefPtr instead.'
207 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
208 'because it implicitly converts to a raw pointer. ',
209 'Please use skia::RefPtr instead.'
215 r
'/HANDLE_EINTR\(.*close',
217 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
218 'descriptor will be closed, and it is incorrect to retry the close.',
219 'Either call close directly and ignore its return value, or wrap close',
220 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
226 r
'/IGNORE_EINTR\((?!.*close)',
228 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
229 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
233 # Files that #define IGNORE_EINTR.
234 r
'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
235 r
'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
242 # Please keep sorted.
246 'OS_CAT', # For testing.
261 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api
, output_api
):
262 """Attempts to prevent use of functions intended only for testing in
263 non-testing code. For now this is just a best-effort implementation
264 that ignores header files and may have some false positives. A
265 better implementation would probably need a proper C++ parser.
267 # We only scan .cc files and the like, as the declaration of
268 # for-testing functions in header files are hard to distinguish from
269 # calls to such functions without a proper C++ parser.
270 file_inclusion_pattern
= r
'.+%s' % _IMPLEMENTATION_EXTENSIONS
272 base_function_pattern
= r
'ForTest(ing)?|for_test(ing)?'
273 inclusion_pattern
= input_api
.re
.compile(r
'(%s)\s*\(' % base_function_pattern
)
274 comment_pattern
= input_api
.re
.compile(r
'//.*%s' % base_function_pattern
)
275 exclusion_pattern
= input_api
.re
.compile(
276 r
'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
277 base_function_pattern
, base_function_pattern
))
279 def FilterFile(affected_file
):
280 black_list
= (_EXCLUDED_PATHS
+
281 _TEST_CODE_EXCLUDED_PATHS
+
282 input_api
.DEFAULT_BLACK_LIST
)
283 return input_api
.FilterSourceFile(
285 white_list
=(file_inclusion_pattern
, ),
286 black_list
=black_list
)
289 for f
in input_api
.AffectedSourceFiles(FilterFile
):
290 local_path
= f
.LocalPath()
291 for line_number
, line
in f
.ChangedContents():
292 if (inclusion_pattern
.search(line
) and
293 not comment_pattern
.search(line
) and
294 not exclusion_pattern
.search(line
)):
296 '%s:%d\n %s' % (local_path
, line_number
, line
.strip()))
299 return [output_api
.PresubmitPromptOrNotify(_TEST_ONLY_WARNING
, problems
)]
304 def _CheckNoIOStreamInHeaders(input_api
, output_api
):
305 """Checks to make sure no .h files include <iostream>."""
307 pattern
= input_api
.re
.compile(r
'^#include\s*<iostream>',
308 input_api
.re
.MULTILINE
)
309 for f
in input_api
.AffectedSourceFiles(input_api
.FilterSourceFile
):
310 if not f
.LocalPath().endswith('.h'):
312 contents
= input_api
.ReadFile(f
)
313 if pattern
.search(contents
):
317 return [ output_api
.PresubmitError(
318 'Do not #include <iostream> in header files, since it inserts static '
319 'initialization into every file including the header. Instead, '
320 '#include <ostream>. See http://crbug.com/94794',
325 def _CheckNoUNIT_TESTInSourceFiles(input_api
, output_api
):
326 """Checks to make sure no source files use UNIT_TEST"""
328 for f
in input_api
.AffectedFiles():
329 if (not f
.LocalPath().endswith(('.cc', '.mm'))):
332 for line_num
, line
in f
.ChangedContents():
333 if 'UNIT_TEST ' in line
or line
.endswith('UNIT_TEST'):
334 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
338 return [output_api
.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
339 '\n'.join(problems
))]
342 def _CheckNoNewWStrings(input_api
, output_api
):
343 """Checks to make sure we don't introduce use of wstrings."""
345 for f
in input_api
.AffectedFiles():
346 if (not f
.LocalPath().endswith(('.cc', '.h')) or
347 f
.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
351 for line_num
, line
in f
.ChangedContents():
352 if 'presubmit: allow wstring' in line
:
354 elif not allowWString
and 'wstring' in line
:
355 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
362 return [output_api
.PresubmitPromptWarning('New code should not use wstrings.'
363 ' If you are calling a cross-platform API that accepts a wstring, '
365 '\n'.join(problems
))]
368 def _CheckNoDEPSGIT(input_api
, output_api
):
369 """Make sure .DEPS.git is never modified manually."""
370 if any(f
.LocalPath().endswith('.DEPS.git') for f
in
371 input_api
.AffectedFiles()):
372 return [output_api
.PresubmitError(
373 'Never commit changes to .DEPS.git. This file is maintained by an\n'
374 'automated system based on what\'s in DEPS and your changes will be\n'
376 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
377 'for more information')]
381 def _CheckNoBannedFunctions(input_api
, output_api
):
382 """Make sure that banned functions are not used."""
386 file_filter
= lambda f
: f
.LocalPath().endswith(('.mm', '.m', '.h'))
387 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
388 for line_num
, line
in f
.ChangedContents():
389 for func_name
, message
, error
in _BANNED_OBJC_FUNCTIONS
:
390 if func_name
in line
:
394 problems
.append(' %s:%d:' % (f
.LocalPath(), line_num
))
395 for message_line
in message
:
396 problems
.append(' %s' % message_line
)
398 file_filter
= lambda f
: f
.LocalPath().endswith(('.cc', '.mm', '.h'))
399 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
400 for line_num
, line
in f
.ChangedContents():
401 for func_name
, message
, error
, excluded_paths
in _BANNED_CPP_FUNCTIONS
:
402 def IsBlacklisted(affected_file
, blacklist
):
403 local_path
= affected_file
.LocalPath()
404 for item
in blacklist
:
405 if input_api
.re
.match(item
, local_path
):
408 if IsBlacklisted(f
, excluded_paths
):
411 if func_name
[0:1] == '/':
412 regex
= func_name
[1:]
413 if input_api
.re
.search(regex
, line
):
415 elif func_name
in line
:
421 problems
.append(' %s:%d:' % (f
.LocalPath(), line_num
))
422 for message_line
in message
:
423 problems
.append(' %s' % message_line
)
427 result
.append(output_api
.PresubmitPromptWarning(
428 'Banned functions were used.\n' + '\n'.join(warnings
)))
430 result
.append(output_api
.PresubmitError(
431 'Banned functions were used.\n' + '\n'.join(errors
)))
435 def _CheckNoPragmaOnce(input_api
, output_api
):
436 """Make sure that banned functions are not used."""
438 pattern
= input_api
.re
.compile(r
'^#pragma\s+once',
439 input_api
.re
.MULTILINE
)
440 for f
in input_api
.AffectedSourceFiles(input_api
.FilterSourceFile
):
441 if not f
.LocalPath().endswith('.h'):
443 contents
= input_api
.ReadFile(f
)
444 if pattern
.search(contents
):
448 return [output_api
.PresubmitError(
449 'Do not use #pragma once in header files.\n'
450 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
455 def _CheckNoTrinaryTrueFalse(input_api
, output_api
):
456 """Checks to make sure we don't introduce use of foo ? true : false."""
458 pattern
= input_api
.re
.compile(r
'\?\s*(true|false)\s*:\s*(true|false)')
459 for f
in input_api
.AffectedFiles():
460 if not f
.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
463 for line_num
, line
in f
.ChangedContents():
464 if pattern
.match(line
):
465 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
469 return [output_api
.PresubmitPromptWarning(
470 'Please consider avoiding the "? true : false" pattern if possible.\n' +
471 '\n'.join(problems
))]
474 def _CheckUnwantedDependencies(input_api
, output_api
):
475 """Runs checkdeps on #include statements added in this
476 change. Breaking - rules is an error, breaking ! rules is a
479 # We need to wait until we have an input_api object and use this
480 # roundabout construct to import checkdeps because this file is
481 # eval-ed and thus doesn't have __file__.
482 original_sys_path
= sys
.path
484 sys
.path
= sys
.path
+ [input_api
.os_path
.join(
485 input_api
.PresubmitLocalPath(), 'tools', 'checkdeps')]
487 from cpp_checker
import CppChecker
488 from rules
import Rule
490 # Restore sys.path to what it was before.
491 sys
.path
= original_sys_path
494 for f
in input_api
.AffectedFiles():
495 if not CppChecker
.IsCppFile(f
.LocalPath()):
498 changed_lines
= [line
for line_num
, line
in f
.ChangedContents()]
499 added_includes
.append([f
.LocalPath(), changed_lines
])
501 deps_checker
= checkdeps
.DepsChecker(input_api
.PresubmitLocalPath())
503 error_descriptions
= []
504 warning_descriptions
= []
505 for path
, rule_type
, rule_description
in deps_checker
.CheckAddedCppIncludes(
507 description_with_path
= '%s\n %s' % (path
, rule_description
)
508 if rule_type
== Rule
.DISALLOW
:
509 error_descriptions
.append(description_with_path
)
511 warning_descriptions
.append(description_with_path
)
514 if error_descriptions
:
515 results
.append(output_api
.PresubmitError(
516 'You added one or more #includes that violate checkdeps rules.',
518 if warning_descriptions
:
519 results
.append(output_api
.PresubmitPromptOrNotify(
520 'You added one or more #includes of files that are temporarily\n'
521 'allowed but being removed. Can you avoid introducing the\n'
522 '#include? See relevant DEPS file(s) for details and contacts.',
523 warning_descriptions
))
527 def _CheckFilePermissions(input_api
, output_api
):
528 """Check that all files have their permissions properly set."""
529 if input_api
.platform
== 'win32':
531 args
= [sys
.executable
, 'tools/checkperms/checkperms.py', '--root',
532 input_api
.change
.RepositoryRoot()]
533 for f
in input_api
.AffectedFiles():
534 args
+= ['--file', f
.LocalPath()]
535 checkperms
= input_api
.subprocess
.Popen(args
,
536 stdout
=input_api
.subprocess
.PIPE
)
537 errors
= checkperms
.communicate()[0].strip()
539 return [output_api
.PresubmitError('checkperms.py failed.',
540 errors
.splitlines())]
544 def _CheckNoAuraWindowPropertyHInHeaders(input_api
, output_api
):
545 """Makes sure we don't include ui/aura/window_property.h
548 pattern
= input_api
.re
.compile(r
'^#include\s*"ui/aura/window_property.h"')
550 for f
in input_api
.AffectedFiles():
551 if not f
.LocalPath().endswith('.h'):
553 for line_num
, line
in f
.ChangedContents():
554 if pattern
.match(line
):
555 errors
.append(' %s:%d' % (f
.LocalPath(), line_num
))
559 results
.append(output_api
.PresubmitError(
560 'Header files should not include ui/aura/window_property.h', errors
))
564 def _CheckIncludeOrderForScope(scope
, input_api
, file_path
, changed_linenums
):
565 """Checks that the lines in scope occur in the right order.
567 1. C system files in alphabetical order
568 2. C++ system files in alphabetical order
569 3. Project's .h files
572 c_system_include_pattern
= input_api
.re
.compile(r
'\s*#include <.*\.h>')
573 cpp_system_include_pattern
= input_api
.re
.compile(r
'\s*#include <.*>')
574 custom_include_pattern
= input_api
.re
.compile(r
'\s*#include ".*')
576 C_SYSTEM_INCLUDES
, CPP_SYSTEM_INCLUDES
, CUSTOM_INCLUDES
= range(3)
578 state
= C_SYSTEM_INCLUDES
581 previous_line_num
= 0
582 problem_linenums
= []
583 for line_num
, line
in scope
:
584 if c_system_include_pattern
.match(line
):
585 if state
!= C_SYSTEM_INCLUDES
:
586 problem_linenums
.append((line_num
, previous_line_num
))
587 elif previous_line
and previous_line
> line
:
588 problem_linenums
.append((line_num
, previous_line_num
))
589 elif cpp_system_include_pattern
.match(line
):
590 if state
== C_SYSTEM_INCLUDES
:
591 state
= CPP_SYSTEM_INCLUDES
592 elif state
== CUSTOM_INCLUDES
:
593 problem_linenums
.append((line_num
, previous_line_num
))
594 elif previous_line
and previous_line
> line
:
595 problem_linenums
.append((line_num
, previous_line_num
))
596 elif custom_include_pattern
.match(line
):
597 if state
!= CUSTOM_INCLUDES
:
598 state
= CUSTOM_INCLUDES
599 elif previous_line
and previous_line
> line
:
600 problem_linenums
.append((line_num
, previous_line_num
))
602 problem_linenums
.append(line_num
)
604 previous_line_num
= line_num
607 for (line_num
, previous_line_num
) in problem_linenums
:
608 if line_num
in changed_linenums
or previous_line_num
in changed_linenums
:
609 warnings
.append(' %s:%d' % (file_path
, line_num
))
613 def _CheckIncludeOrderInFile(input_api
, f
, changed_linenums
):
614 """Checks the #include order for the given file f."""
616 system_include_pattern
= input_api
.re
.compile(r
'\s*#include \<.*')
617 # Exclude the following includes from the check:
618 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
620 # 2) <atlbase.h>, "build/build_config.h"
621 excluded_include_pattern
= input_api
.re
.compile(
622 r
'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
623 custom_include_pattern
= input_api
.re
.compile(r
'\s*#include "(?P<FILE>.*)"')
624 # Match the final or penultimate token if it is xxxtest so we can ignore it
625 # when considering the special first include.
626 test_file_tag_pattern
= input_api
.re
.compile(
627 r
'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
628 if_pattern
= input_api
.re
.compile(
629 r
'\s*#\s*(if|elif|else|endif|define|undef).*')
630 # Some files need specialized order of includes; exclude such files from this
632 uncheckable_includes_pattern
= input_api
.re
.compile(
634 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
636 contents
= f
.NewContents()
640 # Handle the special first include. If the first include file is
641 # some/path/file.h, the corresponding including file can be some/path/file.cc,
642 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
643 # etc. It's also possible that no special first include exists.
644 # If the included file is some/path/file_platform.h the including file could
645 # also be some/path/file_xxxtest_platform.h.
646 including_file_base_name
= test_file_tag_pattern
.sub(
647 '', input_api
.os_path
.basename(f
.LocalPath()))
649 for line
in contents
:
651 if system_include_pattern
.match(line
):
652 # No special first include -> process the line again along with normal
656 match
= custom_include_pattern
.match(line
)
658 match_dict
= match
.groupdict()
659 header_basename
= test_file_tag_pattern
.sub(
660 '', input_api
.os_path
.basename(match_dict
['FILE'])).replace('.h', '')
662 if header_basename
not in including_file_base_name
:
663 # No special first include -> process the line again along with normal
668 # Split into scopes: Each region between #if and #endif is its own scope.
671 for line
in contents
[line_num
:]:
673 if uncheckable_includes_pattern
.match(line
):
675 if if_pattern
.match(line
):
676 scopes
.append(current_scope
)
678 elif ((system_include_pattern
.match(line
) or
679 custom_include_pattern
.match(line
)) and
680 not excluded_include_pattern
.match(line
)):
681 current_scope
.append((line_num
, line
))
682 scopes
.append(current_scope
)
685 warnings
.extend(_CheckIncludeOrderForScope(scope
, input_api
, f
.LocalPath(),
690 def _CheckIncludeOrder(input_api
, output_api
):
691 """Checks that the #include order is correct.
693 1. The corresponding header for source files.
694 2. C system files in alphabetical order
695 3. C++ system files in alphabetical order
696 4. Project's .h files in alphabetical order
698 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
699 these rules separately.
703 for f
in input_api
.AffectedFiles():
704 if f
.LocalPath().endswith(('.cc', '.h')):
705 changed_linenums
= set(line_num
for line_num
, _
in f
.ChangedContents())
706 warnings
.extend(_CheckIncludeOrderInFile(input_api
, f
, changed_linenums
))
710 results
.append(output_api
.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING
,
715 def _CheckForVersionControlConflictsInFile(input_api
, f
):
716 pattern
= input_api
.re
.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
718 for line_num
, line
in f
.ChangedContents():
719 if pattern
.match(line
):
720 errors
.append(' %s:%d %s' % (f
.LocalPath(), line_num
, line
))
724 def _CheckForVersionControlConflicts(input_api
, output_api
):
725 """Usually this is not intentional and will cause a compile failure."""
727 for f
in input_api
.AffectedFiles():
728 errors
.extend(_CheckForVersionControlConflictsInFile(input_api
, f
))
732 results
.append(output_api
.PresubmitError(
733 'Version control conflict markers found, please resolve.', errors
))
737 def _CheckHardcodedGoogleHostsInLowerLayers(input_api
, output_api
):
738 def FilterFile(affected_file
):
739 """Filter function for use with input_api.AffectedSourceFiles,
740 below. This filters out everything except non-test files from
741 top-level directories that generally speaking should not hard-code
742 service URLs (e.g. src/android_webview/, src/content/ and others).
744 return input_api
.FilterSourceFile(
746 white_list
=(r
'^(android_webview|base|content|net)[\\\/].*', ),
747 black_list
=(_EXCLUDED_PATHS
+
748 _TEST_CODE_EXCLUDED_PATHS
+
749 input_api
.DEFAULT_BLACK_LIST
))
751 base_pattern
= '"[^"]*google\.com[^"]*"'
752 comment_pattern
= input_api
.re
.compile('//.*%s' % base_pattern
)
753 pattern
= input_api
.re
.compile(base_pattern
)
754 problems
= [] # items are (filename, line_number, line)
755 for f
in input_api
.AffectedSourceFiles(FilterFile
):
756 for line_num
, line
in f
.ChangedContents():
757 if not comment_pattern
.search(line
) and pattern
.search(line
):
758 problems
.append((f
.LocalPath(), line_num
, line
))
761 return [output_api
.PresubmitPromptOrNotify(
762 'Most layers below src/chrome/ should not hardcode service URLs.\n'
763 'Are you sure this is correct? (Contact: joi@chromium.org)',
765 problem
[0], problem
[1], problem
[2]) for problem
in problems
])]
770 def _CheckNoAbbreviationInPngFileName(input_api
, output_api
):
771 """Makes sure there are no abbreviations in the name of PNG files.
773 pattern
= input_api
.re
.compile(r
'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
775 for f
in input_api
.AffectedFiles(include_deletes
=False):
776 if pattern
.match(f
.LocalPath()):
777 errors
.append(' %s' % f
.LocalPath())
781 results
.append(output_api
.PresubmitError(
782 'The name of PNG files should not have abbreviations. \n'
783 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
784 'Contact oshima@chromium.org if you have questions.', errors
))
788 def _FilesToCheckForIncomingDeps(re
, changed_lines
):
789 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
790 a set of DEPS entries that we should look up.
792 For a directory (rather than a specific filename) we fake a path to
793 a specific filename by adding /DEPS. This is chosen as a file that
794 will seldom or never be subject to per-file include_rules.
796 # We ignore deps entries on auto-generated directories.
797 AUTO_GENERATED_DIRS
= ['grit', 'jni']
799 # This pattern grabs the path without basename in the first
800 # parentheses, and the basename (if present) in the second. It
801 # relies on the simple heuristic that if there is a basename it will
802 # be a header file ending in ".h".
803 pattern
= re
.compile(
804 r
"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
806 for changed_line
in changed_lines
:
807 m
= pattern
.match(changed_line
)
810 if path
.split('/')[0] not in AUTO_GENERATED_DIRS
:
812 results
.add('%s%s' % (path
, m
.group(2)))
814 results
.add('%s/DEPS' % path
)
818 def _CheckAddedDepsHaveTargetApprovals(input_api
, output_api
):
819 """When a dependency prefixed with + is added to a DEPS file, we
820 want to make sure that the change is reviewed by an OWNER of the
821 target file or directory, to avoid layering violations from being
822 introduced. This check verifies that this happens.
824 changed_lines
= set()
825 for f
in input_api
.AffectedFiles():
826 filename
= input_api
.os_path
.basename(f
.LocalPath())
827 if filename
== 'DEPS':
828 changed_lines |
= set(line
.strip()
830 in f
.ChangedContents())
831 if not changed_lines
:
834 virtual_depended_on_files
= _FilesToCheckForIncomingDeps(input_api
.re
,
836 if not virtual_depended_on_files
:
839 if input_api
.is_committing
:
841 return [output_api
.PresubmitNotifyResult(
842 '--tbr was specified, skipping OWNERS check for DEPS additions')]
843 if not input_api
.change
.issue
:
844 return [output_api
.PresubmitError(
845 "DEPS approval by OWNERS check failed: this change has "
846 "no Rietveld issue number, so we can't check it for approvals.")]
847 output
= output_api
.PresubmitError
849 output
= output_api
.PresubmitNotifyResult
851 owners_db
= input_api
.owners_db
852 owner_email
, reviewers
= input_api
.canned_checks
._RietveldOwnerAndReviewers
(
854 owners_db
.email_regexp
,
855 approval_needed
=input_api
.is_committing
)
857 owner_email
= owner_email
or input_api
.change
.author_email
859 reviewers_plus_owner
= set(reviewers
)
861 reviewers_plus_owner
.add(owner_email
)
862 missing_files
= owners_db
.files_not_covered_by(virtual_depended_on_files
,
863 reviewers_plus_owner
)
865 # We strip the /DEPS part that was added by
866 # _FilesToCheckForIncomingDeps to fake a path to a file in a
869 start_deps
= path
.rfind('/DEPS')
871 return path
[:start_deps
]
874 unapproved_dependencies
= ["'+%s'," % StripDeps(path
)
875 for path
in missing_files
]
877 if unapproved_dependencies
:
879 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
880 '\n '.join(sorted(unapproved_dependencies
)))]
881 if not input_api
.is_committing
:
882 suggested_owners
= owners_db
.reviewers_for(missing_files
, owner_email
)
883 output_list
.append(output(
884 'Suggested missing target path OWNERS:\n %s' %
885 '\n '.join(suggested_owners
or [])))
891 def _CheckSpamLogging(input_api
, output_api
):
892 file_inclusion_pattern
= r
'.+%s' % _IMPLEMENTATION_EXTENSIONS
893 black_list
= (_EXCLUDED_PATHS
+
894 _TEST_CODE_EXCLUDED_PATHS
+
895 input_api
.DEFAULT_BLACK_LIST
+
896 (r
"^base[\\\/]logging\.h$",
897 r
"^base[\\\/]logging\.cc$",
898 r
"^cloud_print[\\\/]",
899 r
"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
900 r
"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
901 r
"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
902 r
"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
903 r
"startup_browser_creator\.cc$",
904 r
"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
905 r
"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
906 r
"logging_native_handler\.cc$",
907 r
"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
908 r
"gl_helper_benchmark\.cc$",
909 r
"^native_client_sdk[\\\/]",
910 r
"^remoting[\\\/]base[\\\/]logging\.h$",
911 r
"^remoting[\\\/]host[\\\/].*",
912 r
"^sandbox[\\\/]linux[\\\/].*",
914 r
"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
915 source_file_filter
= lambda x
: input_api
.FilterSourceFile(
916 x
, white_list
=(file_inclusion_pattern
,), black_list
=black_list
)
921 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
922 contents
= input_api
.ReadFile(f
, 'rb')
923 if re
.search(r
"\bD?LOG\s*\(\s*INFO\s*\)", contents
):
924 log_info
.append(f
.LocalPath())
925 elif re
.search(r
"\bD?LOG_IF\s*\(\s*INFO\s*,", contents
):
926 log_info
.append(f
.LocalPath())
928 if re
.search(r
"\bprintf\(", contents
):
929 printf
.append(f
.LocalPath())
930 elif re
.search(r
"\bfprintf\((stdout|stderr)", contents
):
931 printf
.append(f
.LocalPath())
934 return [output_api
.PresubmitError(
935 'These files spam the console log with LOG(INFO):',
938 return [output_api
.PresubmitError(
939 'These files spam the console log with printf/fprintf:',
944 def _CheckForAnonymousVariables(input_api
, output_api
):
945 """These types are all expected to hold locks while in scope and
946 so should never be anonymous (which causes them to be immediately
948 they_who_must_be_named
= [
952 'SkAutoAlphaRestore',
953 'SkAutoBitmapShaderInstall',
954 'SkAutoBlitterChoose',
955 'SkAutoBounderCommit',
957 'SkAutoCanvasRestore',
958 'SkAutoCommentBlock',
960 'SkAutoDisableDirectionCheck',
961 'SkAutoDisableOvalCheck',
968 'SkAutoMaskFreeImage',
969 'SkAutoMutexAcquire',
970 'SkAutoPathBoundsUpdate',
972 'SkAutoRasterClipValidate',
978 anonymous
= r
'(%s)\s*[({]' % '|'.join(they_who_must_be_named
)
979 # bad: base::AutoLock(lock.get());
980 # not bad: base::AutoLock lock(lock.get());
981 bad_pattern
= input_api
.re
.compile(anonymous
)
982 # good: new base::AutoLock(lock.get())
983 good_pattern
= input_api
.re
.compile(r
'\bnew\s*' + anonymous
)
986 for f
in input_api
.AffectedFiles():
987 if not f
.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
989 for linenum
, line
in f
.ChangedContents():
990 if bad_pattern
.search(line
) and not good_pattern
.search(line
):
991 errors
.append('%s:%d' % (f
.LocalPath(), linenum
))
994 return [output_api
.PresubmitError(
995 'These lines create anonymous variables that need to be named:',
1000 def _CheckCygwinShell(input_api
, output_api
):
1001 source_file_filter
= lambda x
: input_api
.FilterSourceFile(
1002 x
, white_list
=(r
'.+\.(gyp|gypi)$',))
1005 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
1006 for linenum
, line
in f
.ChangedContents():
1007 if 'msvs_cygwin_shell' in line
:
1008 cygwin_shell
.append(f
.LocalPath())
1012 return [output_api
.PresubmitError(
1013 'These files should not use msvs_cygwin_shell (the default is 0):',
1014 items
=cygwin_shell
)]
1018 def _CheckUserActionUpdate(input_api
, output_api
):
1019 """Checks if any new user action has been added."""
1020 if any('actions.xml' == input_api
.os_path
.basename(f
) for f
in
1021 input_api
.LocalPaths()):
1022 # If actions.xml is already included in the changelist, the PRESUBMIT
1023 # for actions.xml will do a more complete presubmit check.
1026 file_filter
= lambda f
: f
.LocalPath().endswith(('.cc', '.mm'))
1027 action_re
= r
'[^a-zA-Z]UserMetricsAction\("([^"]*)'
1028 current_actions
= None
1029 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
1030 for line_num
, line
in f
.ChangedContents():
1031 match
= input_api
.re
.search(action_re
, line
)
1033 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1035 if not current_actions
:
1036 with
open('tools/metrics/actions/actions.xml') as actions_f
:
1037 current_actions
= actions_f
.read()
1038 # Search for the matched user action name in |current_actions|.
1039 for action_name
in match
.groups():
1040 action
= 'name="{0}"'.format(action_name
)
1041 if action
not in current_actions
:
1042 return [output_api
.PresubmitPromptWarning(
1043 'File %s line %d: %s is missing in '
1044 'tools/metrics/actions/actions.xml. Please run '
1045 'tools/metrics/actions/extract_actions.py to update.'
1046 % (f
.LocalPath(), line_num
, action_name
))]
1050 def _CheckJavaStyle(input_api
, output_api
):
1051 """Runs checkstyle on changed java files and returns errors if any exist."""
1052 original_sys_path
= sys
.path
1054 sys
.path
= sys
.path
+ [input_api
.os_path
.join(
1055 input_api
.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1058 # Restore sys.path to what it was before.
1059 sys
.path
= original_sys_path
1061 return checkstyle
.RunCheckstyle(
1062 input_api
, output_api
, 'tools/android/checkstyle/chromium-style-5.0.xml')
1065 def _CommonChecks(input_api
, output_api
):
1066 """Checks common to both upload and commit."""
1068 results
.extend(input_api
.canned_checks
.PanProjectChecks(
1069 input_api
, output_api
,
1070 excluded_paths
=_EXCLUDED_PATHS
+ _TESTRUNNER_PATHS
))
1071 results
.extend(_CheckAuthorizedAuthor(input_api
, output_api
))
1073 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api
, output_api
))
1074 results
.extend(_CheckNoIOStreamInHeaders(input_api
, output_api
))
1075 results
.extend(_CheckNoUNIT_TESTInSourceFiles(input_api
, output_api
))
1076 results
.extend(_CheckNoNewWStrings(input_api
, output_api
))
1077 results
.extend(_CheckNoDEPSGIT(input_api
, output_api
))
1078 results
.extend(_CheckNoBannedFunctions(input_api
, output_api
))
1079 results
.extend(_CheckNoPragmaOnce(input_api
, output_api
))
1080 results
.extend(_CheckNoTrinaryTrueFalse(input_api
, output_api
))
1081 results
.extend(_CheckUnwantedDependencies(input_api
, output_api
))
1082 results
.extend(_CheckFilePermissions(input_api
, output_api
))
1083 results
.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api
, output_api
))
1084 results
.extend(_CheckIncludeOrder(input_api
, output_api
))
1085 results
.extend(_CheckForVersionControlConflicts(input_api
, output_api
))
1086 results
.extend(_CheckPatchFiles(input_api
, output_api
))
1087 results
.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api
, output_api
))
1088 results
.extend(_CheckNoAbbreviationInPngFileName(input_api
, output_api
))
1089 results
.extend(_CheckForInvalidOSMacros(input_api
, output_api
))
1090 results
.extend(_CheckAddedDepsHaveTargetApprovals(input_api
, output_api
))
1092 input_api
.canned_checks
.CheckChangeHasNoTabs(
1095 source_file_filter
=lambda x
: x
.LocalPath().endswith('.grd')))
1096 results
.extend(_CheckSpamLogging(input_api
, output_api
))
1097 results
.extend(_CheckForAnonymousVariables(input_api
, output_api
))
1098 results
.extend(_CheckCygwinShell(input_api
, output_api
))
1099 results
.extend(_CheckUserActionUpdate(input_api
, output_api
))
1101 if any('PRESUBMIT.py' == f
.LocalPath() for f
in input_api
.AffectedFiles()):
1102 results
.extend(input_api
.canned_checks
.RunUnitTestsInDirectory(
1103 input_api
, output_api
,
1104 input_api
.PresubmitLocalPath(),
1105 whitelist
=[r
'^PRESUBMIT_test\.py$']))
1109 def _CheckSubversionConfig(input_api
, output_api
):
1110 """Verifies the subversion config file is correctly setup.
1112 Checks that autoprops are enabled, returns an error otherwise.
1114 join
= input_api
.os_path
.join
1115 if input_api
.platform
== 'win32':
1116 appdata
= input_api
.environ
.get('APPDATA', '')
1118 return [output_api
.PresubmitError('%APPDATA% is not configured.')]
1119 path
= join(appdata
, 'Subversion', 'config')
1121 home
= input_api
.environ
.get('HOME', '')
1123 return [output_api
.PresubmitError('$HOME is not configured.')]
1124 path
= join(home
, '.subversion', 'config')
1127 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1128 'configure your subversion configuration file. This enables automatic\n'
1129 'properties to simplify the project maintenance.\n'
1130 'Pro-tip: just download and install\n'
1131 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
1134 lines
= open(path
, 'r').read().splitlines()
1135 # Make sure auto-props is enabled and check for 2 Chromium standard
1137 if (not '*.cc = svn:eol-style=LF' in lines
or
1138 not '*.pdf = svn:mime-type=application/pdf' in lines
or
1139 not 'enable-auto-props = yes' in lines
):
1141 output_api
.PresubmitNotifyResult(
1142 'It looks like you have not configured your subversion config '
1143 'file or it is not up-to-date.\n' + error_msg
)
1145 except (OSError, IOError):
1147 output_api
.PresubmitNotifyResult(
1148 'Can\'t find your subversion config file.\n' + error_msg
)
1153 def _CheckAuthorizedAuthor(input_api
, output_api
):
1154 """For non-googler/chromites committers, verify the author's email address is
1157 # TODO(maruel): Add it to input_api?
1160 author
= input_api
.change
.author_email
1162 input_api
.logging
.info('No author, skipping AUTHOR check')
1164 authors_path
= input_api
.os_path
.join(
1165 input_api
.PresubmitLocalPath(), 'AUTHORS')
1167 input_api
.re
.match(r
'[^#]+\s+\<(.+?)\>\s*$', line
)
1168 for line
in open(authors_path
))
1169 valid_authors
= [item
.group(1).lower() for item
in valid_authors
if item
]
1170 if not any(fnmatch
.fnmatch(author
.lower(), valid
) for valid
in valid_authors
):
1171 input_api
.logging
.info('Valid authors are %s', ', '.join(valid_authors
))
1172 return [output_api
.PresubmitPromptWarning(
1173 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1175 'http://www.chromium.org/developers/contributing-code and read the '
1177 'If you are a chromite, verify the contributor signed the CLA.') %
1182 def _CheckPatchFiles(input_api
, output_api
):
1183 problems
= [f
.LocalPath() for f
in input_api
.AffectedFiles()
1184 if f
.LocalPath().endswith(('.orig', '.rej'))]
1186 return [output_api
.PresubmitError(
1187 "Don't commit .rej and .orig files.", problems
)]
1192 def _DidYouMeanOSMacro(bad_macro
):
1194 return {'A': 'OS_ANDROID',
1204 'W': 'OS_WIN'}[bad_macro
[3].upper()]
1209 def _CheckForInvalidOSMacrosInFile(input_api
, f
):
1210 """Check for sensible looking, totally invalid OS macros."""
1211 preprocessor_statement
= input_api
.re
.compile(r
'^\s*#')
1212 os_macro
= input_api
.re
.compile(r
'defined\((OS_[^)]+)\)')
1214 for lnum
, line
in f
.ChangedContents():
1215 if preprocessor_statement
.search(line
):
1216 for match
in os_macro
.finditer(line
):
1217 if not match
.group(1) in _VALID_OS_MACROS
:
1218 good
= _DidYouMeanOSMacro(match
.group(1))
1219 did_you_mean
= ' (did you mean %s?)' % good
if good
else ''
1220 results
.append(' %s:%d %s%s' % (f
.LocalPath(),
1227 def _CheckForInvalidOSMacros(input_api
, output_api
):
1228 """Check all affected files for invalid OS macros."""
1230 for f
in input_api
.AffectedFiles():
1231 if not f
.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1232 bad_macros
.extend(_CheckForInvalidOSMacrosInFile(input_api
, f
))
1237 return [output_api
.PresubmitError(
1238 'Possibly invalid OS macro[s] found. Please fix your code\n'
1239 'or add your macro to src/PRESUBMIT.py.', bad_macros
)]
1242 def CheckChangeOnUpload(input_api
, output_api
):
1244 results
.extend(_CommonChecks(input_api
, output_api
))
1245 results
.extend(_CheckJavaStyle(input_api
, output_api
))
1249 def GetDefaultTryConfigs(bots
=None):
1250 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1252 To add tests to this list, they MUST be in the the corresponding master's
1253 gatekeeper config. For example, anything on master.chromium would be closed by
1254 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1256 If 'bots' is specified, will only return configurations for bots in that list.
1262 'cacheinvalidation_unittests',
1265 'content_browsertests',
1266 'content_unittests',
1269 'interactive_ui_tests',
1275 'printing_unittests',
1279 # Broken in release.
1281 #'webkit_unit_tests',
1284 builders_and_tests
= {
1285 # TODO(maruel): Figure out a way to run 'sizes' where people can
1286 # effectively update the perf expectation correctly. This requires a
1287 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1288 # incremental build. Reference:
1289 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1290 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1291 # of this step as a try job failure.
1292 'android_aosp': ['compile'],
1293 'android_clang_dbg': ['slave_steps'],
1294 'android_dbg': ['slave_steps'],
1295 'cros_x86': ['defaulttests'],
1296 'ios_dbg_simulator': [
1299 'content_unittests',
1306 'ios_rel_device': ['compile'],
1307 'linux_asan': ['compile'],
1308 'mac_asan': ['compile'],
1309 #TODO(stip): Change the name of this builder to reflect that it's release.
1310 'linux_gtk': standard_tests
,
1311 'linux_chromeos_asan': ['compile'],
1312 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
1313 'linux_chromium_chromeos_rel': ['defaulttests'],
1314 'linux_chromium_compile_dbg': ['defaulttests'],
1315 'linux_chromium_rel': ['defaulttests'],
1316 'linux_chromium_clang_dbg': ['defaulttests'],
1317 'linux_nacl_sdk_build': ['compile'],
1319 'telemetry_perf_unittests',
1320 'telemetry_unittests',
1322 'mac_chromium_compile_dbg': ['defaulttests'],
1323 'mac_chromium_rel': ['defaulttests'],
1324 'mac_nacl_sdk_build': ['compile'],
1326 'telemetry_perf_unittests',
1327 'telemetry_unittests',
1330 'win_chromium_compile_dbg': ['defaulttests'],
1331 'win_nacl_sdk_build': ['compile'],
1332 'win_rel': standard_tests
+ [
1333 'app_list_unittests',
1337 'chrome_elf_unittests',
1338 'chromedriver_unittests',
1339 'components_unittests',
1340 'compositor_unittests',
1343 'google_apis_unittests',
1344 'installer_util_unittests',
1345 'mini_installer_test',
1347 'remoting_unittests',
1348 'sync_integration_tests',
1349 'telemetry_perf_unittests',
1350 'telemetry_unittests',
1358 swarm_enabled_builders
= (
1359 # http://crbug.com/354263
1365 swarm_enabled_tests
= (
1368 'interactive_ui_tests',
1373 for bot
in builders_and_tests
:
1374 if bot
in swarm_enabled_builders
:
1375 builders_and_tests
[bot
] = [x
+ '_swarm' if x
in swarm_enabled_tests
else x
1376 for x
in builders_and_tests
[bot
]]
1380 'tryserver.chromium': dict((bot
, set(builders_and_tests
[bot
]))
1385 'tryserver.chromium': dict(
1387 for bot
, tests
in builders_and_tests
.iteritems())
1391 def CheckChangeOnCommit(input_api
, output_api
):
1393 results
.extend(_CommonChecks(input_api
, output_api
))
1394 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1395 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1396 # input_api, output_api, sources))
1397 # Make sure the tree is 'open'.
1398 results
.extend(input_api
.canned_checks
.CheckTreeIsOpen(
1401 json_url
='http://chromium-status.appspot.com/current?format=json'))
1403 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
1404 input_api
, output_api
))
1405 results
.extend(input_api
.canned_checks
.CheckChangeHasDescription(
1406 input_api
, output_api
))
1407 results
.extend(_CheckSubversionConfig(input_api
, output_api
))
1411 def GetPreferredTryMasters(project
, change
):
1412 files
= change
.LocalPaths()
1414 if not files
or all(re
.search(r
'[\\/]OWNERS$', f
) for f
in files
):
1417 if all(re
.search('\.(m|mm)$|(^|[/_])mac[/_.]', f
) for f
in files
):
1418 return GetDefaultTryConfigs([
1419 'mac_chromium_compile_dbg',
1422 if all(re
.search('(^|[/_])win[/_.]', f
) for f
in files
):
1423 return GetDefaultTryConfigs(['win', 'win_rel'])
1424 if all(re
.search('(^|[/_])android[/_.]', f
) for f
in files
):
1425 return GetDefaultTryConfigs([
1427 'android_clang_dbg',
1430 if all(re
.search('[/_]ios[/_.]', f
) for f
in files
):
1431 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
1434 'android_clang_dbg',
1436 'ios_dbg_simulator',
1438 'linux_chromium_chromeos_rel',
1439 'linux_chromium_clang_dbg',
1440 'linux_chromium_rel',
1441 'mac_chromium_compile_dbg',
1443 'win_chromium_compile_dbg',
1448 # Match things like path/aura/file.cc and path/file_aura.cc.
1449 # Same for chromeos.
1450 if any(re
.search('[/_](aura|chromeos)', f
) for f
in files
):
1452 'linux_chromeos_asan',
1453 'linux_chromium_chromeos_clang_dbg'
1456 # If there are gyp changes to base, build, or chromeos, run a full cros build
1457 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1458 # files have a much higher chance of breaking the cros build, which is
1459 # differnt from the linux_chromeos build that most chrome developers test
1461 if any(re
.search('^(base|build|chromeos).*\.gypi?$', f
) for f
in files
):
1462 builders
.extend(['cros_x86'])
1464 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1465 # unless they're .gyp(i) files as changes to those files can break the gyp
1467 if (not all(re
.search('^chrome', f
) for f
in files
) or
1468 any(re
.search('\.gypi?$', f
) for f
in files
)):
1469 builders
.extend(['android_aosp'])
1471 return GetDefaultTryConfigs(builders
)