blob: 2cfb37f56f66728c2e6bd5c850f40711da3c8e68 [file] [log] [blame]
[email protected]1f7b4172010-01-28 01:17:341# Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]ca8d1982009-02-19 16:33:122# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Top-level presubmit script for Chromium.
6
[email protected]f1293792009-07-31 18:09:567See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
[email protected]50d7d721e2009-11-15 17:56:188for more details about the presubmit API built into gcl.
[email protected]ca8d1982009-02-19 16:33:129"""
10
[email protected]379e7dd2010-01-28 17:39:2111_EXCLUDED_PATHS = (
[email protected]3e4eb112011-01-18 03:29:5412 r"^breakpad[\\\/].*",
13 r"^net/tools/spdyshark/[\\\/].*",
14 r"^skia[\\\/].*",
15 r"^v8[\\\/].*",
16 r".*MakeFile$",
[email protected]4306417642009-06-11 00:33:4017)
[email protected]ca8d1982009-02-19 16:33:1218
[email protected]379e7dd2010-01-28 17:39:2119_TEXT_FILES = (
20 r".*\.txt",
21 r".*\.json",
22)
[email protected]ca8d1982009-02-19 16:33:1223
[email protected]1f7b4172010-01-28 01:17:3424_LICENSE_HEADER = (
[email protected]38fdd9d2010-01-28 18:33:2225 r".*? Copyright \(c\) 20[0-9\-]{2,7} The Chromium Authors\. All rights "
26 r"reserved\." "\n"
[email protected]1f7b4172010-01-28 01:17:3427 r".*? Use of this source code is governed by a BSD-style license that can "
28 "be\n"
29 r".*? found in the LICENSE file\."
30 "\n"
31)
32
[email protected]6a4c8e682010-12-19 03:31:3433def _CheckNoInterfacesInBase(input_api, output_api, source_file_filter):
34 """Checks to make sure no files in libbase.a have |@interface|."""
35 pattern = input_api.re.compile(r'@interface')
36 files = []
37 for f in input_api.AffectedSourceFiles(source_file_filter):
38 if (f.LocalPath().find('base/') != -1 and
39 f.LocalPath().find('base/test/') == -1):
40 contents = input_api.ReadFile(f)
41 if pattern.search(contents):
42 files.append(f)
43
44 if len(files):
45 return [ output_api.PresubmitError(
46 'Objective-C interfaces or categories are forbidden in libbase. ' +
47 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
48 'browse_thread/thread/efb28c10435987fd',
49 files) ]
50 return []
51
[email protected]650c9082010-12-14 14:33:4452def _CheckSingletonInHeaders(input_api, output_api, source_file_filter):
53 """Checks to make sure no header files have |Singleton<|."""
54 pattern = input_api.re.compile(r'Singleton<')
55 files = []
56 for f in input_api.AffectedSourceFiles(source_file_filter):
57 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
58 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
59 contents = input_api.ReadFile(f)
60 if pattern.search(contents):
61 files.append(f)
62
63 if len(files):
64 return [ output_api.PresubmitError(
65 'Found Singleton<T> in the following header files.\n' +
66 'Please move them to an appropriate source file so that the ' +
67 'template gets instantiated in a single compilation unit.',
68 files) ]
69 return []
[email protected]1f7b4172010-01-28 01:17:3470
[email protected]b337cb5b2011-01-23 21:24:0571
72def _CheckSubversionConfig(input_api, output_api):
73 """Verifies the subversion config file is correctly setup.
74
75 Checks that autoprops are enabled, returns an error otherwise.
76 """
77 join = input_api.os_path.join
78 if input_api.platform == 'win32':
79 appdata = input_api.environ.get('APPDATA', '')
80 if not appdata:
81 return [output_api.PresubmitError('%APPDATA% is not configured.')]
82 path = join(appdata, 'Subversion', 'config')
83 else:
84 home = input_api.environ.get('HOME', '')
85 if not home:
86 return [output_api.PresubmitError('$HOME is not configured.')]
87 path = join(home, '.subversion', 'config')
88
89 error_msg = (
90 'Please look at http://dev.chromium.org/developers/coding-style to\n'
91 'configure your subversion configuration file. This enables automatic\n'
[email protected]c6a3c10b2011-01-24 16:14:2092 'properties to simplify the project maintenance.\n'
93 'Pro-tip: just download and install\n'
94 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
[email protected]b337cb5b2011-01-23 21:24:0595
96 try:
97 lines = open(path, 'r').read().splitlines()
98 # Make sure auto-props is enabled and check for 2 Chromium standard
99 # auto-prop.
100 if (not '*.cc = svn:eol-style=LF' in lines or
101 not '*.pdf = svn:mime-type=application/pdf' in lines or
102 not 'enable-auto-props = yes' in lines):
103 return [
[email protected]79ed7e62011-02-21 21:08:53104 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:05105 'It looks like you have not configured your subversion config '
[email protected]b5359c02011-02-01 20:29:56106 'file or it is not up-to-date.\n' + error_msg)
[email protected]b337cb5b2011-01-23 21:24:05107 ]
108 except (OSError, IOError):
109 return [
[email protected]79ed7e62011-02-21 21:08:53110 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:05111 'Can\'t find your subversion config file.\n' + error_msg)
112 ]
113 return []
114
115
[email protected]542d1ad22010-08-04 17:50:55116def _CheckConstNSObject(input_api, output_api, source_file_filter):
117 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
118 pattern = input_api.re.compile(r'const\s+NS\w*\s*\*')
119 files = []
120 for f in input_api.AffectedSourceFiles(source_file_filter):
121 if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'):
122 contents = input_api.ReadFile(f)
123 if pattern.search(contents):
124 files.append(f)
125
126 if len(files):
127 if input_api.is_committing:
128 res_type = output_api.PresubmitPromptWarning
129 else:
130 res_type = output_api.PresubmitNotifyResult
131 return [ res_type('|const NSClass*| is wrong, see ' +
132 'http://dev.chromium.org/developers/clang-mac',
133 files) ]
134 return []
135
136
[email protected]1f7b4172010-01-28 01:17:34137def _CommonChecks(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54138 results = []
[email protected]4306417642009-06-11 00:33:40139 # What does this code do?
140 # It loads the default black list (e.g. third_party, experimental, etc) and
141 # add our black list (breakpad, skia and v8 are still not following
142 # google style and are not really living this repository).
143 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
[email protected]379e7dd2010-01-28 17:39:21144 black_list = input_api.DEFAULT_BLACK_LIST + _EXCLUDED_PATHS
145 white_list = input_api.DEFAULT_WHITE_LIST + _TEXT_FILES
[email protected]4306417642009-06-11 00:33:40146 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
[email protected]379e7dd2010-01-28 17:39:21147 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list,
148 white_list=white_list)
[email protected]4306417642009-06-11 00:33:40149 results.extend(input_api.canned_checks.CheckLongLines(
[email protected]ea1413862010-05-05 23:24:53150 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40151 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
[email protected]ea1413862010-05-05 23:24:53152 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40153 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
[email protected]ea1413862010-05-05 23:24:53154 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40155 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
[email protected]ea1413862010-05-05 23:24:53156 input_api, output_api, source_file_filter=text_files))
[email protected]40cdf8b32009-06-26 23:00:37157 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
158 input_api, output_api))
[email protected]1f7b4172010-01-28 01:17:34159 results.extend(input_api.canned_checks.CheckLicense(
[email protected]ea1413862010-05-05 23:24:53160 input_api, output_api, _LICENSE_HEADER, source_file_filter=sources))
[email protected]542d1ad22010-08-04 17:50:55161 results.extend(_CheckConstNSObject(
162 input_api, output_api, source_file_filter=sources))
[email protected]650c9082010-12-14 14:33:44163 results.extend(_CheckSingletonInHeaders(
164 input_api, output_api, source_file_filter=sources))
[email protected]6a4c8e682010-12-19 03:31:34165 results.extend(_CheckNoInterfacesInBase(
166 input_api, output_api, source_file_filter=sources))
[email protected]1f7b4172010-01-28 01:17:34167 return results
168
169
170def CheckChangeOnUpload(input_api, output_api):
171 results = []
172 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54173 return results
[email protected]ca8d1982009-02-19 16:33:12174
175
176def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54177 results = []
[email protected]806e98e2010-03-19 17:49:27178 if not input_api.json:
179 results.append(output_api.PresubmitNotifyResult(
180 'You don\'t have json nor simplejson installed.\n'
181 ' This is a warning that you will need to upgrade your python '
182 'installation.\n'
183 ' This is no big deal but you\'ll eventually need to '
184 'upgrade.\n'
185 ' How? Easy! You can do it right now and shut me off! Just:\n'
186 ' del depot_tools\\python.bat\n'
187 ' gclient\n'
188 ' Thanks for your patience.'))
[email protected]1f7b4172010-01-28 01:17:34189 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:51190 # TODO(thestig) temporarily disabled, doesn't work in third_party/
191 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
192 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:54193 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:27194 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:34195 input_api,
196 output_api,
[email protected]4efa42142010-08-26 01:29:26197 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:27198 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
199 output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
200 '[email protected]'))
201
[email protected]7fa42f12009-11-09 20:54:16202 # These builders are just too slow.
203 IGNORED_BUILDERS = [
204 'Chromium XP',
[email protected]7fa42f12009-11-09 20:54:16205 'Chromium Mac',
[email protected]01333922010-02-02 21:25:02206 'Chromium Arm (dbg)',
[email protected]7fa42f12009-11-09 20:54:16207 'Chromium Linux',
208 'Chromium Linux x64',
[email protected]7fa42f12009-11-09 20:54:16209 ]
[email protected]806e98e2010-03-19 17:49:27210 results.extend(input_api.canned_checks.CheckBuildbotPendingBuilds(
[email protected]7fa42f12009-11-09 20:54:16211 input_api,
212 output_api,
[email protected]07247462010-12-24 07:45:56213 'http://build.chromium.org/p/chromium/json/builders?filter=1',
[email protected]7fa42f12009-11-09 20:54:16214 6,
215 IGNORED_BUILDERS))
[email protected]3e4eb112011-01-18 03:29:54216 results.extend(input_api.canned_checks.CheckChangeHasBugField(
217 input_api, output_api))
218 results.extend(input_api.canned_checks.CheckChangeHasTestField(
219 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:05220 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54221 return results
[email protected]ca8d1982009-02-19 16:33:12222
223
[email protected]5fa06292009-09-29 01:55:00224def GetPreferredTrySlaves():
225 return ['win', 'linux', 'mac']