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$",
173 r
"^net[\\\/]url_request[\\\/]test_url_fetcher_factory\.cc$",
179 'The use of SkRefPtr is prohibited. ',
180 'Please use skia::RefPtr instead.'
188 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
189 'Please use skia::RefPtr instead.'
197 'The use of SkAutoTUnref is dangerous because it implicitly ',
198 'converts to a raw pointer. Please use skia::RefPtr instead.'
206 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
207 'because it implicitly converts to a raw pointer. ',
208 'Please use skia::RefPtr instead.'
214 r
'/HANDLE_EINTR\(.*close',
216 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
217 'descriptor will be closed, and it is incorrect to retry the close.',
218 'Either call close directly and ignore its return value, or wrap close',
219 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
225 r
'/IGNORE_EINTR\((?!.*close)',
227 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
228 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
232 # Files that #define IGNORE_EINTR.
233 r
'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
234 r
'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
240 'Do not introduce new v8::Extensions into the code base, use',
241 'gin::Wrappable instead. See http://crbug.com/334679',
245 r
'extensions[/\\]renderer[/\\]safe_builtins\.*',
252 # Please keep sorted.
256 'OS_CAT', # For testing.
271 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api
, output_api
):
272 """Attempts to prevent use of functions intended only for testing in
273 non-testing code. For now this is just a best-effort implementation
274 that ignores header files and may have some false positives. A
275 better implementation would probably need a proper C++ parser.
277 # We only scan .cc files and the like, as the declaration of
278 # for-testing functions in header files are hard to distinguish from
279 # calls to such functions without a proper C++ parser.
280 file_inclusion_pattern
= r
'.+%s' % _IMPLEMENTATION_EXTENSIONS
282 base_function_pattern
= r
'[ :]test::[^\s]+|ForTest(ing)?|for_test(ing)?'
283 inclusion_pattern
= input_api
.re
.compile(r
'(%s)\s*\(' % base_function_pattern
)
284 comment_pattern
= input_api
.re
.compile(r
'//.*(%s)' % base_function_pattern
)
285 exclusion_pattern
= input_api
.re
.compile(
286 r
'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
287 base_function_pattern
, base_function_pattern
))
289 def FilterFile(affected_file
):
290 black_list
= (_EXCLUDED_PATHS
+
291 _TEST_CODE_EXCLUDED_PATHS
+
292 input_api
.DEFAULT_BLACK_LIST
)
293 return input_api
.FilterSourceFile(
295 white_list
=(file_inclusion_pattern
, ),
296 black_list
=black_list
)
299 for f
in input_api
.AffectedSourceFiles(FilterFile
):
300 local_path
= f
.LocalPath()
301 for line_number
, line
in f
.ChangedContents():
302 if (inclusion_pattern
.search(line
) and
303 not comment_pattern
.search(line
) and
304 not exclusion_pattern
.search(line
)):
306 '%s:%d\n %s' % (local_path
, line_number
, line
.strip()))
309 return [output_api
.PresubmitPromptOrNotify(_TEST_ONLY_WARNING
, problems
)]
314 def _CheckNoIOStreamInHeaders(input_api
, output_api
):
315 """Checks to make sure no .h files include <iostream>."""
317 pattern
= input_api
.re
.compile(r
'^#include\s*<iostream>',
318 input_api
.re
.MULTILINE
)
319 for f
in input_api
.AffectedSourceFiles(input_api
.FilterSourceFile
):
320 if not f
.LocalPath().endswith('.h'):
322 contents
= input_api
.ReadFile(f
)
323 if pattern
.search(contents
):
327 return [ output_api
.PresubmitError(
328 'Do not #include <iostream> in header files, since it inserts static '
329 'initialization into every file including the header. Instead, '
330 '#include <ostream>. See http://crbug.com/94794',
335 def _CheckNoUNIT_TESTInSourceFiles(input_api
, output_api
):
336 """Checks to make sure no source files use UNIT_TEST"""
338 for f
in input_api
.AffectedFiles():
339 if (not f
.LocalPath().endswith(('.cc', '.mm'))):
342 for line_num
, line
in f
.ChangedContents():
343 if 'UNIT_TEST ' in line
or line
.endswith('UNIT_TEST'):
344 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
348 return [output_api
.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
349 '\n'.join(problems
))]
352 def _CheckNoNewWStrings(input_api
, output_api
):
353 """Checks to make sure we don't introduce use of wstrings."""
355 for f
in input_api
.AffectedFiles():
356 if (not f
.LocalPath().endswith(('.cc', '.h')) or
357 f
.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
361 for line_num
, line
in f
.ChangedContents():
362 if 'presubmit: allow wstring' in line
:
364 elif not allowWString
and 'wstring' in line
:
365 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
372 return [output_api
.PresubmitPromptWarning('New code should not use wstrings.'
373 ' If you are calling a cross-platform API that accepts a wstring, '
375 '\n'.join(problems
))]
378 def _CheckNoDEPSGIT(input_api
, output_api
):
379 """Make sure .DEPS.git is never modified manually."""
380 if any(f
.LocalPath().endswith('.DEPS.git') for f
in
381 input_api
.AffectedFiles()):
382 return [output_api
.PresubmitError(
383 'Never commit changes to .DEPS.git. This file is maintained by an\n'
384 'automated system based on what\'s in DEPS and your changes will be\n'
386 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
387 'for more information')]
391 def _CheckNoBannedFunctions(input_api
, output_api
):
392 """Make sure that banned functions are not used."""
396 file_filter
= lambda f
: f
.LocalPath().endswith(('.mm', '.m', '.h'))
397 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
398 for line_num
, line
in f
.ChangedContents():
399 for func_name
, message
, error
in _BANNED_OBJC_FUNCTIONS
:
401 if func_name
[0:1] == '/':
402 regex
= func_name
[1:]
403 if input_api
.re
.search(regex
, line
):
405 elif func_name
in line
:
411 problems
.append(' %s:%d:' % (f
.LocalPath(), line_num
))
412 for message_line
in message
:
413 problems
.append(' %s' % message_line
)
415 file_filter
= lambda f
: f
.LocalPath().endswith(('.cc', '.mm', '.h'))
416 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
417 for line_num
, line
in f
.ChangedContents():
418 for func_name
, message
, error
, excluded_paths
in _BANNED_CPP_FUNCTIONS
:
419 def IsBlacklisted(affected_file
, blacklist
):
420 local_path
= affected_file
.LocalPath()
421 for item
in blacklist
:
422 if input_api
.re
.match(item
, local_path
):
425 if IsBlacklisted(f
, excluded_paths
):
428 if func_name
[0:1] == '/':
429 regex
= func_name
[1:]
430 if input_api
.re
.search(regex
, line
):
432 elif func_name
in line
:
438 problems
.append(' %s:%d:' % (f
.LocalPath(), line_num
))
439 for message_line
in message
:
440 problems
.append(' %s' % message_line
)
444 result
.append(output_api
.PresubmitPromptWarning(
445 'Banned functions were used.\n' + '\n'.join(warnings
)))
447 result
.append(output_api
.PresubmitError(
448 'Banned functions were used.\n' + '\n'.join(errors
)))
452 def _CheckNoPragmaOnce(input_api
, output_api
):
453 """Make sure that banned functions are not used."""
455 pattern
= input_api
.re
.compile(r
'^#pragma\s+once',
456 input_api
.re
.MULTILINE
)
457 for f
in input_api
.AffectedSourceFiles(input_api
.FilterSourceFile
):
458 if not f
.LocalPath().endswith('.h'):
460 contents
= input_api
.ReadFile(f
)
461 if pattern
.search(contents
):
465 return [output_api
.PresubmitError(
466 'Do not use #pragma once in header files.\n'
467 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
472 def _CheckNoTrinaryTrueFalse(input_api
, output_api
):
473 """Checks to make sure we don't introduce use of foo ? true : false."""
475 pattern
= input_api
.re
.compile(r
'\?\s*(true|false)\s*:\s*(true|false)')
476 for f
in input_api
.AffectedFiles():
477 if not f
.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
480 for line_num
, line
in f
.ChangedContents():
481 if pattern
.match(line
):
482 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
486 return [output_api
.PresubmitPromptWarning(
487 'Please consider avoiding the "? true : false" pattern if possible.\n' +
488 '\n'.join(problems
))]
491 def _CheckUnwantedDependencies(input_api
, output_api
):
492 """Runs checkdeps on #include statements added in this
493 change. Breaking - rules is an error, breaking ! rules is a
496 # We need to wait until we have an input_api object and use this
497 # roundabout construct to import checkdeps because this file is
498 # eval-ed and thus doesn't have __file__.
499 original_sys_path
= sys
.path
501 sys
.path
= sys
.path
+ [input_api
.os_path
.join(
502 input_api
.PresubmitLocalPath(), 'buildtools', 'checkdeps')]
504 from cpp_checker
import CppChecker
505 from rules
import Rule
507 # Restore sys.path to what it was before.
508 sys
.path
= original_sys_path
511 for f
in input_api
.AffectedFiles():
512 if not CppChecker
.IsCppFile(f
.LocalPath()):
515 changed_lines
= [line
for line_num
, line
in f
.ChangedContents()]
516 added_includes
.append([f
.LocalPath(), changed_lines
])
518 deps_checker
= checkdeps
.DepsChecker(input_api
.PresubmitLocalPath())
520 error_descriptions
= []
521 warning_descriptions
= []
522 for path
, rule_type
, rule_description
in deps_checker
.CheckAddedCppIncludes(
524 description_with_path
= '%s\n %s' % (path
, rule_description
)
525 if rule_type
== Rule
.DISALLOW
:
526 error_descriptions
.append(description_with_path
)
528 warning_descriptions
.append(description_with_path
)
531 if error_descriptions
:
532 results
.append(output_api
.PresubmitError(
533 'You added one or more #includes that violate checkdeps rules.',
535 if warning_descriptions
:
536 results
.append(output_api
.PresubmitPromptOrNotify(
537 'You added one or more #includes of files that are temporarily\n'
538 'allowed but being removed. Can you avoid introducing the\n'
539 '#include? See relevant DEPS file(s) for details and contacts.',
540 warning_descriptions
))
544 def _CheckFilePermissions(input_api
, output_api
):
545 """Check that all files have their permissions properly set."""
546 if input_api
.platform
== 'win32':
548 args
= [sys
.executable
, 'tools/checkperms/checkperms.py', '--root',
549 input_api
.change
.RepositoryRoot()]
550 for f
in input_api
.AffectedFiles():
551 args
+= ['--file', f
.LocalPath()]
552 checkperms
= input_api
.subprocess
.Popen(args
,
553 stdout
=input_api
.subprocess
.PIPE
)
554 errors
= checkperms
.communicate()[0].strip()
556 return [output_api
.PresubmitError('checkperms.py failed.',
557 errors
.splitlines())]
561 def _CheckNoAuraWindowPropertyHInHeaders(input_api
, output_api
):
562 """Makes sure we don't include ui/aura/window_property.h
565 pattern
= input_api
.re
.compile(r
'^#include\s*"ui/aura/window_property.h"')
567 for f
in input_api
.AffectedFiles():
568 if not f
.LocalPath().endswith('.h'):
570 for line_num
, line
in f
.ChangedContents():
571 if pattern
.match(line
):
572 errors
.append(' %s:%d' % (f
.LocalPath(), line_num
))
576 results
.append(output_api
.PresubmitError(
577 'Header files should not include ui/aura/window_property.h', errors
))
581 def _CheckIncludeOrderForScope(scope
, input_api
, file_path
, changed_linenums
):
582 """Checks that the lines in scope occur in the right order.
584 1. C system files in alphabetical order
585 2. C++ system files in alphabetical order
586 3. Project's .h files
589 c_system_include_pattern
= input_api
.re
.compile(r
'\s*#include <.*\.h>')
590 cpp_system_include_pattern
= input_api
.re
.compile(r
'\s*#include <.*>')
591 custom_include_pattern
= input_api
.re
.compile(r
'\s*#include ".*')
593 C_SYSTEM_INCLUDES
, CPP_SYSTEM_INCLUDES
, CUSTOM_INCLUDES
= range(3)
595 state
= C_SYSTEM_INCLUDES
598 previous_line_num
= 0
599 problem_linenums
= []
600 for line_num
, line
in scope
:
601 if c_system_include_pattern
.match(line
):
602 if state
!= C_SYSTEM_INCLUDES
:
603 problem_linenums
.append((line_num
, previous_line_num
))
604 elif previous_line
and previous_line
> line
:
605 problem_linenums
.append((line_num
, previous_line_num
))
606 elif cpp_system_include_pattern
.match(line
):
607 if state
== C_SYSTEM_INCLUDES
:
608 state
= CPP_SYSTEM_INCLUDES
609 elif state
== CUSTOM_INCLUDES
:
610 problem_linenums
.append((line_num
, previous_line_num
))
611 elif previous_line
and previous_line
> line
:
612 problem_linenums
.append((line_num
, previous_line_num
))
613 elif custom_include_pattern
.match(line
):
614 if state
!= CUSTOM_INCLUDES
:
615 state
= CUSTOM_INCLUDES
616 elif previous_line
and previous_line
> line
:
617 problem_linenums
.append((line_num
, previous_line_num
))
619 problem_linenums
.append(line_num
)
621 previous_line_num
= line_num
624 for (line_num
, previous_line_num
) in problem_linenums
:
625 if line_num
in changed_linenums
or previous_line_num
in changed_linenums
:
626 warnings
.append(' %s:%d' % (file_path
, line_num
))
630 def _CheckIncludeOrderInFile(input_api
, f
, changed_linenums
):
631 """Checks the #include order for the given file f."""
633 system_include_pattern
= input_api
.re
.compile(r
'\s*#include \<.*')
634 # Exclude the following includes from the check:
635 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
637 # 2) <atlbase.h>, "build/build_config.h"
638 excluded_include_pattern
= input_api
.re
.compile(
639 r
'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
640 custom_include_pattern
= input_api
.re
.compile(r
'\s*#include "(?P<FILE>.*)"')
641 # Match the final or penultimate token if it is xxxtest so we can ignore it
642 # when considering the special first include.
643 test_file_tag_pattern
= input_api
.re
.compile(
644 r
'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
645 if_pattern
= input_api
.re
.compile(
646 r
'\s*#\s*(if|elif|else|endif|define|undef).*')
647 # Some files need specialized order of includes; exclude such files from this
649 uncheckable_includes_pattern
= input_api
.re
.compile(
651 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
653 contents
= f
.NewContents()
657 # Handle the special first include. If the first include file is
658 # some/path/file.h, the corresponding including file can be some/path/file.cc,
659 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
660 # etc. It's also possible that no special first include exists.
661 # If the included file is some/path/file_platform.h the including file could
662 # also be some/path/file_xxxtest_platform.h.
663 including_file_base_name
= test_file_tag_pattern
.sub(
664 '', input_api
.os_path
.basename(f
.LocalPath()))
666 for line
in contents
:
668 if system_include_pattern
.match(line
):
669 # No special first include -> process the line again along with normal
673 match
= custom_include_pattern
.match(line
)
675 match_dict
= match
.groupdict()
676 header_basename
= test_file_tag_pattern
.sub(
677 '', input_api
.os_path
.basename(match_dict
['FILE'])).replace('.h', '')
679 if header_basename
not in including_file_base_name
:
680 # No special first include -> process the line again along with normal
685 # Split into scopes: Each region between #if and #endif is its own scope.
688 for line
in contents
[line_num
:]:
690 if uncheckable_includes_pattern
.match(line
):
692 if if_pattern
.match(line
):
693 scopes
.append(current_scope
)
695 elif ((system_include_pattern
.match(line
) or
696 custom_include_pattern
.match(line
)) and
697 not excluded_include_pattern
.match(line
)):
698 current_scope
.append((line_num
, line
))
699 scopes
.append(current_scope
)
702 warnings
.extend(_CheckIncludeOrderForScope(scope
, input_api
, f
.LocalPath(),
707 def _CheckIncludeOrder(input_api
, output_api
):
708 """Checks that the #include order is correct.
710 1. The corresponding header for source files.
711 2. C system files in alphabetical order
712 3. C++ system files in alphabetical order
713 4. Project's .h files in alphabetical order
715 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
716 these rules separately.
720 for f
in input_api
.AffectedFiles():
721 if f
.LocalPath().endswith(('.cc', '.h')):
722 changed_linenums
= set(line_num
for line_num
, _
in f
.ChangedContents())
723 warnings
.extend(_CheckIncludeOrderInFile(input_api
, f
, changed_linenums
))
727 results
.append(output_api
.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING
,
732 def _CheckForVersionControlConflictsInFile(input_api
, f
):
733 pattern
= input_api
.re
.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
735 for line_num
, line
in f
.ChangedContents():
736 if pattern
.match(line
):
737 errors
.append(' %s:%d %s' % (f
.LocalPath(), line_num
, line
))
741 def _CheckForVersionControlConflicts(input_api
, output_api
):
742 """Usually this is not intentional and will cause a compile failure."""
744 for f
in input_api
.AffectedFiles():
745 errors
.extend(_CheckForVersionControlConflictsInFile(input_api
, f
))
749 results
.append(output_api
.PresubmitError(
750 'Version control conflict markers found, please resolve.', errors
))
754 def _CheckHardcodedGoogleHostsInLowerLayers(input_api
, output_api
):
755 def FilterFile(affected_file
):
756 """Filter function for use with input_api.AffectedSourceFiles,
757 below. This filters out everything except non-test files from
758 top-level directories that generally speaking should not hard-code
759 service URLs (e.g. src/android_webview/, src/content/ and others).
761 return input_api
.FilterSourceFile(
763 white_list
=(r
'^(android_webview|base|content|net)[\\\/].*', ),
764 black_list
=(_EXCLUDED_PATHS
+
765 _TEST_CODE_EXCLUDED_PATHS
+
766 input_api
.DEFAULT_BLACK_LIST
))
768 base_pattern
= '"[^"]*google\.com[^"]*"'
769 comment_pattern
= input_api
.re
.compile('//.*%s' % base_pattern
)
770 pattern
= input_api
.re
.compile(base_pattern
)
771 problems
= [] # items are (filename, line_number, line)
772 for f
in input_api
.AffectedSourceFiles(FilterFile
):
773 for line_num
, line
in f
.ChangedContents():
774 if not comment_pattern
.search(line
) and pattern
.search(line
):
775 problems
.append((f
.LocalPath(), line_num
, line
))
778 return [output_api
.PresubmitPromptOrNotify(
779 'Most layers below src/chrome/ should not hardcode service URLs.\n'
780 'Are you sure this is correct?',
782 problem
[0], problem
[1], problem
[2]) for problem
in problems
])]
787 def _CheckNoAbbreviationInPngFileName(input_api
, output_api
):
788 """Makes sure there are no abbreviations in the name of PNG files.
790 pattern
= input_api
.re
.compile(r
'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
792 for f
in input_api
.AffectedFiles(include_deletes
=False):
793 if pattern
.match(f
.LocalPath()):
794 errors
.append(' %s' % f
.LocalPath())
798 results
.append(output_api
.PresubmitError(
799 'The name of PNG files should not have abbreviations. \n'
800 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
801 'Contact oshima@chromium.org if you have questions.', errors
))
805 def _FilesToCheckForIncomingDeps(re
, changed_lines
):
806 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
807 a set of DEPS entries that we should look up.
809 For a directory (rather than a specific filename) we fake a path to
810 a specific filename by adding /DEPS. This is chosen as a file that
811 will seldom or never be subject to per-file include_rules.
813 # We ignore deps entries on auto-generated directories.
814 AUTO_GENERATED_DIRS
= ['grit', 'jni']
816 # This pattern grabs the path without basename in the first
817 # parentheses, and the basename (if present) in the second. It
818 # relies on the simple heuristic that if there is a basename it will
819 # be a header file ending in ".h".
820 pattern
= re
.compile(
821 r
"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
823 for changed_line
in changed_lines
:
824 m
= pattern
.match(changed_line
)
827 if path
.split('/')[0] not in AUTO_GENERATED_DIRS
:
829 results
.add('%s%s' % (path
, m
.group(2)))
831 results
.add('%s/DEPS' % path
)
835 def _CheckAddedDepsHaveTargetApprovals(input_api
, output_api
):
836 """When a dependency prefixed with + is added to a DEPS file, we
837 want to make sure that the change is reviewed by an OWNER of the
838 target file or directory, to avoid layering violations from being
839 introduced. This check verifies that this happens.
841 changed_lines
= set()
842 for f
in input_api
.AffectedFiles():
843 filename
= input_api
.os_path
.basename(f
.LocalPath())
844 if filename
== 'DEPS':
845 changed_lines |
= set(line
.strip()
847 in f
.ChangedContents())
848 if not changed_lines
:
851 virtual_depended_on_files
= _FilesToCheckForIncomingDeps(input_api
.re
,
853 if not virtual_depended_on_files
:
856 if input_api
.is_committing
:
858 return [output_api
.PresubmitNotifyResult(
859 '--tbr was specified, skipping OWNERS check for DEPS additions')]
860 if not input_api
.change
.issue
:
861 return [output_api
.PresubmitError(
862 "DEPS approval by OWNERS check failed: this change has "
863 "no Rietveld issue number, so we can't check it for approvals.")]
864 output
= output_api
.PresubmitError
866 output
= output_api
.PresubmitNotifyResult
868 owners_db
= input_api
.owners_db
869 owner_email
, reviewers
= input_api
.canned_checks
._RietveldOwnerAndReviewers
(
871 owners_db
.email_regexp
,
872 approval_needed
=input_api
.is_committing
)
874 owner_email
= owner_email
or input_api
.change
.author_email
876 reviewers_plus_owner
= set(reviewers
)
878 reviewers_plus_owner
.add(owner_email
)
879 missing_files
= owners_db
.files_not_covered_by(virtual_depended_on_files
,
880 reviewers_plus_owner
)
882 # We strip the /DEPS part that was added by
883 # _FilesToCheckForIncomingDeps to fake a path to a file in a
886 start_deps
= path
.rfind('/DEPS')
888 return path
[:start_deps
]
891 unapproved_dependencies
= ["'+%s'," % StripDeps(path
)
892 for path
in missing_files
]
894 if unapproved_dependencies
:
896 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
897 '\n '.join(sorted(unapproved_dependencies
)))]
898 if not input_api
.is_committing
:
899 suggested_owners
= owners_db
.reviewers_for(missing_files
, owner_email
)
900 output_list
.append(output(
901 'Suggested missing target path OWNERS:\n %s' %
902 '\n '.join(suggested_owners
or [])))
908 def _CheckSpamLogging(input_api
, output_api
):
909 file_inclusion_pattern
= r
'.+%s' % _IMPLEMENTATION_EXTENSIONS
910 black_list
= (_EXCLUDED_PATHS
+
911 _TEST_CODE_EXCLUDED_PATHS
+
912 input_api
.DEFAULT_BLACK_LIST
+
913 (r
"^base[\\\/]logging\.h$",
914 r
"^base[\\\/]logging\.cc$",
915 r
"^cloud_print[\\\/]",
916 r
"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
917 r
"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
918 r
"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
919 r
"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
920 r
"startup_browser_creator\.cc$",
921 r
"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
922 r
"^extensions[\\\/]renderer[\\\/]logging_native_handler\.cc$",
923 r
"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
924 r
"gl_helper_benchmark\.cc$",
925 r
"^native_client_sdk[\\\/]",
926 r
"^remoting[\\\/]base[\\\/]logging\.h$",
927 r
"^remoting[\\\/]host[\\\/].*",
928 r
"^sandbox[\\\/]linux[\\\/].*",
930 r
"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
931 source_file_filter
= lambda x
: input_api
.FilterSourceFile(
932 x
, white_list
=(file_inclusion_pattern
,), black_list
=black_list
)
937 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
938 contents
= input_api
.ReadFile(f
, 'rb')
939 if re
.search(r
"\bD?LOG\s*\(\s*INFO\s*\)", contents
):
940 log_info
.append(f
.LocalPath())
941 elif re
.search(r
"\bD?LOG_IF\s*\(\s*INFO\s*,", contents
):
942 log_info
.append(f
.LocalPath())
944 if re
.search(r
"\bprintf\(", contents
):
945 printf
.append(f
.LocalPath())
946 elif re
.search(r
"\bfprintf\((stdout|stderr)", contents
):
947 printf
.append(f
.LocalPath())
950 return [output_api
.PresubmitError(
951 'These files spam the console log with LOG(INFO):',
954 return [output_api
.PresubmitError(
955 'These files spam the console log with printf/fprintf:',
960 def _CheckForAnonymousVariables(input_api
, output_api
):
961 """These types are all expected to hold locks while in scope and
962 so should never be anonymous (which causes them to be immediately
964 they_who_must_be_named
= [
968 'SkAutoAlphaRestore',
969 'SkAutoBitmapShaderInstall',
970 'SkAutoBlitterChoose',
971 'SkAutoBounderCommit',
973 'SkAutoCanvasRestore',
974 'SkAutoCommentBlock',
976 'SkAutoDisableDirectionCheck',
977 'SkAutoDisableOvalCheck',
984 'SkAutoMaskFreeImage',
985 'SkAutoMutexAcquire',
986 'SkAutoPathBoundsUpdate',
988 'SkAutoRasterClipValidate',
994 anonymous
= r
'(%s)\s*[({]' % '|'.join(they_who_must_be_named
)
995 # bad: base::AutoLock(lock.get());
996 # not bad: base::AutoLock lock(lock.get());
997 bad_pattern
= input_api
.re
.compile(anonymous
)
998 # good: new base::AutoLock(lock.get())
999 good_pattern
= input_api
.re
.compile(r
'\bnew\s*' + anonymous
)
1002 for f
in input_api
.AffectedFiles():
1003 if not f
.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
1005 for linenum
, line
in f
.ChangedContents():
1006 if bad_pattern
.search(line
) and not good_pattern
.search(line
):
1007 errors
.append('%s:%d' % (f
.LocalPath(), linenum
))
1010 return [output_api
.PresubmitError(
1011 'These lines create anonymous variables that need to be named:',
1016 def _CheckCygwinShell(input_api
, output_api
):
1017 source_file_filter
= lambda x
: input_api
.FilterSourceFile(
1018 x
, white_list
=(r
'.+\.(gyp|gypi)$',))
1021 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
1022 for linenum
, line
in f
.ChangedContents():
1023 if 'msvs_cygwin_shell' in line
:
1024 cygwin_shell
.append(f
.LocalPath())
1028 return [output_api
.PresubmitError(
1029 'These files should not use msvs_cygwin_shell (the default is 0):',
1030 items
=cygwin_shell
)]
1034 def _CheckUserActionUpdate(input_api
, output_api
):
1035 """Checks if any new user action has been added."""
1036 if any('actions.xml' == input_api
.os_path
.basename(f
) for f
in
1037 input_api
.LocalPaths()):
1038 # If actions.xml is already included in the changelist, the PRESUBMIT
1039 # for actions.xml will do a more complete presubmit check.
1042 file_filter
= lambda f
: f
.LocalPath().endswith(('.cc', '.mm'))
1043 action_re
= r
'[^a-zA-Z]UserMetricsAction\("([^"]*)'
1044 current_actions
= None
1045 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
1046 for line_num
, line
in f
.ChangedContents():
1047 match
= input_api
.re
.search(action_re
, line
)
1049 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1051 if not current_actions
:
1052 with
open('tools/metrics/actions/actions.xml') as actions_f
:
1053 current_actions
= actions_f
.read()
1054 # Search for the matched user action name in |current_actions|.
1055 for action_name
in match
.groups():
1056 action
= 'name="{0}"'.format(action_name
)
1057 if action
not in current_actions
:
1058 return [output_api
.PresubmitPromptWarning(
1059 'File %s line %d: %s is missing in '
1060 'tools/metrics/actions/actions.xml. Please run '
1061 'tools/metrics/actions/extract_actions.py to update.'
1062 % (f
.LocalPath(), line_num
, action_name
))]
1066 def _CheckJavaStyle(input_api
, output_api
):
1067 """Runs checkstyle on changed java files and returns errors if any exist."""
1068 original_sys_path
= sys
.path
1070 sys
.path
= sys
.path
+ [input_api
.os_path
.join(
1071 input_api
.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1074 # Restore sys.path to what it was before.
1075 sys
.path
= original_sys_path
1077 return checkstyle
.RunCheckstyle(
1078 input_api
, output_api
, 'tools/android/checkstyle/chromium-style-5.0.xml')
1083 ( "-webkit-box", "flex" ),
1084 ( "-webkit-inline-box", "inline-flex" ),
1085 ( "-webkit-flex", "flex" ),
1086 ( "-webkit-inline-flex", "inline-flex" ),
1087 ( "-webkit-min-content", "min-content" ),
1088 ( "-webkit-max-content", "max-content" ),
1091 ( "-webkit-background-clip", "background-clip" ),
1092 ( "-webkit-background-origin", "background-origin" ),
1093 ( "-webkit-background-size", "background-size" ),
1094 ( "-webkit-box-shadow", "box-shadow" ),
1097 ( "-webkit-gradient", "gradient" ),
1098 ( "-webkit-repeating-gradient", "repeating-gradient" ),
1099 ( "-webkit-linear-gradient", "linear-gradient" ),
1100 ( "-webkit-repeating-linear-gradient", "repeating-linear-gradient" ),
1101 ( "-webkit-radial-gradient", "radial-gradient" ),
1102 ( "-webkit-repeating-radial-gradient", "repeating-radial-gradient" ),
1105 def _CheckNoDeprecatedCSS(input_api
, output_api
):
1106 """ Make sure that we don't use deprecated CSS
1107 properties, functions or values. Our external
1108 documentation is ignored by the hooks as it
1109 needs to be consumed by WebKit. """
1111 file_inclusion_pattern
= (r
".+\.css$")
1112 black_list
= (_EXCLUDED_PATHS
+
1113 _TEST_CODE_EXCLUDED_PATHS
+
1114 input_api
.DEFAULT_BLACK_LIST
+
1115 (r
"^chrome/common/extensions/docs",
1117 r
"^native_client_sdk"))
1118 file_filter
= lambda f
: input_api
.FilterSourceFile(
1119 f
, white_list
=file_inclusion_pattern
, black_list
=black_list
)
1120 for fpath
in input_api
.AffectedFiles(file_filter
=file_filter
):
1121 for line_num
, line
in fpath
.ChangedContents():
1122 for (deprecated_value
, value
) in _DEPRECATED_CSS
:
1123 if input_api
.re
.search(deprecated_value
, line
):
1124 results
.append(output_api
.PresubmitError(
1125 "%s:%d: Use of deprecated CSS %s, use %s instead" %
1126 (fpath
.LocalPath(), line_num
, deprecated_value
, value
)))
1129 def _CommonChecks(input_api
, output_api
):
1130 """Checks common to both upload and commit."""
1132 results
.extend(input_api
.canned_checks
.PanProjectChecks(
1133 input_api
, output_api
,
1134 excluded_paths
=_EXCLUDED_PATHS
+ _TESTRUNNER_PATHS
))
1135 results
.extend(_CheckAuthorizedAuthor(input_api
, output_api
))
1137 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api
, output_api
))
1138 results
.extend(_CheckNoIOStreamInHeaders(input_api
, output_api
))
1139 results
.extend(_CheckNoUNIT_TESTInSourceFiles(input_api
, output_api
))
1140 results
.extend(_CheckNoNewWStrings(input_api
, output_api
))
1141 results
.extend(_CheckNoDEPSGIT(input_api
, output_api
))
1142 results
.extend(_CheckNoBannedFunctions(input_api
, output_api
))
1143 results
.extend(_CheckNoPragmaOnce(input_api
, output_api
))
1144 results
.extend(_CheckNoTrinaryTrueFalse(input_api
, output_api
))
1145 results
.extend(_CheckUnwantedDependencies(input_api
, output_api
))
1146 results
.extend(_CheckFilePermissions(input_api
, output_api
))
1147 results
.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api
, output_api
))
1148 results
.extend(_CheckIncludeOrder(input_api
, output_api
))
1149 results
.extend(_CheckForVersionControlConflicts(input_api
, output_api
))
1150 results
.extend(_CheckPatchFiles(input_api
, output_api
))
1151 results
.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api
, output_api
))
1152 results
.extend(_CheckNoAbbreviationInPngFileName(input_api
, output_api
))
1153 results
.extend(_CheckForInvalidOSMacros(input_api
, output_api
))
1154 results
.extend(_CheckAddedDepsHaveTargetApprovals(input_api
, output_api
))
1156 input_api
.canned_checks
.CheckChangeHasNoTabs(
1159 source_file_filter
=lambda x
: x
.LocalPath().endswith('.grd')))
1160 results
.extend(_CheckSpamLogging(input_api
, output_api
))
1161 results
.extend(_CheckForAnonymousVariables(input_api
, output_api
))
1162 results
.extend(_CheckCygwinShell(input_api
, output_api
))
1163 results
.extend(_CheckUserActionUpdate(input_api
, output_api
))
1164 results
.extend(_CheckNoDeprecatedCSS(input_api
, output_api
))
1166 if any('PRESUBMIT.py' == f
.LocalPath() for f
in input_api
.AffectedFiles()):
1167 results
.extend(input_api
.canned_checks
.RunUnitTestsInDirectory(
1168 input_api
, output_api
,
1169 input_api
.PresubmitLocalPath(),
1170 whitelist
=[r
'^PRESUBMIT_test\.py$']))
1174 def _CheckSubversionConfig(input_api
, output_api
):
1175 """Verifies the subversion config file is correctly setup.
1177 Checks that autoprops are enabled, returns an error otherwise.
1179 join
= input_api
.os_path
.join
1180 if input_api
.platform
== 'win32':
1181 appdata
= input_api
.environ
.get('APPDATA', '')
1183 return [output_api
.PresubmitError('%APPDATA% is not configured.')]
1184 path
= join(appdata
, 'Subversion', 'config')
1186 home
= input_api
.environ
.get('HOME', '')
1188 return [output_api
.PresubmitError('$HOME is not configured.')]
1189 path
= join(home
, '.subversion', 'config')
1192 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1193 'configure your subversion configuration file. This enables automatic\n'
1194 'properties to simplify the project maintenance.\n'
1195 'Pro-tip: just download and install\n'
1196 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
1199 lines
= open(path
, 'r').read().splitlines()
1200 # Make sure auto-props is enabled and check for 2 Chromium standard
1202 if (not '*.cc = svn:eol-style=LF' in lines
or
1203 not '*.pdf = svn:mime-type=application/pdf' in lines
or
1204 not 'enable-auto-props = yes' in lines
):
1206 output_api
.PresubmitNotifyResult(
1207 'It looks like you have not configured your subversion config '
1208 'file or it is not up-to-date.\n' + error_msg
)
1210 except (OSError, IOError):
1212 output_api
.PresubmitNotifyResult(
1213 'Can\'t find your subversion config file.\n' + error_msg
)
1218 def _CheckAuthorizedAuthor(input_api
, output_api
):
1219 """For non-googler/chromites committers, verify the author's email address is
1222 # TODO(maruel): Add it to input_api?
1225 author
= input_api
.change
.author_email
1227 input_api
.logging
.info('No author, skipping AUTHOR check')
1229 authors_path
= input_api
.os_path
.join(
1230 input_api
.PresubmitLocalPath(), 'AUTHORS')
1232 input_api
.re
.match(r
'[^#]+\s+\<(.+?)\>\s*$', line
)
1233 for line
in open(authors_path
))
1234 valid_authors
= [item
.group(1).lower() for item
in valid_authors
if item
]
1235 if not any(fnmatch
.fnmatch(author
.lower(), valid
) for valid
in valid_authors
):
1236 input_api
.logging
.info('Valid authors are %s', ', '.join(valid_authors
))
1237 return [output_api
.PresubmitPromptWarning(
1238 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1240 'http://www.chromium.org/developers/contributing-code and read the '
1242 'If you are a chromite, verify the contributor signed the CLA.') %
1247 def _CheckPatchFiles(input_api
, output_api
):
1248 problems
= [f
.LocalPath() for f
in input_api
.AffectedFiles()
1249 if f
.LocalPath().endswith(('.orig', '.rej'))]
1251 return [output_api
.PresubmitError(
1252 "Don't commit .rej and .orig files.", problems
)]
1257 def _DidYouMeanOSMacro(bad_macro
):
1259 return {'A': 'OS_ANDROID',
1269 'W': 'OS_WIN'}[bad_macro
[3].upper()]
1274 def _CheckForInvalidOSMacrosInFile(input_api
, f
):
1275 """Check for sensible looking, totally invalid OS macros."""
1276 preprocessor_statement
= input_api
.re
.compile(r
'^\s*#')
1277 os_macro
= input_api
.re
.compile(r
'defined\((OS_[^)]+)\)')
1279 for lnum
, line
in f
.ChangedContents():
1280 if preprocessor_statement
.search(line
):
1281 for match
in os_macro
.finditer(line
):
1282 if not match
.group(1) in _VALID_OS_MACROS
:
1283 good
= _DidYouMeanOSMacro(match
.group(1))
1284 did_you_mean
= ' (did you mean %s?)' % good
if good
else ''
1285 results
.append(' %s:%d %s%s' % (f
.LocalPath(),
1292 def _CheckForInvalidOSMacros(input_api
, output_api
):
1293 """Check all affected files for invalid OS macros."""
1295 for f
in input_api
.AffectedFiles():
1296 if not f
.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1297 bad_macros
.extend(_CheckForInvalidOSMacrosInFile(input_api
, f
))
1302 return [output_api
.PresubmitError(
1303 'Possibly invalid OS macro[s] found. Please fix your code\n'
1304 'or add your macro to src/PRESUBMIT.py.', bad_macros
)]
1307 def CheckChangeOnUpload(input_api
, output_api
):
1309 results
.extend(_CommonChecks(input_api
, output_api
))
1310 results
.extend(_CheckJavaStyle(input_api
, output_api
))
1314 def GetTryServerMasterForBot(bot
):
1315 """Returns the Try Server master for the given bot.
1317 Assumes that most Try Servers are on the tryserver.chromium master."""
1318 non_default_master_map
= {
1319 'linux_gpu': 'tryserver.chromium.gpu',
1320 'mac_gpu': 'tryserver.chromium.gpu',
1321 'win_gpu': 'tryserver.chromium.gpu',
1323 return non_default_master_map
.get(bot
, 'tryserver.chromium')
1326 def GetDefaultTryConfigs(bots
=None):
1327 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1329 To add tests to this list, they MUST be in the the corresponding master's
1330 gatekeeper config. For example, anything on master.chromium would be closed by
1331 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1333 If 'bots' is specified, will only return configurations for bots in that list.
1339 'cacheinvalidation_unittests',
1342 'content_browsertests',
1343 'content_unittests',
1346 'interactive_ui_tests',
1352 'printing_unittests',
1356 # Broken in release.
1358 #'webkit_unit_tests',
1361 builders_and_tests
= {
1362 # TODO(maruel): Figure out a way to run 'sizes' where people can
1363 # effectively update the perf expectation correctly. This requires a
1364 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1365 # incremental build. Reference:
1366 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1367 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1368 # of this step as a try job failure.
1369 'android_aosp': ['compile'],
1370 'android_chromium_gn_compile_rel': ['compile'],
1371 'android_clang_dbg': ['slave_steps'],
1372 'android_dbg': ['slave_steps'],
1373 'cros_x86': ['defaulttests'],
1374 'ios_dbg_simulator': [
1377 'content_unittests',
1384 'ios_rel_device': ['compile'],
1385 'linux_asan': ['compile'],
1386 'mac_asan': ['compile'],
1387 #TODO(stip): Change the name of this builder to reflect that it's release.
1388 'linux_gtk': standard_tests
,
1389 'linux_chromeos_asan': ['compile'],
1390 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
1391 'linux_chromium_chromeos_rel': ['defaulttests'],
1392 'linux_chromium_compile_dbg': ['defaulttests'],
1393 'linux_chromium_gn_rel': ['defaulttests'],
1394 'linux_chromium_rel': ['defaulttests'],
1395 'linux_chromium_clang_dbg': ['defaulttests'],
1396 'linux_gpu': ['defaulttests'],
1397 'linux_nacl_sdk_build': ['compile'],
1399 'telemetry_perf_unittests',
1400 'telemetry_unittests',
1402 'mac_chromium_compile_dbg': ['defaulttests'],
1403 'mac_chromium_rel': ['defaulttests'],
1404 'mac_gpu': ['defaulttests'],
1405 'mac_nacl_sdk_build': ['compile'],
1407 'telemetry_perf_unittests',
1408 'telemetry_unittests',
1411 'win_chromium_compile_dbg': ['defaulttests'],
1412 'win_chromium_dbg': ['defaulttests'],
1413 'win_chromium_rel': ['defaulttests'],
1414 'win_chromium_x64_rel': ['defaulttests'],
1415 'win_gpu': ['defaulttests'],
1416 'win_nacl_sdk_build': ['compile'],
1417 'win_rel': standard_tests
+ [
1418 'app_list_unittests',
1422 'chrome_elf_unittests',
1423 'chromedriver_unittests',
1424 'components_unittests',
1425 'compositor_unittests',
1428 'google_apis_unittests',
1429 'installer_util_unittests',
1430 'mini_installer_test',
1432 'remoting_unittests',
1433 'sync_integration_tests',
1434 'telemetry_perf_unittests',
1435 'telemetry_unittests',
1443 swarm_enabled_builders
= (
1444 # http://crbug.com/354263
1450 swarm_enabled_tests
= (
1453 'interactive_ui_tests',
1458 for bot
in builders_and_tests
:
1459 if bot
in swarm_enabled_builders
:
1460 builders_and_tests
[bot
] = [x
+ '_swarm' if x
in swarm_enabled_tests
else x
1461 for x
in builders_and_tests
[bot
]]
1464 filtered_builders_and_tests
= dict((bot
, set(builders_and_tests
[bot
]))
1467 filtered_builders_and_tests
= dict(
1469 for bot
, tests
in builders_and_tests
.iteritems())
1471 # Build up the mapping from tryserver master to bot/test.
1473 for bot
, tests
in filtered_builders_and_tests
.iteritems():
1474 out
.setdefault(GetTryServerMasterForBot(bot
), {})[bot
] = tests
1478 def CheckChangeOnCommit(input_api
, output_api
):
1480 results
.extend(_CommonChecks(input_api
, output_api
))
1481 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1482 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1483 # input_api, output_api, sources))
1484 # Make sure the tree is 'open'.
1485 results
.extend(input_api
.canned_checks
.CheckTreeIsOpen(
1488 json_url
='http://chromium-status.appspot.com/current?format=json'))
1490 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
1491 input_api
, output_api
))
1492 results
.extend(input_api
.canned_checks
.CheckChangeHasDescription(
1493 input_api
, output_api
))
1494 results
.extend(_CheckSubversionConfig(input_api
, output_api
))
1498 def GetPreferredTryMasters(project
, change
):
1499 files
= change
.LocalPaths()
1501 if not files
or all(re
.search(r
'[\\/]OWNERS$', f
) for f
in files
):
1504 if all(re
.search('\.(m|mm)$|(^|[/_])mac[/_.]', f
) for f
in files
):
1505 return GetDefaultTryConfigs([
1506 'mac_chromium_compile_dbg',
1509 if all(re
.search('(^|[/_])win[/_.]', f
) for f
in files
):
1510 return GetDefaultTryConfigs(['win_chromium_dbg', 'win_chromium_rel'])
1511 if all(re
.search('(^|[/_])android[/_.]', f
) for f
in files
):
1512 return GetDefaultTryConfigs([
1514 'android_clang_dbg',
1517 if all(re
.search('[/_]ios[/_.]', f
) for f
in files
):
1518 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
1521 'android_chromium_gn_compile_rel',
1522 'android_clang_dbg',
1524 'ios_dbg_simulator',
1526 'linux_chromium_chromeos_rel',
1527 'linux_chromium_clang_dbg',
1528 'linux_chromium_gn_rel',
1529 'linux_chromium_rel',
1531 'mac_chromium_compile_dbg',
1534 'win_chromium_compile_dbg',
1536 'win_chromium_x64_rel',
1540 # Match things like path/aura/file.cc and path/file_aura.cc.
1541 # Same for chromeos.
1542 if any(re
.search('[/_](aura|chromeos)', f
) for f
in files
):
1544 'linux_chromeos_asan',
1545 'linux_chromium_chromeos_clang_dbg'
1548 # If there are gyp changes to base, build, or chromeos, run a full cros build
1549 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1550 # files have a much higher chance of breaking the cros build, which is
1551 # differnt from the linux_chromeos build that most chrome developers test
1553 if any(re
.search('^(base|build|chromeos).*\.gypi?$', f
) for f
in files
):
1554 builders
.extend(['cros_x86'])
1556 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1557 # unless they're .gyp(i) files as changes to those files can break the gyp
1559 if (not all(re
.search('^chrome', f
) for f
in files
) or
1560 any(re
.search('\.gypi?$', f
) for f
in files
)):
1561 builders
.extend(['android_aosp'])
1563 return GetDefaultTryConfigs(builders
)