blob: 9f4eefa7ad6f53feccfa312e740a4b9ebaf28f71 [file] [log] [blame]
[email protected]2fac3752011-11-27 20:56:511# Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]93b2d7372009-11-17 18:54:532# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
[email protected]5a0114502011-11-29 13:01:245"""Presubmit script for changes affecting chrome/
6
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
tfarina78bb92f42015-01-31 00:20:488for more details about the presubmit API built into depot_tools.
[email protected]5a0114502011-11-29 13:01:249"""
10
11import re
[email protected]93b2d7372009-11-17 18:54:5312
13INCLUDE_CPP_FILES_ONLY = (
14 r'.*\.cc$', r'.*\.h$'
15)
16
17EXCLUDE = (
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
[email protected]3139e9f2013-10-10 21:29:4723 r'.*_messages.*\.h$',
[email protected]93b2d7372009-11-17 18:54:5324 r'render_messages.h$',
25 # Autogenerated window resources files are off limits
26 r'.*resource.h$',
[email protected]93b2d7372009-11-17 18:54:5327 # Header trickery
28 r'.*-inl\.h$',
[email protected]93b2d7372009-11-17 18:54:5329 # Has safe printf usage that cpplint complains about
30 r'safe_browsing_util\.cc$',
[email protected]93b2d7372009-11-17 18:54:5331)
32
[email protected]5a0114502011-11-29 13:01:2433def _CheckChangeLintsClean(input_api, output_api):
34 """Makes sure that the chrome/ code is cpplint clean."""
[email protected]93b2d7372009-11-17 18:54:5335 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)
[email protected]5a0114502011-11-29 13:01:2438 return input_api.canned_checks.CheckChangeLintsClean(
39 input_api, output_api, sources)
40
41def _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
47
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))
52
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)]
59
60def _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
65
66def 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
71
72def CheckChangeOnCommit(input_api, output_api):
73 results = []
74 results.extend(_CommonChecks(input_api, output_api))
[email protected]93b2d7372009-11-17 18:54:5375 return results