Roll src/third_party/WebKit 58870dd:8cff7c9 (svn 202487:202488)
[chromium-blink-merge.git] / chrome / PRESUBMIT.py
blob195a5f6c9530c6503e3b1719b160de579b724910
1 # Copyright (c) 2011 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 """Presubmit script for changes affecting chrome/
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools.
9 """
11 import re
13 INCLUDE_CPP_FILES_ONLY = (
14 r'.*\.(cc|h)$',
17 EXCLUDE = (
18 # Objective C confuses everything.
19 r'.*cocoa.*',
20 r'.*_mac\.(cc|h)$',
21 r'.*_mac_.*',
22 # All the messages files do weird multiple include trickery
23 r'.*_messages.*\.h$',
24 r'render_messages.h$',
25 # Autogenerated window resources files are off limits
26 r'.*resource.h$',
27 # Header trickery
28 r'.*-inl\.h$',
29 # Has safe printf usage that cpplint complains about
30 r'safe_browsing_util\.cc$',
33 def _CheckChangeLintsClean(input_api, output_api):
34 """Makes sure that the chrome/ code is cpplint clean."""
35 black_list = input_api.DEFAULT_BLACK_LIST + EXCLUDE
36 sources = lambda x: input_api.FilterSourceFile(
37 x, white_list=INCLUDE_CPP_FILES_ONLY, black_list=black_list)
38 return input_api.canned_checks.CheckChangeLintsClean(
39 input_api, output_api, sources)
41 def _CheckNoContentUnitTestsInChrome(input_api, output_api):
42 """Makes sure that no unit tests from content/ are included in unit_tests."""
43 problems = []
44 for f in input_api.AffectedFiles():
45 if not f.LocalPath().endswith('chrome_tests.gypi'):
46 continue
48 for line_num, line in f.ChangedContents():
49 m = re.search(r"'(.*\/content\/.*unittest.*)'", line)
50 if m:
51 problems.append(m.group(1))
53 if not problems:
54 return []
55 return [output_api.PresubmitPromptWarning(
56 'Unit tests located in content/ should be added to the ' +
57 'content_tests.gypi:content_unittests target.',
58 items=problems)]
60 def _CommonChecks(input_api, output_api):
61 """Checks common to both upload and commit."""
62 results = []
63 results.extend(_CheckNoContentUnitTestsInChrome(input_api, output_api))
64 return results
66 def CheckChangeOnUpload(input_api, output_api):
67 results = []
68 results.extend(_CommonChecks(input_api, output_api))
69 results.extend(_CheckChangeLintsClean(input_api, output_api))
70 return results
72 def CheckChangeOnCommit(input_api, output_api):
73 results = []
74 results.extend(_CommonChecks(input_api, output_api))
75 return results