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
"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
22 r
"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
27 r
".+[\\\/]pnacl_shim\.c$",
30 # Fragment of a regular expression that matches file name suffixes
31 # used to indicate different platforms.
32 _PLATFORM_SPECIFIERS
= r
'(_(android|chromeos|gtk|mac|posix|win))?'
34 # Fragment of a regular expression that matches C++ and Objective-C++
35 # implementation files.
36 _IMPLEMENTATION_EXTENSIONS
= r
'\.(cc|cpp|cxx|mm)$'
38 # Regular expression that matches code only used for test binaries
40 _TEST_CODE_EXCLUDED_PATHS
= (
41 r
'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS
,
42 r
'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS
,
43 r
'.+_(api|browser|perf|unit|ui)?test%s%s' % (_PLATFORM_SPECIFIERS
,
44 _IMPLEMENTATION_EXTENSIONS
),
45 r
'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS
,
46 r
'.*[/\\](test|tool(s)?)[/\\].*',
47 # At request of folks maintaining this folder.
48 r
'chrome[/\\]browser[/\\]automation[/\\].*',
51 _TEST_ONLY_WARNING
= (
52 'You might be calling functions intended only for testing from\n'
53 'production code. It is OK to ignore this warning if you know what\n'
54 'you are doing, as the heuristics used to detect the situation are\n'
55 'not perfect. The commit queue will not block on this warning.\n'
56 'Email joi@chromium.org if you have questions.')
59 _INCLUDE_ORDER_WARNING
= (
60 'Your #include order seems to be broken. Send mail to\n'
61 'marja@chromium.org if this is not the case.')
64 _BANNED_OBJC_FUNCTIONS
= (
68 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
69 'prohibited. Please use CrTrackingArea instead.',
70 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
77 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
79 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
84 'convertPointFromBase:',
86 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
87 'Please use |convertPoint:(point) fromView:nil| instead.',
88 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
93 'convertPointToBase:',
95 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
96 'Please use |convertPoint:(point) toView:nil| instead.',
97 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
102 'convertRectFromBase:',
104 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
105 'Please use |convertRect:(point) fromView:nil| instead.',
106 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
111 'convertRectToBase:',
113 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
114 'Please use |convertRect:(point) toView:nil| instead.',
115 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
120 'convertSizeFromBase:',
122 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
123 'Please use |convertSize:(point) fromView:nil| instead.',
124 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
129 'convertSizeToBase:',
131 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
132 'Please use |convertSize:(point) toView:nil| instead.',
133 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
140 _BANNED_CPP_FUNCTIONS
= (
141 # Make sure that gtest's FRIEND_TEST() macro is not used; the
142 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
143 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
147 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
148 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
156 'New code should not use ScopedAllowIO. Post a task to the blocking',
157 'pool or the FILE thread instead.',
161 r
"^content[\\\/]shell[\\\/]shell_browser_main\.cc$",
168 # Please keep sorted.
171 'OS_CAT', # For testing.
181 'OS_SUN', # Not in build/build_config.h but in skia.
186 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api
, output_api
):
187 """Attempts to prevent use of functions intended only for testing in
188 non-testing code. For now this is just a best-effort implementation
189 that ignores header files and may have some false positives. A
190 better implementation would probably need a proper C++ parser.
192 # We only scan .cc files and the like, as the declaration of
193 # for-testing functions in header files are hard to distinguish from
194 # calls to such functions without a proper C++ parser.
195 file_inclusion_pattern
= r
'.+%s' % _IMPLEMENTATION_EXTENSIONS
197 base_function_pattern
= r
'ForTest(ing)?|for_test(ing)?'
198 inclusion_pattern
= input_api
.re
.compile(r
'(%s)\s*\(' % base_function_pattern
)
199 exclusion_pattern
= input_api
.re
.compile(
200 r
'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
201 base_function_pattern
, base_function_pattern
))
203 def FilterFile(affected_file
):
204 black_list
= (_EXCLUDED_PATHS
+
205 _TEST_CODE_EXCLUDED_PATHS
+
206 input_api
.DEFAULT_BLACK_LIST
)
207 return input_api
.FilterSourceFile(
209 white_list
=(file_inclusion_pattern
, ),
210 black_list
=black_list
)
213 for f
in input_api
.AffectedSourceFiles(FilterFile
):
214 local_path
= f
.LocalPath()
215 lines
= input_api
.ReadFile(f
).splitlines()
218 if (inclusion_pattern
.search(line
) and
219 not exclusion_pattern
.search(line
)):
221 '%s:%d\n %s' % (local_path
, line_number
, line
.strip()))
225 if not input_api
.is_committing
:
226 return [output_api
.PresubmitPromptWarning(_TEST_ONLY_WARNING
, problems
)]
228 # We don't warn on commit, to avoid stopping commits going through CQ.
229 return [output_api
.PresubmitNotifyResult(_TEST_ONLY_WARNING
, problems
)]
234 def _CheckNoIOStreamInHeaders(input_api
, output_api
):
235 """Checks to make sure no .h files include <iostream>."""
237 pattern
= input_api
.re
.compile(r
'^#include\s*<iostream>',
238 input_api
.re
.MULTILINE
)
239 for f
in input_api
.AffectedSourceFiles(input_api
.FilterSourceFile
):
240 if not f
.LocalPath().endswith('.h'):
242 contents
= input_api
.ReadFile(f
)
243 if pattern
.search(contents
):
247 return [ output_api
.PresubmitError(
248 'Do not #include <iostream> in header files, since it inserts static '
249 'initialization into every file including the header. Instead, '
250 '#include <ostream>. See http://crbug.com/94794',
255 def _CheckNoUNIT_TESTInSourceFiles(input_api
, output_api
):
256 """Checks to make sure no source files use UNIT_TEST"""
258 for f
in input_api
.AffectedFiles():
259 if (not f
.LocalPath().endswith(('.cc', '.mm'))):
262 for line_num
, line
in f
.ChangedContents():
263 if 'UNIT_TEST' in line
:
264 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
268 return [output_api
.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
269 '\n'.join(problems
))]
272 def _CheckNoNewWStrings(input_api
, output_api
):
273 """Checks to make sure we don't introduce use of wstrings."""
275 for f
in input_api
.AffectedFiles():
276 if (not f
.LocalPath().endswith(('.cc', '.h')) or
277 f
.LocalPath().endswith('test.cc')):
281 for line_num
, line
in f
.ChangedContents():
282 if 'presubmit: allow wstring' in line
:
284 elif not allowWString
and 'wstring' in line
:
285 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
292 return [output_api
.PresubmitPromptWarning('New code should not use wstrings.'
293 ' If you are calling a cross-platform API that accepts a wstring, '
295 '\n'.join(problems
))]
298 def _CheckNoDEPSGIT(input_api
, output_api
):
299 """Make sure .DEPS.git is never modified manually."""
300 if any(f
.LocalPath().endswith('.DEPS.git') for f
in
301 input_api
.AffectedFiles()):
302 return [output_api
.PresubmitError(
303 'Never commit changes to .DEPS.git. This file is maintained by an\n'
304 'automated system based on what\'s in DEPS and your changes will be\n'
306 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
307 'for more information')]
311 def _CheckNoBannedFunctions(input_api
, output_api
):
312 """Make sure that banned functions are not used."""
316 file_filter
= lambda f
: f
.LocalPath().endswith(('.mm', '.m', '.h'))
317 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
318 for line_num
, line
in f
.ChangedContents():
319 for func_name
, message
, error
in _BANNED_OBJC_FUNCTIONS
:
320 if func_name
in line
:
324 problems
.append(' %s:%d:' % (f
.LocalPath(), line_num
))
325 for message_line
in message
:
326 problems
.append(' %s' % message_line
)
328 file_filter
= lambda f
: f
.LocalPath().endswith(('.cc', '.mm', '.h'))
329 for f
in input_api
.AffectedFiles(file_filter
=file_filter
):
330 for line_num
, line
in f
.ChangedContents():
331 for func_name
, message
, error
, excluded_paths
in _BANNED_CPP_FUNCTIONS
:
332 def IsBlacklisted(affected_file
, blacklist
):
333 local_path
= affected_file
.LocalPath()
334 for item
in blacklist
:
335 if input_api
.re
.match(item
, local_path
):
338 if IsBlacklisted(f
, excluded_paths
):
340 if func_name
in line
:
344 problems
.append(' %s:%d:' % (f
.LocalPath(), line_num
))
345 for message_line
in message
:
346 problems
.append(' %s' % message_line
)
350 result
.append(output_api
.PresubmitPromptWarning(
351 'Banned functions were used.\n' + '\n'.join(warnings
)))
353 result
.append(output_api
.PresubmitError(
354 'Banned functions were used.\n' + '\n'.join(errors
)))
358 def _CheckNoPragmaOnce(input_api
, output_api
):
359 """Make sure that banned functions are not used."""
361 pattern
= input_api
.re
.compile(r
'^#pragma\s+once',
362 input_api
.re
.MULTILINE
)
363 for f
in input_api
.AffectedSourceFiles(input_api
.FilterSourceFile
):
364 if not f
.LocalPath().endswith('.h'):
366 contents
= input_api
.ReadFile(f
)
367 if pattern
.search(contents
):
371 return [output_api
.PresubmitError(
372 'Do not use #pragma once in header files.\n'
373 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
378 def _CheckNoTrinaryTrueFalse(input_api
, output_api
):
379 """Checks to make sure we don't introduce use of foo ? true : false."""
381 pattern
= input_api
.re
.compile(r
'\?\s*(true|false)\s*:\s*(true|false)')
382 for f
in input_api
.AffectedFiles():
383 if not f
.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
386 for line_num
, line
in f
.ChangedContents():
387 if pattern
.match(line
):
388 problems
.append(' %s:%d' % (f
.LocalPath(), line_num
))
392 return [output_api
.PresubmitPromptWarning(
393 'Please consider avoiding the "? true : false" pattern if possible.\n' +
394 '\n'.join(problems
))]
397 def _CheckUnwantedDependencies(input_api
, output_api
):
398 """Runs checkdeps on #include statements added in this
399 change. Breaking - rules is an error, breaking ! rules is a
402 # We need to wait until we have an input_api object and use this
403 # roundabout construct to import checkdeps because this file is
404 # eval-ed and thus doesn't have __file__.
405 original_sys_path
= sys
.path
407 sys
.path
= sys
.path
+ [input_api
.os_path
.join(
408 input_api
.PresubmitLocalPath(), 'tools', 'checkdeps')]
410 from cpp_checker
import CppChecker
411 from rules
import Rule
413 # Restore sys.path to what it was before.
414 sys
.path
= original_sys_path
417 for f
in input_api
.AffectedFiles():
418 if not CppChecker
.IsCppFile(f
.LocalPath()):
421 changed_lines
= [line
for line_num
, line
in f
.ChangedContents()]
422 added_includes
.append([f
.LocalPath(), changed_lines
])
424 deps_checker
= checkdeps
.DepsChecker()
426 error_descriptions
= []
427 warning_descriptions
= []
428 for path
, rule_type
, rule_description
in deps_checker
.CheckAddedCppIncludes(
430 description_with_path
= '%s\n %s' % (path
, rule_description
)
431 if rule_type
== Rule
.DISALLOW
:
432 error_descriptions
.append(description_with_path
)
434 warning_descriptions
.append(description_with_path
)
437 if error_descriptions
:
438 results
.append(output_api
.PresubmitError(
439 'You added one or more #includes that violate checkdeps rules.',
441 if warning_descriptions
:
442 if not input_api
.is_committing
:
443 warning_factory
= output_api
.PresubmitPromptWarning
445 # We don't want to block use of the CQ when there is a warning
446 # of this kind, so we only show a message when committing.
447 warning_factory
= output_api
.PresubmitNotifyResult
448 results
.append(warning_factory(
449 'You added one or more #includes of files that are temporarily\n'
450 'allowed but being removed. Can you avoid introducing the\n'
451 '#include? See relevant DEPS file(s) for details and contacts.',
452 warning_descriptions
))
456 def _CheckFilePermissions(input_api
, output_api
):
457 """Check that all files have their permissions properly set."""
458 args
= [sys
.executable
, 'tools/checkperms/checkperms.py', '--root',
459 input_api
.change
.RepositoryRoot()]
460 for f
in input_api
.AffectedFiles():
461 args
+= ['--file', f
.LocalPath()]
463 (errors
, stderrdata
) = subprocess
.Popen(args
).communicate()
467 results
.append(output_api
.PresubmitError('checkperms.py failed.',
472 def _CheckNoAuraWindowPropertyHInHeaders(input_api
, output_api
):
473 """Makes sure we don't include ui/aura/window_property.h
476 pattern
= input_api
.re
.compile(r
'^#include\s*"ui/aura/window_property.h"')
478 for f
in input_api
.AffectedFiles():
479 if not f
.LocalPath().endswith('.h'):
481 for line_num
, line
in f
.ChangedContents():
482 if pattern
.match(line
):
483 errors
.append(' %s:%d' % (f
.LocalPath(), line_num
))
487 results
.append(output_api
.PresubmitError(
488 'Header files should not include ui/aura/window_property.h', errors
))
492 def _CheckIncludeOrderForScope(scope
, input_api
, file_path
, changed_linenums
):
493 """Checks that the lines in scope occur in the right order.
495 1. C system files in alphabetical order
496 2. C++ system files in alphabetical order
497 3. Project's .h files
500 c_system_include_pattern
= input_api
.re
.compile(r
'\s*#include <.*\.h>')
501 cpp_system_include_pattern
= input_api
.re
.compile(r
'\s*#include <.*>')
502 custom_include_pattern
= input_api
.re
.compile(r
'\s*#include ".*')
504 C_SYSTEM_INCLUDES
, CPP_SYSTEM_INCLUDES
, CUSTOM_INCLUDES
= range(3)
506 state
= C_SYSTEM_INCLUDES
509 previous_line_num
= 0
510 problem_linenums
= []
511 for line_num
, line
in scope
:
512 if c_system_include_pattern
.match(line
):
513 if state
!= C_SYSTEM_INCLUDES
:
514 problem_linenums
.append((line_num
, previous_line_num
))
515 elif previous_line
and previous_line
> line
:
516 problem_linenums
.append((line_num
, previous_line_num
))
517 elif cpp_system_include_pattern
.match(line
):
518 if state
== C_SYSTEM_INCLUDES
:
519 state
= CPP_SYSTEM_INCLUDES
520 elif state
== CUSTOM_INCLUDES
:
521 problem_linenums
.append((line_num
, previous_line_num
))
522 elif previous_line
and previous_line
> line
:
523 problem_linenums
.append((line_num
, previous_line_num
))
524 elif custom_include_pattern
.match(line
):
525 if state
!= CUSTOM_INCLUDES
:
526 state
= CUSTOM_INCLUDES
527 elif previous_line
and previous_line
> line
:
528 problem_linenums
.append((line_num
, previous_line_num
))
530 problem_linenums
.append(line_num
)
532 previous_line_num
= line_num
535 for (line_num
, previous_line_num
) in problem_linenums
:
536 if line_num
in changed_linenums
or previous_line_num
in changed_linenums
:
537 warnings
.append(' %s:%d' % (file_path
, line_num
))
541 def _CheckIncludeOrderInFile(input_api
, f
, changed_linenums
):
542 """Checks the #include order for the given file f."""
544 system_include_pattern
= input_api
.re
.compile(r
'\s*#include \<.*')
545 # Exclude #include <.../...> includes from the check; e.g., <sys/...> includes
546 # often need to appear in a specific order.
547 excluded_include_pattern
= input_api
.re
.compile(r
'\s*#include \<.*/.*')
548 custom_include_pattern
= input_api
.re
.compile(r
'\s*#include "(?P<FILE>.*)"')
549 if_pattern
= input_api
.re
.compile(
550 r
'\s*#\s*(if|elif|else|endif|define|undef).*')
551 # Some files need specialized order of includes; exclude such files from this
553 uncheckable_includes_pattern
= input_api
.re
.compile(
555 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
557 contents
= f
.NewContents()
561 # Handle the special first include. If the first include file is
562 # some/path/file.h, the corresponding including file can be some/path/file.cc,
563 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
564 # etc. It's also possible that no special first include exists.
565 for line
in contents
:
567 if system_include_pattern
.match(line
):
568 # No special first include -> process the line again along with normal
572 match
= custom_include_pattern
.match(line
)
574 match_dict
= match
.groupdict()
575 header_basename
= input_api
.os_path
.basename(
576 match_dict
['FILE']).replace('.h', '')
577 if header_basename
not in input_api
.os_path
.basename(f
.LocalPath()):
578 # No special first include -> process the line again along with normal
583 # Split into scopes: Each region between #if and #endif is its own scope.
586 for line
in contents
[line_num
:]:
588 if uncheckable_includes_pattern
.match(line
):
590 if if_pattern
.match(line
):
591 scopes
.append(current_scope
)
593 elif ((system_include_pattern
.match(line
) or
594 custom_include_pattern
.match(line
)) and
595 not excluded_include_pattern
.match(line
)):
596 current_scope
.append((line_num
, line
))
597 scopes
.append(current_scope
)
600 warnings
.extend(_CheckIncludeOrderForScope(scope
, input_api
, f
.LocalPath(),
605 def _CheckIncludeOrder(input_api
, output_api
):
606 """Checks that the #include order is correct.
608 1. The corresponding header for source files.
609 2. C system files in alphabetical order
610 3. C++ system files in alphabetical order
611 4. Project's .h files in alphabetical order
613 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
614 these rules separately.
618 for f
in input_api
.AffectedFiles():
619 if f
.LocalPath().endswith(('.cc', '.h')):
620 changed_linenums
= set(line_num
for line_num
, _
in f
.ChangedContents())
621 warnings
.extend(_CheckIncludeOrderInFile(input_api
, f
, changed_linenums
))
625 if not input_api
.is_committing
:
626 results
.append(output_api
.PresubmitPromptWarning(_INCLUDE_ORDER_WARNING
,
629 # We don't warn on commit, to avoid stopping commits going through CQ.
630 results
.append(output_api
.PresubmitNotifyResult(_INCLUDE_ORDER_WARNING
,
635 def _CheckForVersionControlConflictsInFile(input_api
, f
):
636 pattern
= input_api
.re
.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
638 for line_num
, line
in f
.ChangedContents():
639 if pattern
.match(line
):
640 errors
.append(' %s:%d %s' % (f
.LocalPath(), line_num
, line
))
644 def _CheckForVersionControlConflicts(input_api
, output_api
):
645 """Usually this is not intentional and will cause a compile failure."""
647 for f
in input_api
.AffectedFiles():
648 errors
.extend(_CheckForVersionControlConflictsInFile(input_api
, f
))
652 results
.append(output_api
.PresubmitError(
653 'Version control conflict markers found, please resolve.', errors
))
657 def _CheckHardcodedGoogleHostsInLowerLayers(input_api
, output_api
):
658 def FilterFile(affected_file
):
659 """Filter function for use with input_api.AffectedSourceFiles,
660 below. This filters out everything except non-test files from
661 top-level directories that generally speaking should not hard-code
662 service URLs (e.g. src/android_webview/, src/content/ and others).
664 return input_api
.FilterSourceFile(
666 white_list
=(r
'^(android_webview|base|content|net)[\\\/].*', ),
667 black_list
=(_EXCLUDED_PATHS
+
668 _TEST_CODE_EXCLUDED_PATHS
+
669 input_api
.DEFAULT_BLACK_LIST
))
671 pattern
= input_api
.re
.compile('"[^"]*google\.com[^"]*"')
672 problems
= [] # items are (filename, line_number, line)
673 for f
in input_api
.AffectedSourceFiles(FilterFile
):
674 for line_num
, line
in f
.ChangedContents():
675 if pattern
.search(line
):
676 problems
.append((f
.LocalPath(), line_num
, line
))
679 if not input_api
.is_committing
:
680 warning_factory
= output_api
.PresubmitPromptWarning
682 # We don't want to block use of the CQ when there is a warning
683 # of this kind, so we only show a message when committing.
684 warning_factory
= output_api
.PresubmitNotifyResult
685 return [warning_factory(
686 'Most layers below src/chrome/ should not hardcode service URLs.\n'
687 'Are you sure this is correct? (Contact: joi@chromium.org)',
689 problem
[0], problem
[1], problem
[2]) for problem
in problems
])]
694 def _CheckNoAbbreviationInPngFileName(input_api
, output_api
):
695 """Makes sure there are no abbreviations in the name of PNG files.
697 pattern
= input_api
.re
.compile(r
'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
699 for f
in input_api
.AffectedFiles(include_deletes
=False):
700 if pattern
.match(f
.LocalPath()):
701 errors
.append(' %s' % f
.LocalPath())
705 results
.append(output_api
.PresubmitError(
706 'The name of PNG files should not have abbreviations. \n'
707 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
708 'Contact oshima@chromium.org if you have questions.', errors
))
712 def _CommonChecks(input_api
, output_api
):
713 """Checks common to both upload and commit."""
715 results
.extend(input_api
.canned_checks
.PanProjectChecks(
716 input_api
, output_api
, excluded_paths
=_EXCLUDED_PATHS
))
717 results
.extend(_CheckAuthorizedAuthor(input_api
, output_api
))
719 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api
, output_api
))
720 results
.extend(_CheckNoIOStreamInHeaders(input_api
, output_api
))
721 results
.extend(_CheckNoUNIT_TESTInSourceFiles(input_api
, output_api
))
722 results
.extend(_CheckNoNewWStrings(input_api
, output_api
))
723 results
.extend(_CheckNoDEPSGIT(input_api
, output_api
))
724 results
.extend(_CheckNoBannedFunctions(input_api
, output_api
))
725 results
.extend(_CheckNoPragmaOnce(input_api
, output_api
))
726 results
.extend(_CheckNoTrinaryTrueFalse(input_api
, output_api
))
727 results
.extend(_CheckUnwantedDependencies(input_api
, output_api
))
728 results
.extend(_CheckFilePermissions(input_api
, output_api
))
729 results
.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api
, output_api
))
730 results
.extend(_CheckIncludeOrder(input_api
, output_api
))
731 results
.extend(_CheckForVersionControlConflicts(input_api
, output_api
))
732 results
.extend(_CheckPatchFiles(input_api
, output_api
))
733 results
.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api
, output_api
))
734 results
.extend(_CheckNoAbbreviationInPngFileName(input_api
, output_api
))
735 results
.extend(_CheckForInvalidOSMacros(input_api
, output_api
))
737 if any('PRESUBMIT.py' == f
.LocalPath() for f
in input_api
.AffectedFiles()):
738 results
.extend(input_api
.canned_checks
.RunUnitTestsInDirectory(
739 input_api
, output_api
,
740 input_api
.PresubmitLocalPath(),
741 whitelist
=[r
'^PRESUBMIT_test\.py$']))
745 def _CheckSubversionConfig(input_api
, output_api
):
746 """Verifies the subversion config file is correctly setup.
748 Checks that autoprops are enabled, returns an error otherwise.
750 join
= input_api
.os_path
.join
751 if input_api
.platform
== 'win32':
752 appdata
= input_api
.environ
.get('APPDATA', '')
754 return [output_api
.PresubmitError('%APPDATA% is not configured.')]
755 path
= join(appdata
, 'Subversion', 'config')
757 home
= input_api
.environ
.get('HOME', '')
759 return [output_api
.PresubmitError('$HOME is not configured.')]
760 path
= join(home
, '.subversion', 'config')
763 'Please look at http://dev.chromium.org/developers/coding-style to\n'
764 'configure your subversion configuration file. This enables automatic\n'
765 'properties to simplify the project maintenance.\n'
766 'Pro-tip: just download and install\n'
767 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
770 lines
= open(path
, 'r').read().splitlines()
771 # Make sure auto-props is enabled and check for 2 Chromium standard
773 if (not '*.cc = svn:eol-style=LF' in lines
or
774 not '*.pdf = svn:mime-type=application/pdf' in lines
or
775 not 'enable-auto-props = yes' in lines
):
777 output_api
.PresubmitNotifyResult(
778 'It looks like you have not configured your subversion config '
779 'file or it is not up-to-date.\n' + error_msg
)
781 except (OSError, IOError):
783 output_api
.PresubmitNotifyResult(
784 'Can\'t find your subversion config file.\n' + error_msg
)
789 def _CheckAuthorizedAuthor(input_api
, output_api
):
790 """For non-googler/chromites committers, verify the author's email address is
793 # TODO(maruel): Add it to input_api?
796 author
= input_api
.change
.author_email
798 input_api
.logging
.info('No author, skipping AUTHOR check')
800 authors_path
= input_api
.os_path
.join(
801 input_api
.PresubmitLocalPath(), 'AUTHORS')
803 input_api
.re
.match(r
'[^#]+\s+\<(.+?)\>\s*$', line
)
804 for line
in open(authors_path
))
805 valid_authors
= [item
.group(1).lower() for item
in valid_authors
if item
]
806 if not any(fnmatch
.fnmatch(author
.lower(), valid
) for valid
in valid_authors
):
807 input_api
.logging
.info('Valid authors are %s', ', '.join(valid_authors
))
808 return [output_api
.PresubmitPromptWarning(
809 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
811 'http://www.chromium.org/developers/contributing-code and read the '
813 'If you are a chromite, verify the contributor signed the CLA.') %
818 def _CheckPatchFiles(input_api
, output_api
):
819 problems
= [f
.LocalPath() for f
in input_api
.AffectedFiles()
820 if f
.LocalPath().endswith(('.orig', '.rej'))]
822 return [output_api
.PresubmitError(
823 "Don't commit .rej and .orig files.", problems
)]
828 def _DidYouMeanOSMacro(bad_macro
):
830 return {'A': 'OS_ANDROID',
840 'W': 'OS_WIN'}[bad_macro
[3].upper()]
845 def _CheckForInvalidOSMacrosInFile(input_api
, f
):
846 """Check for sensible looking, totally invalid OS macros."""
847 preprocessor_statement
= input_api
.re
.compile(r
'^\s*#')
848 os_macro
= input_api
.re
.compile(r
'defined\((OS_[^)]+)\)')
850 for lnum
, line
in f
.ChangedContents():
851 if preprocessor_statement
.search(line
):
852 for match
in os_macro
.finditer(line
):
853 if not match
.group(1) in _VALID_OS_MACROS
:
854 good
= _DidYouMeanOSMacro(match
.group(1))
855 did_you_mean
= ' (did you mean %s?)' % good
if good
else ''
856 results
.append(' %s:%d %s%s' % (f
.LocalPath(),
863 def _CheckForInvalidOSMacros(input_api
, output_api
):
864 """Check all affected files for invalid OS macros."""
866 for f
in input_api
.AffectedFiles():
867 if not f
.LocalPath().endswith(('.py', '.js', '.html', '.css')):
868 bad_macros
.extend(_CheckForInvalidOSMacrosInFile(input_api
, f
))
873 return [output_api
.PresubmitError(
874 'Possibly invalid OS macro[s] found. Please fix your code\n'
875 'or add your macro to src/PRESUBMIT.py.', bad_macros
)]
878 def CheckChangeOnUpload(input_api
, output_api
):
880 results
.extend(_CommonChecks(input_api
, output_api
))
884 def CheckChangeOnCommit(input_api
, output_api
):
886 results
.extend(_CommonChecks(input_api
, output_api
))
887 # TODO(thestig) temporarily disabled, doesn't work in third_party/
888 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
889 # input_api, output_api, sources))
890 # Make sure the tree is 'open'.
891 results
.extend(input_api
.canned_checks
.CheckTreeIsOpen(
894 json_url
='http://chromium-status.appspot.com/current?format=json'))
895 results
.extend(input_api
.canned_checks
.CheckRietveldTryJobExecution(input_api
,
896 output_api
, 'http://codereview.chromium.org',
897 ('win_rel', 'linux_rel', 'mac_rel, win:compile'),
898 'tryserver@chromium.org'))
900 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
901 input_api
, output_api
))
902 results
.extend(input_api
.canned_checks
.CheckChangeHasDescription(
903 input_api
, output_api
))
904 results
.extend(_CheckSubversionConfig(input_api
, output_api
))
908 def GetPreferredTrySlaves(project
, change
):
909 files
= change
.LocalPaths()
911 if not files
or all(re
.search(r
'[\\/]OWNERS$', f
) for f
in files
):
914 if all(re
.search('\.(m|mm)$|(^|[/_])mac[/_.]', f
) for f
in files
):
915 return ['mac_rel', 'mac_asan', 'mac:compile']
916 if all(re
.search('(^|[/_])win[/_.]', f
) for f
in files
):
917 return ['win_rel', 'win7_aura', 'win:compile']
918 if all(re
.search('(^|[/_])android[/_.]', f
) for f
in files
):
919 return ['android_dbg', 'android_clang_dbg']
920 if all(re
.search('^native_client_sdk', f
) for f
in files
):
921 return ['linux_nacl_sdk', 'win_nacl_sdk', 'mac_nacl_sdk']
922 if all(re
.search('[/_]ios[/_.]', f
) for f
in files
):
923 return ['ios_rel_device', 'ios_dbg_simulator']
933 'linux_clang:compile',
943 # Match things like path/aura/file.cc and path/file_aura.cc.
945 if any(re
.search('[/_](aura|chromeos)', f
) for f
in files
):
946 trybots
+= ['linux_chromeos_clang:compile', 'linux_chromeos_asan']