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.
19 r
"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
20 r
"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
21 r
"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
27 r
"^webkit[\\\/]compositor_bindings[\\\/].*",
28 r
".+[\\\/]pnacl_shim\.c$",
32 _TEST_ONLY_WARNING
= (
33 'You might be calling functions intended only for testing from\n'
34 'production code. It is OK to ignore this warning if you know what\n'
35 'you are doing, as the heuristics used to detect the situation are\n'
36 'not perfect. The commit queue will not block on this warning.\n'
37 'Email joi@chromium.org if you have questions.')
40 _INCLUDE_ORDER_WARNING
= (
41 'Your #include order seems to be broken. Send mail to\n'
42 'marja@chromium.org if this is not the case.')
45 _BANNED_OBJC_FUNCTIONS
= (
49 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
50 'prohibited. Please use CrTrackingArea instead.',
51 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
58 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
60 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
65 'convertPointFromBase:',
67 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
68 'Please use |convertPoint:(point) fromView:nil| instead.',
69 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
74 'convertPointToBase:',
76 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
77 'Please use |convertPoint:(point) toView:nil| instead.',
78 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
83 'convertRectFromBase:',
85 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
86 'Please use |convertRect:(point) fromView:nil| instead.',
87 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
94 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
95 'Please use |convertRect:(point) toView:nil| instead.',
96 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
101 'convertSizeFromBase:',
103 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
104 'Please use |convertSize:(point) fromView:nil| instead.',
105 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
110 'convertSizeToBase:',
112 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
113 'Please use |convertSize:(point) toView:nil| instead.',
114 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
121 _BANNED_CPP_FUNCTIONS
= (
122 # Make sure that gtest's FRIEND_TEST() macro is not used; the
123 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
124 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
128 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
129 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
137 'New code should not use ScopedAllowIO. Post a task to the blocking',
138 'pool or the FILE thread instead.',
142 r
"^content[\\\/]shell[\\\/]shell_browser_main\.cc$",
146 'FilePathWatcher::Delegate',
148 'New code should not use FilePathWatcher::Delegate. Use the callback',
149 'interface instead.',
155 'browser::FindAnyBrowser',
157 'This function is deprecated and we\'re working on removing it. Pass',
158 'more context to get a Browser*, like a WebContents, window, or session',
159 'id. Talk to robertshield@ for more information.',
165 'browser::FindOrCreateTabbedBrowser',
167 'This function is deprecated and we\'re working on removing it. Pass',
168 'more context to get a Browser*, like a WebContents, window, or session',
169 'id. Talk to robertshield@ for more information.',
177 'This function is deprecated and we\'re working on removing it. Rename',
187 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api
, output_api
):
188 """Attempts to prevent use of functions intended only for testing in
189 non-testing code. For now this is just a best-effort implementation
190 that ignores header files and may have some false positives. A
191 better implementation would probably need a proper C++ parser.
193 # We only scan .cc files and the like, as the declaration of
194 # for-testing functions in header files are hard to distinguish from
195 # calls to such functions without a proper C++ parser.
196 platform_specifiers
= r
'(_(android|chromeos|gtk|mac|posix|win))?'
197 source_extensions
= r
'\.(cc|cpp|cxx|mm)$'
198 file_inclusion_pattern
= r
'.+%s' % source_extensions
199 file_exclusion_patterns
= (
200 r
'.*[/\\](fake_|test_|mock_).+%s' % source_extensions
,
201 r
'.+_test_(base|support|util)%s' % source_extensions
,
202 r
'.+_(api|browser|perf|unit|ui)?test%s%s' % (platform_specifiers
,
204 r
'.+profile_sync_service_harness%s' % source_extensions
,
206 path_exclusion_patterns
= (
207 r
'.*[/\\](test|tool(s)?)[/\\].*',
208 # At request of folks maintaining this folder.
209 r
'chrome[/\\]browser[/\\]automation[/\\].*',
212 base_function_pattern
= r
'ForTest(ing)?|for_test(ing)?'
213 inclusion_pattern
= input_api
.re
.compile(r
'(%s)\s*\(' % base_function_pattern
)
214 exclusion_pattern
= input_api
.re
.compile(
215 r
'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
216 base_function_pattern
, base_function_pattern
))
218 def FilterFile(affected_file
):
219 black_list
= (file_exclusion_patterns
+ path_exclusion_patterns
+
220 _EXCLUDED_PATHS
+ input_api
.DEFAULT_BLACK_LIST
)
221 return input_api
.FilterSourceFile(
223 white_list
=(file_inclusion_pattern
, ),
224 black_list
=black_list
)
227 for f
in input_api
.AffectedSourceFiles(FilterFile
):
228 local_path
= f
.LocalPath()
229 lines
= input_api
.ReadFile(f
).splitlines()
232 if (inclusion_pattern
.search(line
) and
233 not exclusion_pattern
.search(line
)):
235 '%s:%d\n %s' % (local_path
, line_number
, line
.strip()))
239 if not input_api
.is_committing
:
240 return [output_api
.PresubmitPromptWarning(_TEST_ONLY_WARNING
, problems
)]
242 # We don't warn on commit, to avoid stopping commits going through CQ.
243 return [output_api
.PresubmitNotifyResult(_TEST_ONLY_WARNING
, problems
)]
248 def _CheckNoIOStreamInHeaders(input_api
, output_api
):
249 """Checks to make sure no .h files include <iostream>."""
251 pattern
= input_api
.re
.compile(r
'^#include\s*<iostream>',
252 input_api
.re
.MULTILINE
)
253 for f
in input_api
.AffectedSourceFiles(input_api
.FilterSourceFile
):
254 if not f
.LocalPath().endswith('.h'):
256 contents
= input_api
.ReadFile(f
)
257 if pattern
.search(contents
):
261 return [ output_api
.PresubmitError(
262 'Do not #include <iostream> in header files, since it inserts static '
263 'initialization into every file including the header. Instead, '
264 '#include <ostream>. See http://crbug.com/94794',
269 def _CheckNoUNIT_TESTInSourceFiles(input_api
, output_api
):
270 """Checks to make sure no source files use UNIT_TEST"""
272 for f
in input_api
.AffectedFiles():
273 if (not f
.LocalPath().endswith(('.cc', '.mm'))):
276 for line_num
, line
in f
.ChangedContents():
277 if 'UNIT_TEST' in line
:
278 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
282 return [output_api
.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
283 '\n'.join(problems
))]
286 def _CheckNoNewWStrings(input_api
, output_api
):
287 """Checks to make sure we don't introduce use of wstrings."""
289 for f
in input_api
.AffectedFiles():
290 if (not f
.LocalPath().endswith(('.cc', '.h')) or
291 f
.LocalPath().endswith('test.cc')):
295 for line_num
, line
in f
.ChangedContents():
296 if 'presubmit: allow wstring' in line
:
298 elif not allowWString
and 'wstring' in line
:
299 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
306 return [output_api
.PresubmitPromptWarning('New code should not use wstrings.'
307 ' If you are calling a cross-platform API that accepts a wstring, '
309 '\n'.join(problems
))]
312 def _CheckNoDEPSGIT(input_api
, output_api
):
313 """Make sure .DEPS.git is never modified manually."""
314 if any(f
.LocalPath().endswith('.DEPS.git') for f
in
315 input_api
.AffectedFiles()):
316 return [output_api
.PresubmitError(
317 'Never commit changes to .DEPS.git. This file is maintained by an\n'
318 'automated system based on what\'s in DEPS and your changes will be\n'
320 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
321 'for more information')]
325 def _CheckNoBannedFunctions(input_api
, output_api
):
326 """Make sure that banned functions are not used."""
330 file_filter
= lambda f
: f
.LocalPath().endswith(('.mm', '.m', '.h'))
331 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
332 for line_num
, line
in f
.ChangedContents():
333 for func_name
, message
, error
in _BANNED_OBJC_FUNCTIONS
:
334 if func_name
in line
:
338 problems
.append(' %s:%d:' % (f
.LocalPath(), line_num
))
339 for message_line
in message
:
340 problems
.append(' %s' % message_line
)
342 file_filter
= lambda f
: f
.LocalPath().endswith(('.cc', '.mm', '.h'))
343 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
344 for line_num
, line
in f
.ChangedContents():
345 for func_name
, message
, error
, excluded_paths
in _BANNED_CPP_FUNCTIONS
:
346 def IsBlacklisted(affected_file
, blacklist
):
347 local_path
= affected_file
.LocalPath()
348 for item
in blacklist
:
349 if input_api
.re
.match(item
, local_path
):
352 if IsBlacklisted(f
, excluded_paths
):
354 if func_name
in line
:
358 problems
.append(' %s:%d:' % (f
.LocalPath(), line_num
))
359 for message_line
in message
:
360 problems
.append(' %s' % message_line
)
364 result
.append(output_api
.PresubmitPromptWarning(
365 'Banned functions were used.\n' + '\n'.join(warnings
)))
367 result
.append(output_api
.PresubmitError(
368 'Banned functions were used.\n' + '\n'.join(errors
)))
372 def _CheckNoPragmaOnce(input_api
, output_api
):
373 """Make sure that banned functions are not used."""
375 pattern
= input_api
.re
.compile(r
'^#pragma\s+once',
376 input_api
.re
.MULTILINE
)
377 for f
in input_api
.AffectedSourceFiles(input_api
.FilterSourceFile
):
378 if not f
.LocalPath().endswith('.h'):
380 contents
= input_api
.ReadFile(f
)
381 if pattern
.search(contents
):
385 return [output_api
.PresubmitError(
386 'Do not use #pragma once in header files.\n'
387 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
392 def _CheckNoTrinaryTrueFalse(input_api
, output_api
):
393 """Checks to make sure we don't introduce use of foo ? true : false."""
395 pattern
= input_api
.re
.compile(r
'\?\s*(true|false)\s*:\s*(true|false)')
396 for f
in input_api
.AffectedFiles():
397 if not f
.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
400 for line_num
, line
in f
.ChangedContents():
401 if pattern
.match(line
):
402 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
406 return [output_api
.PresubmitPromptWarning(
407 'Please consider avoiding the "? true : false" pattern if possible.\n' +
408 '\n'.join(problems
))]
411 def _CheckUnwantedDependencies(input_api
, output_api
):
412 """Runs checkdeps on #include statements added in this
413 change. Breaking - rules is an error, breaking ! rules is a
416 # We need to wait until we have an input_api object and use this
417 # roundabout construct to import checkdeps because this file is
418 # eval-ed and thus doesn't have __file__.
419 original_sys_path
= sys
.path
421 sys
.path
= sys
.path
+ [input_api
.os_path
.join(
422 input_api
.PresubmitLocalPath(), 'tools', 'checkdeps')]
424 from cpp_checker
import CppChecker
425 from rules
import Rule
427 # Restore sys.path to what it was before.
428 sys
.path
= original_sys_path
431 for f
in input_api
.AffectedFiles():
432 if not CppChecker
.IsCppFile(f
.LocalPath()):
435 changed_lines
= [line
for line_num
, line
in f
.ChangedContents()]
436 added_includes
.append([f
.LocalPath(), changed_lines
])
438 deps_checker
= checkdeps
.DepsChecker()
440 error_descriptions
= []
441 warning_descriptions
= []
442 for path
, rule_type
, rule_description
in deps_checker
.CheckAddedCppIncludes(
444 description_with_path
= '%s\n %s' % (path
, rule_description
)
445 if rule_type
== Rule
.DISALLOW
:
446 error_descriptions
.append(description_with_path
)
448 warning_descriptions
.append(description_with_path
)
451 if error_descriptions
:
452 results
.append(output_api
.PresubmitError(
453 'You added one or more #includes that violate checkdeps rules.',
455 if warning_descriptions
:
456 if not input_api
.is_committing
:
457 warning_factory
= output_api
.PresubmitPromptWarning
459 # We don't want to block use of the CQ when there is a warning
460 # of this kind, so we only show a message when committing.
461 warning_factory
= output_api
.PresubmitNotifyResult
462 results
.append(warning_factory(
463 'You added one or more #includes of files that are temporarily\n'
464 'allowed but being removed. Can you avoid introducing the\n'
465 '#include? See relevant DEPS file(s) for details and contacts.',
466 warning_descriptions
))
470 def _CheckFilePermissions(input_api
, output_api
):
471 """Check that all files have their permissions properly set."""
472 args
= [sys
.executable
, 'tools/checkperms/checkperms.py', '--root',
473 input_api
.change
.RepositoryRoot()]
474 for f
in input_api
.AffectedFiles():
475 args
+= ['--file', f
.LocalPath()]
477 (errors
, stderrdata
) = subprocess
.Popen(args
).communicate()
481 results
.append(output_api
.PresubmitError('checkperms.py failed.',
486 def _CheckNoAuraWindowPropertyHInHeaders(input_api
, output_api
):
487 """Makes sure we don't include ui/aura/window_property.h
490 pattern
= input_api
.re
.compile(r
'^#include\s*"ui/aura/window_property.h"')
492 for f
in input_api
.AffectedFiles():
493 if not f
.LocalPath().endswith('.h'):
495 for line_num
, line
in f
.ChangedContents():
496 if pattern
.match(line
):
497 errors
.append(' %s:%d' % (f
.LocalPath(), line_num
))
501 results
.append(output_api
.PresubmitError(
502 'Header files should not include ui/aura/window_property.h', errors
))
506 def _CheckIncludeOrderForScope(scope
, input_api
, file_path
, changed_linenums
):
507 """Checks that the lines in scope occur in the right order.
509 1. C system files in alphabetical order
510 2. C++ system files in alphabetical order
511 3. Project's .h files
514 c_system_include_pattern
= input_api
.re
.compile(r
'\s*#include <.*\.h>')
515 cpp_system_include_pattern
= input_api
.re
.compile(r
'\s*#include <.*>')
516 custom_include_pattern
= input_api
.re
.compile(r
'\s*#include ".*')
518 C_SYSTEM_INCLUDES
, CPP_SYSTEM_INCLUDES
, CUSTOM_INCLUDES
= range(3)
520 state
= C_SYSTEM_INCLUDES
523 previous_line_num
= 0
524 problem_linenums
= []
525 for line_num
, line
in scope
:
526 if c_system_include_pattern
.match(line
):
527 if state
!= C_SYSTEM_INCLUDES
:
528 problem_linenums
.append((line_num
, previous_line_num
))
529 elif previous_line
and previous_line
> line
:
530 problem_linenums
.append((line_num
, previous_line_num
))
531 elif cpp_system_include_pattern
.match(line
):
532 if state
== C_SYSTEM_INCLUDES
:
533 state
= CPP_SYSTEM_INCLUDES
534 elif state
== CUSTOM_INCLUDES
:
535 problem_linenums
.append((line_num
, previous_line_num
))
536 elif previous_line
and previous_line
> line
:
537 problem_linenums
.append((line_num
, previous_line_num
))
538 elif custom_include_pattern
.match(line
):
539 if state
!= CUSTOM_INCLUDES
:
540 state
= CUSTOM_INCLUDES
541 elif previous_line
and previous_line
> line
:
542 problem_linenums
.append((line_num
, previous_line_num
))
544 problem_linenums
.append(line_num
)
546 previous_line_num
= line_num
549 for (line_num
, previous_line_num
) in problem_linenums
:
550 if line_num
in changed_linenums
or previous_line_num
in changed_linenums
:
551 warnings
.append(' %s:%d' % (file_path
, line_num
))
555 def _CheckIncludeOrderInFile(input_api
, f
, is_source
, changed_linenums
):
556 """Checks the #include order for the given file f."""
558 system_include_pattern
= input_api
.re
.compile(r
'\s*#include \<.*')
559 # Exclude #include <.../...> includes from the check; e.g., <sys/...> includes
560 # often need to appear in a specific order.
561 excluded_include_pattern
= input_api
.re
.compile(r
'\s*#include \<.*/.*')
562 custom_include_pattern
= input_api
.re
.compile(r
'\s*#include "(?P<FILE>.*)"')
563 if_pattern
= input_api
.re
.compile(r
'\s*#\s*(if|elif|else|endif).*')
565 contents
= f
.NewContents()
569 # Handle the special first include for source files. If the header file is
570 # some/path/file.h, the corresponding source file can be some/path/file.cc,
571 # some/other/path/file.cc, some/path/file_platform.cc etc. It's also possible
572 # that no special first include exists.
574 for line
in contents
:
576 if system_include_pattern
.match(line
):
577 # No special first include -> process the line again along with normal
581 match
= custom_include_pattern
.match(line
)
583 match_dict
= match
.groupdict()
584 header_basename
= input_api
.os_path
.basename(
585 match_dict
['FILE']).replace('.h', '')
586 if header_basename
not in input_api
.os_path
.basename(f
.LocalPath()):
587 # No special first include -> process the line again along with normal
592 # Split into scopes: Each region between #if and #endif is its own scope.
595 for line
in contents
[line_num
:]:
597 if if_pattern
.match(line
):
598 scopes
.append(current_scope
)
600 elif ((system_include_pattern
.match(line
) or
601 custom_include_pattern
.match(line
)) and
602 not excluded_include_pattern
.match(line
)):
603 current_scope
.append((line_num
, line
))
604 scopes
.append(current_scope
)
607 warnings
.extend(_CheckIncludeOrderForScope(scope
, input_api
, f
.LocalPath(),
612 def _CheckIncludeOrder(input_api
, output_api
):
613 """Checks that the #include order is correct.
615 1. The corresponding header for source files.
616 2. C system files in alphabetical order
617 3. C++ system files in alphabetical order
618 4. Project's .h files in alphabetical order
620 Each region between #if and #endif follows these rules separately.
624 for f
in input_api
.AffectedFiles():
625 changed_linenums
= set([line_num
for line_num
, _
in f
.ChangedContents()])
626 if f
.LocalPath().endswith('.cc'):
627 warnings
.extend(_CheckIncludeOrderInFile(input_api
, f
, True,
629 elif f
.LocalPath().endswith('.h'):
630 warnings
.extend(_CheckIncludeOrderInFile(input_api
, f
, False,
635 results
.append(output_api
.PresubmitPromptWarning(_INCLUDE_ORDER_WARNING
,
640 def _CheckForVersionControlConflictsInFile(input_api
, f
):
641 pattern
= input_api
.re
.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
643 for line_num
, line
in f
.ChangedContents():
644 if pattern
.match(line
):
645 errors
.append(' %s:%d %s' % (f
.LocalPath(), line_num
, line
))
649 def _CheckForVersionControlConflicts(input_api
, output_api
):
650 """Usually this is not intentional and will cause a compile failure."""
652 for f
in input_api
.AffectedFiles():
653 errors
.extend(_CheckForVersionControlConflictsInFile(input_api
, f
))
657 results
.append(output_api
.PresubmitError(
658 'Version control conflict markers found, please resolve.', errors
))
662 def _CommonChecks(input_api
, output_api
):
663 """Checks common to both upload and commit."""
665 results
.extend(input_api
.canned_checks
.PanProjectChecks(
666 input_api
, output_api
, excluded_paths
=_EXCLUDED_PATHS
))
667 results
.extend(_CheckAuthorizedAuthor(input_api
, output_api
))
669 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api
, output_api
))
670 results
.extend(_CheckNoIOStreamInHeaders(input_api
, output_api
))
671 results
.extend(_CheckNoUNIT_TESTInSourceFiles(input_api
, output_api
))
672 results
.extend(_CheckNoNewWStrings(input_api
, output_api
))
673 results
.extend(_CheckNoDEPSGIT(input_api
, output_api
))
674 results
.extend(_CheckNoBannedFunctions(input_api
, output_api
))
675 results
.extend(_CheckNoPragmaOnce(input_api
, output_api
))
676 results
.extend(_CheckNoTrinaryTrueFalse(input_api
, output_api
))
677 results
.extend(_CheckUnwantedDependencies(input_api
, output_api
))
678 results
.extend(_CheckFilePermissions(input_api
, output_api
))
679 results
.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api
, output_api
))
680 results
.extend(_CheckIncludeOrder(input_api
, output_api
))
681 results
.extend(_CheckForVersionControlConflicts(input_api
, output_api
))
683 if any('PRESUBMIT.py' == f
.LocalPath() for f
in input_api
.AffectedFiles()):
684 results
.extend(input_api
.canned_checks
.RunUnitTestsInDirectory(
685 input_api
, output_api
,
686 input_api
.PresubmitLocalPath(),
687 whitelist
=[r
'.+_test\.py$']))
691 def _CheckSubversionConfig(input_api
, output_api
):
692 """Verifies the subversion config file is correctly setup.
694 Checks that autoprops are enabled, returns an error otherwise.
696 join
= input_api
.os_path
.join
697 if input_api
.platform
== 'win32':
698 appdata
= input_api
.environ
.get('APPDATA', '')
700 return [output_api
.PresubmitError('%APPDATA% is not configured.')]
701 path
= join(appdata
, 'Subversion', 'config')
703 home
= input_api
.environ
.get('HOME', '')
705 return [output_api
.PresubmitError('$HOME is not configured.')]
706 path
= join(home
, '.subversion', 'config')
709 'Please look at http://dev.chromium.org/developers/coding-style to\n'
710 'configure your subversion configuration file. This enables automatic\n'
711 'properties to simplify the project maintenance.\n'
712 'Pro-tip: just download and install\n'
713 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
716 lines
= open(path
, 'r').read().splitlines()
717 # Make sure auto-props is enabled and check for 2 Chromium standard
719 if (not '*.cc = svn:eol-style=LF' in lines
or
720 not '*.pdf = svn:mime-type=application/pdf' in lines
or
721 not 'enable-auto-props = yes' in lines
):
723 output_api
.PresubmitNotifyResult(
724 'It looks like you have not configured your subversion config '
725 'file or it is not up-to-date.\n' + error_msg
)
727 except (OSError, IOError):
729 output_api
.PresubmitNotifyResult(
730 'Can\'t find your subversion config file.\n' + error_msg
)
735 def _CheckAuthorizedAuthor(input_api
, output_api
):
736 """For non-googler/chromites committers, verify the author's email address is
739 # TODO(maruel): Add it to input_api?
742 author
= input_api
.change
.author_email
744 input_api
.logging
.info('No author, skipping AUTHOR check')
746 authors_path
= input_api
.os_path
.join(
747 input_api
.PresubmitLocalPath(), 'AUTHORS')
749 input_api
.re
.match(r
'[^#]+\s+\<(.+?)\>\s*$', line
)
750 for line
in open(authors_path
))
751 valid_authors
= [item
.group(1).lower() for item
in valid_authors
if item
]
752 if input_api
.verbose
:
753 print 'Valid authors are %s' % ', '.join(valid_authors
)
754 if not any(fnmatch
.fnmatch(author
.lower(), valid
) for valid
in valid_authors
):
755 return [output_api
.PresubmitPromptWarning(
756 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
758 'http://www.chromium.org/developers/contributing-code and read the '
760 'If you are a chromite, verify the contributor signed the CLA.') %
765 def CheckChangeOnUpload(input_api
, output_api
):
767 results
.extend(_CommonChecks(input_api
, output_api
))
771 def CheckChangeOnCommit(input_api
, output_api
):
773 results
.extend(_CommonChecks(input_api
, output_api
))
774 # TODO(thestig) temporarily disabled, doesn't work in third_party/
775 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
776 # input_api, output_api, sources))
777 # Make sure the tree is 'open'.
778 results
.extend(input_api
.canned_checks
.CheckTreeIsOpen(
781 json_url
='http://chromium-status.appspot.com/current?format=json'))
782 results
.extend(input_api
.canned_checks
.CheckRietveldTryJobExecution(input_api
,
783 output_api
, 'http://codereview.chromium.org',
784 ('win_rel', 'linux_rel', 'mac_rel, win:compile'),
785 'tryserver@chromium.org'))
787 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
788 input_api
, output_api
))
789 results
.extend(input_api
.canned_checks
.CheckChangeHasDescription(
790 input_api
, output_api
))
791 results
.extend(_CheckSubversionConfig(input_api
, output_api
))
795 def GetPreferredTrySlaves(project
, change
):
796 files
= change
.LocalPaths()
801 if all(re
.search('\.(m|mm)$|(^|[/_])mac[/_.]', f
) for f
in files
):
802 return ['mac_rel', 'mac_asan']
803 if all(re
.search('(^|[/_])win[/_.]', f
) for f
in files
):
805 if all(re
.search('(^|[/_])android[/_.]', f
) for f
in files
):
806 return ['android_dbg', 'android_clang_dbg']
807 if all(re
.search('^native_client_sdk', f
) for f
in files
):
808 return ['linux_nacl_sdk', 'win_nacl_sdk', 'mac_nacl_sdk']
809 if all(re
.search('[/_]ios[/_.]', f
) for f
in files
):
810 return ['ios_rel_device', 'ios_dbg_simulator']
820 'linux_clang:compile',
828 # Match things like path/aura/file.cc and path/file_aura.cc.
830 if any(re
.search('[/_](aura|chromeos)', f
) for f
in files
):
831 trybots
+= ['linux_chromeos_clang:compile', 'linux_chromeos_asan']