blob: 8a1fccdf1629aacdf1cff52447b6e7ca7dc0fbfa [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
8for more details about the presubmit API built into gcl.
9"""
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
23 r'.*_messages_internal\.h$',
24 r'render_messages.h$',
25 # Autogenerated window resources files are off limits
26 r'.*resource.h$',
27 # GTK macros in C-ish header code cause false positives
28 r'gtk_.*\.h$',
29 # Header trickery
30 r'.*-inl\.h$',
31 # Templates
32 r'sigslotrepeater\.h$',
33 # GCC attribute trickery
34 r'sel_main\.cc$',
35 # Mozilla code
36 r'mork_reader\.h$',
37 r'mork_reader\.cc$',
38 r'nss_decryptor_linux\.cc$',
39 # Has safe printf usage that cpplint complains about
40 r'safe_browsing_util\.cc$',
[email protected]93b2d7372009-11-17 18:54:5341 # Bogus ifdef tricks
[email protected]8d6cba42011-09-02 10:05:1942 r'renderer_webkitplatformsupport_impl\.cc$',
[email protected]93b2d7372009-11-17 18:54:5343 # Lines > 100 chars
44 r'gcapi\.cc$',
45)
46
[email protected]5a0114502011-11-29 13:01:2447def _CheckChangeLintsClean(input_api, output_api):
48 """Makes sure that the chrome/ code is cpplint clean."""
[email protected]93b2d7372009-11-17 18:54:5349 black_list = input_api.DEFAULT_BLACK_LIST + EXCLUDE
50 sources = lambda x: input_api.FilterSourceFile(
51 x, white_list=INCLUDE_CPP_FILES_ONLY, black_list=black_list)
[email protected]5a0114502011-11-29 13:01:2452 return input_api.canned_checks.CheckChangeLintsClean(
53 input_api, output_api, sources)
54
55def _CheckNoContentUnitTestsInChrome(input_api, output_api):
56 """Makes sure that no unit tests from content/ are included in unit_tests."""
57 problems = []
58 for f in input_api.AffectedFiles():
59 if not f.LocalPath().endswith('chrome_tests.gypi'):
60 continue
61
62 for line_num, line in f.ChangedContents():
63 m = re.search(r"'(.*\/content\/.*unittest.*)'", line)
64 if m:
65 problems.append(m.group(1))
66
67 if not problems:
68 return []
69 return [output_api.PresubmitPromptWarning(
70 'Unit tests located in content/ should be added to the ' +
71 'content_tests.gypi:content_unittests target.',
72 items=problems)]
73
74def _CommonChecks(input_api, output_api):
75 """Checks common to both upload and commit."""
76 results = []
77 results.extend(_CheckNoContentUnitTestsInChrome(input_api, output_api))
78 return results
79
80def CheckChangeOnUpload(input_api, output_api):
81 results = []
82 results.extend(_CommonChecks(input_api, output_api))
83 results.extend(_CheckChangeLintsClean(input_api, output_api))
84 return results
85
86def CheckChangeOnCommit(input_api, output_api):
87 results = []
88 results.extend(_CommonChecks(input_api, output_api))
[email protected]93b2d7372009-11-17 18:54:5389 return results