blob: 4d5c85391b6477f644b3edfabd28599e29f8dd53 [file] [log] [blame]
[email protected]a18130a2012-01-03 17:52:081# Copyright (c) 2012 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
tfarina78bb92f42015-01-31 00:20:488for more details about the presubmit API built into depot_tools.
[email protected]ca8d1982009-02-19 16:33:129"""
10
[email protected]eea609a2011-11-18 13:10:1211
[email protected]379e7dd2010-01-28 17:39:2112_EXCLUDED_PATHS = (
[email protected]3e4eb112011-01-18 03:29:5413 r"^breakpad[\\\/].*",
[email protected]40d1dbb2012-10-26 07:18:0014 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
15 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
[email protected]8886ffcb2013-02-12 04:56:2816 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
[email protected]a18130a2012-01-03 17:52:0817 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
[email protected]3e4eb112011-01-18 03:29:5418 r"^skia[\\\/].*",
19 r"^v8[\\\/].*",
20 r".*MakeFile$",
[email protected]1084ccc2012-03-14 03:22:5321 r".+_autogen\.h$",
[email protected]ce145c02012-09-06 09:49:3422 r".+[\\\/]pnacl_shim\.c$",
[email protected]e07b6ac72013-08-20 00:30:4223 r"^gpu[\\\/]config[\\\/].*_list_json\.cc$",
[email protected]d2600602014-02-19 00:09:1924 r"^chrome[\\\/]browser[\\\/]resources[\\\/]pdf[\\\/]index.js"
[email protected]4306417642009-06-11 00:33:4025)
[email protected]ca8d1982009-02-19 16:33:1226
jochen9ea8fdbc2014-09-25 13:21:3527# The NetscapePlugIn library is excluded from pan-project as it will soon
28# be deleted together with the rest of the NPAPI and it's not worthwhile to
29# update the coding style until then.
[email protected]3de922f2013-12-20 13:27:3830_TESTRUNNER_PATHS = (
[email protected]de28fed2e2014-02-01 14:36:3231 r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*",
[email protected]3de922f2013-12-20 13:27:3832)
33
[email protected]06e6d0ff2012-12-11 01:36:4434# Fragment of a regular expression that matches C++ and Objective-C++
35# implementation files.
36_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
37
38# Regular expression that matches code only used for test binaries
39# (best effort).
40_TEST_CODE_EXCLUDED_PATHS = (
joaodasilva718f87672014-08-30 09:25:4941 r'.*[\\\/](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4442 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
[email protected]6e04f8c2014-01-29 18:08:3243 r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
[email protected]e2d7e6f2013-04-23 12:57:1244 _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4445 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
joaodasilva718f87672014-08-30 09:25:4946 r'.*[\\\/](test|tool(s)?)[\\\/].*',
[email protected]ef070cc2013-05-03 11:53:0547 # content_shell is used for running layout tests.
joaodasilva718f87672014-08-30 09:25:4948 r'content[\\\/]shell[\\\/].*',
[email protected]06e6d0ff2012-12-11 01:36:4449 # At request of folks maintaining this folder.
joaodasilva718f87672014-08-30 09:25:4950 r'chrome[\\\/]browser[\\\/]automation[\\\/].*',
[email protected]7b054982013-11-27 00:44:4751 # Non-production example code.
joaodasilva718f87672014-08-30 09:25:4952 r'mojo[\\\/]examples[\\\/].*',
[email protected]8176de12014-06-20 19:07:0853 # Launcher for running iOS tests on the simulator.
joaodasilva718f87672014-08-30 09:25:4954 r'testing[\\\/]iossim[\\\/]iossim\.mm$',
[email protected]06e6d0ff2012-12-11 01:36:4455)
[email protected]ca8d1982009-02-19 16:33:1256
[email protected]eea609a2011-11-18 13:10:1257_TEST_ONLY_WARNING = (
58 'You might be calling functions intended only for testing from\n'
59 'production code. It is OK to ignore this warning if you know what\n'
60 'you are doing, as the heuristics used to detect the situation are\n'
[email protected]b0149772014-03-27 16:47:5861 'not perfect. The commit queue will not block on this warning.')
[email protected]eea609a2011-11-18 13:10:1262
63
[email protected]cf9b78f2012-11-14 11:40:2864_INCLUDE_ORDER_WARNING = (
marjaa017dc482015-03-09 17:13:4065 'Your #include order seems to be broken. Remember to use the right '
66 'collation (LC_COLLATE=C) and check https://google-styleguide.googlecode'
67 '.com/svn/trunk/cppguide.html#Names_and_Order_of_Includes')
[email protected]cf9b78f2012-11-14 11:40:2868
[email protected]127f18ec2012-06-16 05:05:5969_BANNED_OBJC_FUNCTIONS = (
70 (
71 'addTrackingRect:',
[email protected]23e6cbc2012-06-16 18:51:2072 (
73 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
[email protected]127f18ec2012-06-16 05:05:5974 'prohibited. Please use CrTrackingArea instead.',
75 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
76 ),
77 False,
78 ),
79 (
[email protected]eaae1972014-04-16 04:17:2680 r'/NSTrackingArea\W',
[email protected]23e6cbc2012-06-16 18:51:2081 (
82 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
[email protected]127f18ec2012-06-16 05:05:5983 'instead.',
84 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
85 ),
86 False,
87 ),
88 (
89 'convertPointFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2090 (
91 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5992 'Please use |convertPoint:(point) fromView:nil| instead.',
93 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
94 ),
95 True,
96 ),
97 (
98 'convertPointToBase:',
[email protected]23e6cbc2012-06-16 18:51:2099 (
100 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59101 'Please use |convertPoint:(point) toView:nil| instead.',
102 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
103 ),
104 True,
105 ),
106 (
107 'convertRectFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20108 (
109 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59110 'Please use |convertRect:(point) fromView:nil| instead.',
111 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
112 ),
113 True,
114 ),
115 (
116 'convertRectToBase:',
[email protected]23e6cbc2012-06-16 18:51:20117 (
118 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59119 'Please use |convertRect:(point) toView:nil| instead.',
120 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
121 ),
122 True,
123 ),
124 (
125 'convertSizeFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20126 (
127 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59128 'Please use |convertSize:(point) fromView:nil| instead.',
129 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
130 ),
131 True,
132 ),
133 (
134 'convertSizeToBase:',
[email protected]23e6cbc2012-06-16 18:51:20135 (
136 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59137 'Please use |convertSize:(point) toView:nil| instead.',
138 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
139 ),
140 True,
141 ),
142)
143
144
145_BANNED_CPP_FUNCTIONS = (
[email protected]23e6cbc2012-06-16 18:51:20146 # Make sure that gtest's FRIEND_TEST() macro is not used; the
147 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
[email protected]e00ccc92012-11-01 17:32:30148 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
[email protected]23e6cbc2012-06-16 18:51:20149 (
150 'FRIEND_TEST(',
151 (
[email protected]e3c945502012-06-26 20:01:49152 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
[email protected]23e6cbc2012-06-16 18:51:20153 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
154 ),
155 False,
[email protected]7345da02012-11-27 14:31:49156 (),
[email protected]23e6cbc2012-06-16 18:51:20157 ),
158 (
159 'ScopedAllowIO',
160 (
[email protected]e3c945502012-06-26 20:01:49161 'New code should not use ScopedAllowIO. Post a task to the blocking',
162 'pool or the FILE thread instead.',
[email protected]23e6cbc2012-06-16 18:51:20163 ),
[email protected]e3c945502012-06-26 20:01:49164 True,
[email protected]7345da02012-11-27 14:31:49165 (
thestig75844fdb2014-09-09 19:47:10166 r"^base[\\\/]process[\\\/]process_metrics_linux\.cc$",
tfarina0923ac52015-01-07 03:21:22167 r"^chrome[\\\/]browser[\\\/]chromeos[\\\/]boot_times_recorder\.cc$",
alematee4016bb2014-11-12 17:38:51168 r"^chrome[\\\/]browser[\\\/]chromeos[\\\/]"
169 "customization_document_browsertest\.cc$",
philipj3f9d5bde2014-08-28 14:09:09170 r"^components[\\\/]crash[\\\/]app[\\\/]breakpad_mac\.mm$",
[email protected]de7d61ff2013-08-20 11:30:41171 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
172 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
jamesra03ae492014-10-03 04:26:48173 r"^mojo[\\\/]edk[\\\/]embedder[\\\/]" +
174 r"simple_platform_shared_buffer_posix\.cc$",
[email protected]398ad132013-04-02 15:11:01175 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
[email protected]1f52a572014-05-12 23:21:54176 r"^net[\\\/]url_request[\\\/]test_url_fetcher_factory\.cc$",
dnicoara171d8c82015-03-05 20:46:18177 r"^ui[\\\/]ozone[\\\/]platform[\\\/]drm[\\\/]host[\\\/]"
dnicoarab29d0512015-05-07 19:29:23178 "drm_display_host_manager\.cc$",
[email protected]7345da02012-11-27 14:31:49179 ),
[email protected]23e6cbc2012-06-16 18:51:20180 ),
[email protected]52657f62013-05-20 05:30:31181 (
182 'SkRefPtr',
183 (
184 'The use of SkRefPtr is prohibited. ',
185 'Please use skia::RefPtr instead.'
186 ),
187 True,
188 (),
189 ),
190 (
191 'SkAutoRef',
192 (
193 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
194 'Please use skia::RefPtr instead.'
195 ),
196 True,
197 (),
198 ),
199 (
200 'SkAutoTUnref',
201 (
202 'The use of SkAutoTUnref is dangerous because it implicitly ',
203 'converts to a raw pointer. Please use skia::RefPtr instead.'
204 ),
205 True,
206 (),
207 ),
208 (
209 'SkAutoUnref',
210 (
211 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
212 'because it implicitly converts to a raw pointer. ',
213 'Please use skia::RefPtr instead.'
214 ),
215 True,
216 (),
217 ),
[email protected]d89eec82013-12-03 14:10:59218 (
219 r'/HANDLE_EINTR\(.*close',
220 (
221 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
222 'descriptor will be closed, and it is incorrect to retry the close.',
223 'Either call close directly and ignore its return value, or wrap close',
224 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
225 ),
226 True,
227 (),
228 ),
229 (
230 r'/IGNORE_EINTR\((?!.*close)',
231 (
232 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
233 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
234 ),
235 True,
236 (
237 # Files that #define IGNORE_EINTR.
238 r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
239 r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
240 ),
241 ),
[email protected]ec5b3f02014-04-04 18:43:43242 (
243 r'/v8::Extension\(',
244 (
245 'Do not introduce new v8::Extensions into the code base, use',
246 'gin::Wrappable instead. See http://crbug.com/334679',
247 ),
248 True,
[email protected]f55c90ee62014-04-12 00:50:03249 (
joaodasilva718f87672014-08-30 09:25:49250 r'extensions[\\\/]renderer[\\\/]safe_builtins\.*',
[email protected]f55c90ee62014-04-12 00:50:03251 ),
[email protected]ec5b3f02014-04-04 18:43:43252 ),
skyostilf9469f72015-04-20 10:38:52253 (
sdefresneeaeccc52015-04-22 08:18:32254 '\<MessageLoopProxy\>',
skyostilf9469f72015-04-20 10:38:52255 (
256 'MessageLoopProxy is deprecated. ',
257 'Please use SingleThreadTaskRunner or ThreadTaskRunnerHandle instead.'
258 ),
259 True,
kinuko59024ce2015-04-21 22:18:30260 (
261 # Internal message_loop related code may still use it.
262 r'^base[\\\/]message_loop[\\\/].*',
263 ),
skyostilf9469f72015-04-20 10:38:52264 ),
[email protected]127f18ec2012-06-16 05:05:59265)
266
mlamouria82272622014-09-16 18:45:04267_IPC_ENUM_TRAITS_DEPRECATED = (
268 'You are using IPC_ENUM_TRAITS() in your code. It has been deprecated.\n'
269 'See http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc')
270
[email protected]127f18ec2012-06-16 05:05:59271
[email protected]b00342e7f2013-03-26 16:21:54272_VALID_OS_MACROS = (
273 # Please keep sorted.
274 'OS_ANDROID',
[email protected]f4440b42014-03-19 05:47:01275 'OS_ANDROID_HOST',
[email protected]b00342e7f2013-03-26 16:21:54276 'OS_BSD',
277 'OS_CAT', # For testing.
278 'OS_CHROMEOS',
279 'OS_FREEBSD',
280 'OS_IOS',
281 'OS_LINUX',
282 'OS_MACOSX',
283 'OS_NACL',
hidehikof7295f22014-10-28 11:57:21284 'OS_NACL_NONSFI',
285 'OS_NACL_SFI',
[email protected]b00342e7f2013-03-26 16:21:54286 'OS_OPENBSD',
287 'OS_POSIX',
[email protected]eda7afa12014-02-06 12:27:37288 'OS_QNX',
[email protected]b00342e7f2013-03-26 16:21:54289 'OS_SOLARIS',
[email protected]b00342e7f2013-03-26 16:21:54290 'OS_WIN',
291)
292
293
[email protected]55459852011-08-10 15:17:19294def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
295 """Attempts to prevent use of functions intended only for testing in
296 non-testing code. For now this is just a best-effort implementation
297 that ignores header files and may have some false positives. A
298 better implementation would probably need a proper C++ parser.
299 """
300 # We only scan .cc files and the like, as the declaration of
301 # for-testing functions in header files are hard to distinguish from
302 # calls to such functions without a proper C++ parser.
[email protected]06e6d0ff2012-12-11 01:36:44303 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
[email protected]55459852011-08-10 15:17:19304
[email protected]23501822014-05-14 02:06:09305 base_function_pattern = r'[ :]test::[^\s]+|ForTest(ing)?|for_test(ing)?'
[email protected]55459852011-08-10 15:17:19306 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
[email protected]23501822014-05-14 02:06:09307 comment_pattern = input_api.re.compile(r'//.*(%s)' % base_function_pattern)
[email protected]55459852011-08-10 15:17:19308 exclusion_pattern = input_api.re.compile(
309 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
310 base_function_pattern, base_function_pattern))
311
312 def FilterFile(affected_file):
[email protected]06e6d0ff2012-12-11 01:36:44313 black_list = (_EXCLUDED_PATHS +
314 _TEST_CODE_EXCLUDED_PATHS +
315 input_api.DEFAULT_BLACK_LIST)
[email protected]55459852011-08-10 15:17:19316 return input_api.FilterSourceFile(
317 affected_file,
318 white_list=(file_inclusion_pattern, ),
319 black_list=black_list)
320
321 problems = []
322 for f in input_api.AffectedSourceFiles(FilterFile):
323 local_path = f.LocalPath()
[email protected]825d27182014-01-02 21:24:24324 for line_number, line in f.ChangedContents():
[email protected]2fdd1f362013-01-16 03:56:03325 if (inclusion_pattern.search(line) and
[email protected]de4f7d22013-05-23 14:27:46326 not comment_pattern.search(line) and
[email protected]2fdd1f362013-01-16 03:56:03327 not exclusion_pattern.search(line)):
[email protected]55459852011-08-10 15:17:19328 problems.append(
[email protected]2fdd1f362013-01-16 03:56:03329 '%s:%d\n %s' % (local_path, line_number, line.strip()))
[email protected]55459852011-08-10 15:17:19330
331 if problems:
[email protected]f7051d52013-04-02 18:31:42332 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
[email protected]2fdd1f362013-01-16 03:56:03333 else:
334 return []
[email protected]55459852011-08-10 15:17:19335
336
[email protected]10689ca2011-09-02 02:31:54337def _CheckNoIOStreamInHeaders(input_api, output_api):
338 """Checks to make sure no .h files include <iostream>."""
339 files = []
340 pattern = input_api.re.compile(r'^#include\s*<iostream>',
341 input_api.re.MULTILINE)
342 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
343 if not f.LocalPath().endswith('.h'):
344 continue
345 contents = input_api.ReadFile(f)
346 if pattern.search(contents):
347 files.append(f)
348
349 if len(files):
350 return [ output_api.PresubmitError(
[email protected]6c063c62012-07-11 19:11:06351 'Do not #include <iostream> in header files, since it inserts static '
352 'initialization into every file including the header. Instead, '
[email protected]10689ca2011-09-02 02:31:54353 '#include <ostream>. See http://crbug.com/94794',
354 files) ]
355 return []
356
357
[email protected]72df4e782012-06-21 16:28:18358def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
359 """Checks to make sure no source files use UNIT_TEST"""
360 problems = []
361 for f in input_api.AffectedFiles():
362 if (not f.LocalPath().endswith(('.cc', '.mm'))):
363 continue
364
365 for line_num, line in f.ChangedContents():
[email protected]549f86a2013-11-19 13:00:04366 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
[email protected]72df4e782012-06-21 16:28:18367 problems.append(' %s:%d' % (f.LocalPath(), line_num))
368
369 if not problems:
370 return []
371 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
372 '\n'.join(problems))]
373
374
mcasasb7440c282015-02-04 14:52:19375def _FindHistogramNameInLine(histogram_name, line):
376 """Tries to find a histogram name or prefix in a line."""
377 if not "affected-histogram" in line:
378 return histogram_name in line
379 # A histogram_suffixes tag type has an affected-histogram name as a prefix of
380 # the histogram_name.
381 if not '"' in line:
382 return False
383 histogram_prefix = line.split('\"')[1]
384 return histogram_prefix in histogram_name
385
386
387def _CheckUmaHistogramChanges(input_api, output_api):
388 """Check that UMA histogram names in touched lines can still be found in other
389 lines of the patch or in histograms.xml. Note that this check would not catch
390 the reverse: changes in histograms.xml not matched in the code itself."""
391 touched_histograms = []
392 histograms_xml_modifications = []
393 pattern = input_api.re.compile('UMA_HISTOGRAM.*\("(.*)"')
394 for f in input_api.AffectedFiles():
395 # If histograms.xml itself is modified, keep the modified lines for later.
396 if f.LocalPath().endswith(('histograms.xml')):
397 histograms_xml_modifications = f.ChangedContents()
398 continue
399 if not f.LocalPath().endswith(('cc', 'mm', 'cpp')):
400 continue
401 for line_num, line in f.ChangedContents():
402 found = pattern.search(line)
403 if found:
404 touched_histograms.append([found.group(1), f, line_num])
405
406 # Search for the touched histogram names in the local modifications to
407 # histograms.xml, and, if not found, on the base histograms.xml file.
408 unmatched_histograms = []
409 for histogram_info in touched_histograms:
410 histogram_name_found = False
411 for line_num, line in histograms_xml_modifications:
412 histogram_name_found = _FindHistogramNameInLine(histogram_info[0], line)
413 if histogram_name_found:
414 break
415 if not histogram_name_found:
416 unmatched_histograms.append(histogram_info)
417
eromanb90c82e7e32015-04-01 15:13:49418 histograms_xml_path = 'tools/metrics/histograms/histograms.xml'
mcasasb7440c282015-02-04 14:52:19419 problems = []
420 if unmatched_histograms:
eromanb90c82e7e32015-04-01 15:13:49421 with open(histograms_xml_path) as histograms_xml:
mcasasb7440c282015-02-04 14:52:19422 for histogram_name, f, line_num in unmatched_histograms:
mcasas39c1b8b2015-02-25 15:33:45423 histograms_xml.seek(0)
mcasasb7440c282015-02-04 14:52:19424 histogram_name_found = False
425 for line in histograms_xml:
426 histogram_name_found = _FindHistogramNameInLine(histogram_name, line)
427 if histogram_name_found:
428 break
429 if not histogram_name_found:
430 problems.append(' [%s:%d] %s' %
431 (f.LocalPath(), line_num, histogram_name))
432
433 if not problems:
434 return []
435 return [output_api.PresubmitPromptWarning('Some UMA_HISTOGRAM lines have '
436 'been modified and the associated histogram name has no match in either '
eromanb90c82e7e32015-04-01 15:13:49437 '%s or the modifications of it:' % (histograms_xml_path), problems)]
mcasasb7440c282015-02-04 14:52:19438
439
[email protected]8ea5d4b2011-09-13 21:49:22440def _CheckNoNewWStrings(input_api, output_api):
441 """Checks to make sure we don't introduce use of wstrings."""
[email protected]55463aa62011-10-12 00:48:27442 problems = []
[email protected]8ea5d4b2011-09-13 21:49:22443 for f in input_api.AffectedFiles():
[email protected]b5c24292011-11-28 14:38:20444 if (not f.LocalPath().endswith(('.cc', '.h')) or
scottmge6f04402014-11-05 01:59:57445 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or
446 '/win/' in f.LocalPath()):
[email protected]b5c24292011-11-28 14:38:20447 continue
[email protected]8ea5d4b2011-09-13 21:49:22448
[email protected]a11dbe9b2012-08-07 01:32:58449 allowWString = False
[email protected]b5c24292011-11-28 14:38:20450 for line_num, line in f.ChangedContents():
[email protected]a11dbe9b2012-08-07 01:32:58451 if 'presubmit: allow wstring' in line:
452 allowWString = True
453 elif not allowWString and 'wstring' in line:
[email protected]55463aa62011-10-12 00:48:27454 problems.append(' %s:%d' % (f.LocalPath(), line_num))
[email protected]a11dbe9b2012-08-07 01:32:58455 allowWString = False
456 else:
457 allowWString = False
[email protected]8ea5d4b2011-09-13 21:49:22458
[email protected]55463aa62011-10-12 00:48:27459 if not problems:
460 return []
461 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
[email protected]a11dbe9b2012-08-07 01:32:58462 ' If you are calling a cross-platform API that accepts a wstring, '
463 'fix the API.\n' +
[email protected]55463aa62011-10-12 00:48:27464 '\n'.join(problems))]
[email protected]8ea5d4b2011-09-13 21:49:22465
466
[email protected]2a8ac9c2011-10-19 17:20:44467def _CheckNoDEPSGIT(input_api, output_api):
468 """Make sure .DEPS.git is never modified manually."""
469 if any(f.LocalPath().endswith('.DEPS.git') for f in
470 input_api.AffectedFiles()):
471 return [output_api.PresubmitError(
472 'Never commit changes to .DEPS.git. This file is maintained by an\n'
473 'automated system based on what\'s in DEPS and your changes will be\n'
474 'overwritten.\n'
[email protected]cb706912014-06-28 20:46:34475 'See https://sites.google.com/a/chromium.org/dev/developers/how-tos/get-the-code#Rolling_DEPS\n'
[email protected]2a8ac9c2011-10-19 17:20:44476 'for more information')]
477 return []
478
479
tandriief664692014-09-23 14:51:47480def _CheckValidHostsInDEPS(input_api, output_api):
481 """Checks that DEPS file deps are from allowed_hosts."""
482 # Run only if DEPS file has been modified to annoy fewer bystanders.
483 if all(f.LocalPath() != 'DEPS' for f in input_api.AffectedFiles()):
484 return []
485 # Outsource work to gclient verify
486 try:
487 input_api.subprocess.check_output(['gclient', 'verify'])
488 return []
489 except input_api.subprocess.CalledProcessError, error:
490 return [output_api.PresubmitError(
491 'DEPS file must have only git dependencies.',
492 long_text=error.output)]
493
494
[email protected]127f18ec2012-06-16 05:05:59495def _CheckNoBannedFunctions(input_api, output_api):
496 """Make sure that banned functions are not used."""
497 warnings = []
498 errors = []
499
500 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
501 for f in input_api.AffectedFiles(file_filter=file_filter):
502 for line_num, line in f.ChangedContents():
503 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
[email protected]eaae1972014-04-16 04:17:26504 matched = False
505 if func_name[0:1] == '/':
506 regex = func_name[1:]
507 if input_api.re.search(regex, line):
508 matched = True
509 elif func_name in line:
510 matched = True
511 if matched:
[email protected]127f18ec2012-06-16 05:05:59512 problems = warnings;
513 if error:
514 problems = errors;
515 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
516 for message_line in message:
517 problems.append(' %s' % message_line)
518
519 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
520 for f in input_api.AffectedFiles(file_filter=file_filter):
521 for line_num, line in f.ChangedContents():
[email protected]7345da02012-11-27 14:31:49522 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
523 def IsBlacklisted(affected_file, blacklist):
524 local_path = affected_file.LocalPath()
525 for item in blacklist:
526 if input_api.re.match(item, local_path):
527 return True
528 return False
529 if IsBlacklisted(f, excluded_paths):
530 continue
[email protected]d89eec82013-12-03 14:10:59531 matched = False
532 if func_name[0:1] == '/':
533 regex = func_name[1:]
534 if input_api.re.search(regex, line):
535 matched = True
536 elif func_name in line:
537 matched = True
538 if matched:
[email protected]127f18ec2012-06-16 05:05:59539 problems = warnings;
540 if error:
541 problems = errors;
542 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
543 for message_line in message:
544 problems.append(' %s' % message_line)
545
546 result = []
547 if (warnings):
548 result.append(output_api.PresubmitPromptWarning(
549 'Banned functions were used.\n' + '\n'.join(warnings)))
550 if (errors):
551 result.append(output_api.PresubmitError(
552 'Banned functions were used.\n' + '\n'.join(errors)))
553 return result
554
555
[email protected]6c063c62012-07-11 19:11:06556def _CheckNoPragmaOnce(input_api, output_api):
557 """Make sure that banned functions are not used."""
558 files = []
559 pattern = input_api.re.compile(r'^#pragma\s+once',
560 input_api.re.MULTILINE)
561 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
562 if not f.LocalPath().endswith('.h'):
563 continue
564 contents = input_api.ReadFile(f)
565 if pattern.search(contents):
566 files.append(f)
567
568 if files:
569 return [output_api.PresubmitError(
570 'Do not use #pragma once in header files.\n'
571 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
572 files)]
573 return []
574
[email protected]127f18ec2012-06-16 05:05:59575
[email protected]e7479052012-09-19 00:26:12576def _CheckNoTrinaryTrueFalse(input_api, output_api):
577 """Checks to make sure we don't introduce use of foo ? true : false."""
578 problems = []
579 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
580 for f in input_api.AffectedFiles():
581 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
582 continue
583
584 for line_num, line in f.ChangedContents():
585 if pattern.match(line):
586 problems.append(' %s:%d' % (f.LocalPath(), line_num))
587
588 if not problems:
589 return []
590 return [output_api.PresubmitPromptWarning(
591 'Please consider avoiding the "? true : false" pattern if possible.\n' +
592 '\n'.join(problems))]
593
594
[email protected]55f9f382012-07-31 11:02:18595def _CheckUnwantedDependencies(input_api, output_api):
596 """Runs checkdeps on #include statements added in this
597 change. Breaking - rules is an error, breaking ! rules is a
598 warning.
599 """
mohan.reddyf21db962014-10-16 12:26:47600 import sys
[email protected]55f9f382012-07-31 11:02:18601 # We need to wait until we have an input_api object and use this
602 # roundabout construct to import checkdeps because this file is
603 # eval-ed and thus doesn't have __file__.
604 original_sys_path = sys.path
605 try:
606 sys.path = sys.path + [input_api.os_path.join(
[email protected]5298cc982014-05-29 20:53:47607 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')]
[email protected]55f9f382012-07-31 11:02:18608 import checkdeps
609 from cpp_checker import CppChecker
610 from rules import Rule
611 finally:
612 # Restore sys.path to what it was before.
613 sys.path = original_sys_path
614
615 added_includes = []
616 for f in input_api.AffectedFiles():
617 if not CppChecker.IsCppFile(f.LocalPath()):
618 continue
619
620 changed_lines = [line for line_num, line in f.ChangedContents()]
621 added_includes.append([f.LocalPath(), changed_lines])
622
[email protected]26385172013-05-09 23:11:35623 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
[email protected]55f9f382012-07-31 11:02:18624
625 error_descriptions = []
626 warning_descriptions = []
627 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
628 added_includes):
629 description_with_path = '%s\n %s' % (path, rule_description)
630 if rule_type == Rule.DISALLOW:
631 error_descriptions.append(description_with_path)
632 else:
633 warning_descriptions.append(description_with_path)
634
635 results = []
636 if error_descriptions:
637 results.append(output_api.PresubmitError(
638 'You added one or more #includes that violate checkdeps rules.',
639 error_descriptions))
640 if warning_descriptions:
[email protected]f7051d52013-04-02 18:31:42641 results.append(output_api.PresubmitPromptOrNotify(
[email protected]55f9f382012-07-31 11:02:18642 'You added one or more #includes of files that are temporarily\n'
643 'allowed but being removed. Can you avoid introducing the\n'
644 '#include? See relevant DEPS file(s) for details and contacts.',
645 warning_descriptions))
646 return results
647
648
[email protected]fbcafe5a2012-08-08 15:31:22649def _CheckFilePermissions(input_api, output_api):
650 """Check that all files have their permissions properly set."""
[email protected]791507202014-02-03 23:19:15651 if input_api.platform == 'win32':
652 return []
mohan.reddyf21db962014-10-16 12:26:47653 args = [input_api.python_executable, 'tools/checkperms/checkperms.py',
654 '--root', input_api.change.RepositoryRoot()]
[email protected]fbcafe5a2012-08-08 15:31:22655 for f in input_api.AffectedFiles():
656 args += ['--file', f.LocalPath()]
[email protected]f0d330f2014-01-30 01:44:34657 checkperms = input_api.subprocess.Popen(args,
658 stdout=input_api.subprocess.PIPE)
659 errors = checkperms.communicate()[0].strip()
[email protected]fbcafe5a2012-08-08 15:31:22660 if errors:
[email protected]f0d330f2014-01-30 01:44:34661 return [output_api.PresubmitError('checkperms.py failed.',
662 errors.splitlines())]
663 return []
[email protected]fbcafe5a2012-08-08 15:31:22664
665
[email protected]c8278b32012-10-30 20:35:49666def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
667 """Makes sure we don't include ui/aura/window_property.h
668 in header files.
669 """
670 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
671 errors = []
672 for f in input_api.AffectedFiles():
673 if not f.LocalPath().endswith('.h'):
674 continue
675 for line_num, line in f.ChangedContents():
676 if pattern.match(line):
677 errors.append(' %s:%d' % (f.LocalPath(), line_num))
678
679 results = []
680 if errors:
681 results.append(output_api.PresubmitError(
682 'Header files should not include ui/aura/window_property.h', errors))
683 return results
684
685
[email protected]cf9b78f2012-11-14 11:40:28686def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
687 """Checks that the lines in scope occur in the right order.
688
689 1. C system files in alphabetical order
690 2. C++ system files in alphabetical order
691 3. Project's .h files
692 """
693
694 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
695 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
696 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
697
698 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
699
700 state = C_SYSTEM_INCLUDES
701
702 previous_line = ''
[email protected]728b9bb2012-11-14 20:38:57703 previous_line_num = 0
[email protected]cf9b78f2012-11-14 11:40:28704 problem_linenums = []
705 for line_num, line in scope:
706 if c_system_include_pattern.match(line):
707 if state != C_SYSTEM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57708 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28709 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57710 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28711 elif cpp_system_include_pattern.match(line):
712 if state == C_SYSTEM_INCLUDES:
713 state = CPP_SYSTEM_INCLUDES
714 elif state == CUSTOM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57715 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28716 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57717 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28718 elif custom_include_pattern.match(line):
719 if state != CUSTOM_INCLUDES:
720 state = CUSTOM_INCLUDES
721 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57722 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28723 else:
724 problem_linenums.append(line_num)
725 previous_line = line
[email protected]728b9bb2012-11-14 20:38:57726 previous_line_num = line_num
[email protected]cf9b78f2012-11-14 11:40:28727
728 warnings = []
[email protected]728b9bb2012-11-14 20:38:57729 for (line_num, previous_line_num) in problem_linenums:
730 if line_num in changed_linenums or previous_line_num in changed_linenums:
[email protected]cf9b78f2012-11-14 11:40:28731 warnings.append(' %s:%d' % (file_path, line_num))
732 return warnings
733
734
[email protected]ac294a12012-12-06 16:38:43735def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
[email protected]cf9b78f2012-11-14 11:40:28736 """Checks the #include order for the given file f."""
737
[email protected]2299dcf2012-11-15 19:56:24738 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
[email protected]23093b62013-09-20 12:16:30739 # Exclude the following includes from the check:
740 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
741 # specific order.
742 # 2) <atlbase.h>, "build/build_config.h"
743 excluded_include_pattern = input_api.re.compile(
744 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
[email protected]2299dcf2012-11-15 19:56:24745 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
[email protected]3e83618c2013-10-09 22:32:33746 # Match the final or penultimate token if it is xxxtest so we can ignore it
747 # when considering the special first include.
748 test_file_tag_pattern = input_api.re.compile(
749 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
[email protected]0e5c1852012-12-18 20:17:11750 if_pattern = input_api.re.compile(
751 r'\s*#\s*(if|elif|else|endif|define|undef).*')
752 # Some files need specialized order of includes; exclude such files from this
753 # check.
754 uncheckable_includes_pattern = input_api.re.compile(
755 r'\s*#include '
756 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
[email protected]cf9b78f2012-11-14 11:40:28757
758 contents = f.NewContents()
759 warnings = []
760 line_num = 0
761
[email protected]ac294a12012-12-06 16:38:43762 # Handle the special first include. If the first include file is
763 # some/path/file.h, the corresponding including file can be some/path/file.cc,
764 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
765 # etc. It's also possible that no special first include exists.
[email protected]3e83618c2013-10-09 22:32:33766 # If the included file is some/path/file_platform.h the including file could
767 # also be some/path/file_xxxtest_platform.h.
768 including_file_base_name = test_file_tag_pattern.sub(
769 '', input_api.os_path.basename(f.LocalPath()))
770
[email protected]ac294a12012-12-06 16:38:43771 for line in contents:
772 line_num += 1
773 if system_include_pattern.match(line):
774 # No special first include -> process the line again along with normal
775 # includes.
776 line_num -= 1
777 break
778 match = custom_include_pattern.match(line)
779 if match:
780 match_dict = match.groupdict()
[email protected]3e83618c2013-10-09 22:32:33781 header_basename = test_file_tag_pattern.sub(
782 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
783
784 if header_basename not in including_file_base_name:
[email protected]2299dcf2012-11-15 19:56:24785 # No special first include -> process the line again along with normal
786 # includes.
787 line_num -= 1
[email protected]ac294a12012-12-06 16:38:43788 break
[email protected]cf9b78f2012-11-14 11:40:28789
790 # Split into scopes: Each region between #if and #endif is its own scope.
791 scopes = []
792 current_scope = []
793 for line in contents[line_num:]:
794 line_num += 1
[email protected]0e5c1852012-12-18 20:17:11795 if uncheckable_includes_pattern.match(line):
[email protected]4436c9e2014-01-07 23:19:54796 continue
[email protected]2309b0fa02012-11-16 12:18:27797 if if_pattern.match(line):
[email protected]cf9b78f2012-11-14 11:40:28798 scopes.append(current_scope)
799 current_scope = []
[email protected]962f117e2012-11-22 18:11:56800 elif ((system_include_pattern.match(line) or
801 custom_include_pattern.match(line)) and
802 not excluded_include_pattern.match(line)):
[email protected]cf9b78f2012-11-14 11:40:28803 current_scope.append((line_num, line))
804 scopes.append(current_scope)
805
806 for scope in scopes:
807 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
808 changed_linenums))
809 return warnings
810
811
812def _CheckIncludeOrder(input_api, output_api):
813 """Checks that the #include order is correct.
814
815 1. The corresponding header for source files.
816 2. C system files in alphabetical order
817 3. C++ system files in alphabetical order
818 4. Project's .h files in alphabetical order
819
[email protected]ac294a12012-12-06 16:38:43820 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
821 these rules separately.
[email protected]cf9b78f2012-11-14 11:40:28822 """
[email protected]e120b012014-08-15 19:08:35823 def FileFilterIncludeOrder(affected_file):
824 black_list = (_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST)
825 return input_api.FilterSourceFile(affected_file, black_list=black_list)
[email protected]cf9b78f2012-11-14 11:40:28826
827 warnings = []
[email protected]e120b012014-08-15 19:08:35828 for f in input_api.AffectedFiles(file_filter=FileFilterIncludeOrder):
tapted574f09c2015-05-19 13:08:08829 if f.LocalPath().endswith(('.cc', '.h', '.mm')):
[email protected]ac294a12012-12-06 16:38:43830 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
831 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
[email protected]cf9b78f2012-11-14 11:40:28832
833 results = []
834 if warnings:
[email protected]f7051d52013-04-02 18:31:42835 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
[email protected]120cf540d2012-12-10 17:55:53836 warnings))
[email protected]cf9b78f2012-11-14 11:40:28837 return results
838
839
[email protected]70ca77752012-11-20 03:45:03840def _CheckForVersionControlConflictsInFile(input_api, f):
841 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
842 errors = []
843 for line_num, line in f.ChangedContents():
dbeam95c35a2f2015-06-02 01:40:23844 if f.LocalPath().endswith('.md'):
845 # First-level headers in markdown look a lot like version control
846 # conflict markers. http://daringfireball.net/projects/markdown/basics
847 continue
[email protected]70ca77752012-11-20 03:45:03848 if pattern.match(line):
849 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
850 return errors
851
852
853def _CheckForVersionControlConflicts(input_api, output_api):
854 """Usually this is not intentional and will cause a compile failure."""
855 errors = []
856 for f in input_api.AffectedFiles():
857 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
858
859 results = []
860 if errors:
861 results.append(output_api.PresubmitError(
862 'Version control conflict markers found, please resolve.', errors))
863 return results
864
865
[email protected]06e6d0ff2012-12-11 01:36:44866def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
867 def FilterFile(affected_file):
868 """Filter function for use with input_api.AffectedSourceFiles,
869 below. This filters out everything except non-test files from
870 top-level directories that generally speaking should not hard-code
871 service URLs (e.g. src/android_webview/, src/content/ and others).
872 """
873 return input_api.FilterSourceFile(
874 affected_file,
[email protected]78bb39d62012-12-11 15:11:56875 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
[email protected]06e6d0ff2012-12-11 01:36:44876 black_list=(_EXCLUDED_PATHS +
877 _TEST_CODE_EXCLUDED_PATHS +
878 input_api.DEFAULT_BLACK_LIST))
879
[email protected]de4f7d22013-05-23 14:27:46880 base_pattern = '"[^"]*google\.com[^"]*"'
881 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
882 pattern = input_api.re.compile(base_pattern)
[email protected]06e6d0ff2012-12-11 01:36:44883 problems = [] # items are (filename, line_number, line)
884 for f in input_api.AffectedSourceFiles(FilterFile):
885 for line_num, line in f.ChangedContents():
[email protected]de4f7d22013-05-23 14:27:46886 if not comment_pattern.search(line) and pattern.search(line):
[email protected]06e6d0ff2012-12-11 01:36:44887 problems.append((f.LocalPath(), line_num, line))
888
889 if problems:
[email protected]f7051d52013-04-02 18:31:42890 return [output_api.PresubmitPromptOrNotify(
[email protected]06e6d0ff2012-12-11 01:36:44891 'Most layers below src/chrome/ should not hardcode service URLs.\n'
[email protected]b0149772014-03-27 16:47:58892 'Are you sure this is correct?',
[email protected]06e6d0ff2012-12-11 01:36:44893 [' %s:%d: %s' % (
894 problem[0], problem[1], problem[2]) for problem in problems])]
[email protected]2fdd1f362013-01-16 03:56:03895 else:
896 return []
[email protected]06e6d0ff2012-12-11 01:36:44897
898
[email protected]d2530012013-01-25 16:39:27899def _CheckNoAbbreviationInPngFileName(input_api, output_api):
900 """Makes sure there are no abbreviations in the name of PNG files.
binji0dcdf342014-12-12 18:32:31901 The native_client_sdk directory is excluded because it has auto-generated PNG
902 files for documentation.
[email protected]d2530012013-01-25 16:39:27903 """
[email protected]d2530012013-01-25 16:39:27904 errors = []
binji0dcdf342014-12-12 18:32:31905 white_list = (r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$',)
906 black_list = (r'^native_client_sdk[\\\/]',)
907 file_filter = lambda f: input_api.FilterSourceFile(
908 f, white_list=white_list, black_list=black_list)
909 for f in input_api.AffectedFiles(include_deletes=False,
910 file_filter=file_filter):
911 errors.append(' %s' % f.LocalPath())
[email protected]d2530012013-01-25 16:39:27912
913 results = []
914 if errors:
915 results.append(output_api.PresubmitError(
916 'The name of PNG files should not have abbreviations. \n'
917 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
918 'Contact [email protected] if you have questions.', errors))
919 return results
920
921
[email protected]14a6131c2014-01-08 01:15:41922def _FilesToCheckForIncomingDeps(re, changed_lines):
[email protected]f32e2d1e2013-07-26 21:39:08923 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
[email protected]14a6131c2014-01-08 01:15:41924 a set of DEPS entries that we should look up.
925
926 For a directory (rather than a specific filename) we fake a path to
927 a specific filename by adding /DEPS. This is chosen as a file that
928 will seldom or never be subject to per-file include_rules.
929 """
[email protected]2b438d62013-11-14 17:54:14930 # We ignore deps entries on auto-generated directories.
931 AUTO_GENERATED_DIRS = ['grit', 'jni']
[email protected]f32e2d1e2013-07-26 21:39:08932
933 # This pattern grabs the path without basename in the first
934 # parentheses, and the basename (if present) in the second. It
935 # relies on the simple heuristic that if there is a basename it will
936 # be a header file ending in ".h".
937 pattern = re.compile(
938 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
[email protected]2b438d62013-11-14 17:54:14939 results = set()
[email protected]f32e2d1e2013-07-26 21:39:08940 for changed_line in changed_lines:
941 m = pattern.match(changed_line)
942 if m:
943 path = m.group(1)
[email protected]2b438d62013-11-14 17:54:14944 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
[email protected]14a6131c2014-01-08 01:15:41945 if m.group(2):
946 results.add('%s%s' % (path, m.group(2)))
947 else:
948 results.add('%s/DEPS' % path)
[email protected]f32e2d1e2013-07-26 21:39:08949 return results
950
951
[email protected]e871964c2013-05-13 14:14:55952def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
953 """When a dependency prefixed with + is added to a DEPS file, we
954 want to make sure that the change is reviewed by an OWNER of the
955 target file or directory, to avoid layering violations from being
956 introduced. This check verifies that this happens.
957 """
958 changed_lines = set()
959 for f in input_api.AffectedFiles():
960 filename = input_api.os_path.basename(f.LocalPath())
961 if filename == 'DEPS':
962 changed_lines |= set(line.strip()
963 for line_num, line
964 in f.ChangedContents())
965 if not changed_lines:
966 return []
967
[email protected]14a6131c2014-01-08 01:15:41968 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
969 changed_lines)
[email protected]e871964c2013-05-13 14:14:55970 if not virtual_depended_on_files:
971 return []
972
973 if input_api.is_committing:
974 if input_api.tbr:
975 return [output_api.PresubmitNotifyResult(
976 '--tbr was specified, skipping OWNERS check for DEPS additions')]
977 if not input_api.change.issue:
978 return [output_api.PresubmitError(
979 "DEPS approval by OWNERS check failed: this change has "
980 "no Rietveld issue number, so we can't check it for approvals.")]
981 output = output_api.PresubmitError
982 else:
983 output = output_api.PresubmitNotifyResult
984
985 owners_db = input_api.owners_db
986 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
987 input_api,
988 owners_db.email_regexp,
989 approval_needed=input_api.is_committing)
990
991 owner_email = owner_email or input_api.change.author_email
992
[email protected]de4f7d22013-05-23 14:27:46993 reviewers_plus_owner = set(reviewers)
[email protected]e71c6082013-05-22 02:28:51994 if owner_email:
[email protected]de4f7d22013-05-23 14:27:46995 reviewers_plus_owner.add(owner_email)
[email protected]e871964c2013-05-13 14:14:55996 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
997 reviewers_plus_owner)
[email protected]14a6131c2014-01-08 01:15:41998
999 # We strip the /DEPS part that was added by
1000 # _FilesToCheckForIncomingDeps to fake a path to a file in a
1001 # directory.
1002 def StripDeps(path):
1003 start_deps = path.rfind('/DEPS')
1004 if start_deps != -1:
1005 return path[:start_deps]
1006 else:
1007 return path
1008 unapproved_dependencies = ["'+%s'," % StripDeps(path)
[email protected]e871964c2013-05-13 14:14:551009 for path in missing_files]
1010
1011 if unapproved_dependencies:
1012 output_list = [
[email protected]14a6131c2014-01-08 01:15:411013 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
[email protected]e871964c2013-05-13 14:14:551014 '\n '.join(sorted(unapproved_dependencies)))]
1015 if not input_api.is_committing:
1016 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
1017 output_list.append(output(
1018 'Suggested missing target path OWNERS:\n %s' %
1019 '\n '.join(suggested_owners or [])))
1020 return output_list
1021
1022 return []
1023
1024
[email protected]85218562013-11-22 07:41:401025def _CheckSpamLogging(input_api, output_api):
1026 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
1027 black_list = (_EXCLUDED_PATHS +
1028 _TEST_CODE_EXCLUDED_PATHS +
1029 input_api.DEFAULT_BLACK_LIST +
[email protected]6f742dd02013-11-26 23:19:501030 (r"^base[\\\/]logging\.h$",
[email protected]80f360a2014-01-23 01:36:191031 r"^base[\\\/]logging\.cc$",
[email protected]8dc338c2013-12-09 16:28:481032 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
[email protected]6e268db2013-12-04 01:41:461033 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
[email protected]4de75262013-12-18 23:16:121034 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
1035 r"startup_browser_creator\.cc$",
[email protected]fe0e6e12013-12-04 05:52:581036 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
[email protected]8cf6f842014-08-08 21:33:161037 r"chrome[\\\/]browser[\\\/]diagnostics[\\\/]" +
[email protected]f5b9a3f342014-08-08 22:06:031038 r"diagnostics_writer\.cc$",
[email protected]9f13b602014-08-07 02:59:151039 r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
1040 r"^chromecast[\\\/]",
1041 r"^cloud_print[\\\/]",
[email protected]9056e732014-01-08 06:25:251042 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
1043 r"gl_helper_benchmark\.cc$",
thestigc9e38a22014-09-13 01:02:111044 r"^courgette[\\\/]courgette_tool\.cc$",
[email protected]9f13b602014-08-07 02:59:151045 r"^extensions[\\\/]renderer[\\\/]logging_native_handler\.cc$",
prashant.nb0252f62014-11-08 05:02:111046 r"^ipc[\\\/]ipc_logging\.cc$",
[email protected]9c36d922014-03-24 16:47:521047 r"^native_client_sdk[\\\/]",
[email protected]cdbdced2013-11-27 21:35:501048 r"^remoting[\\\/]base[\\\/]logging\.h$",
[email protected]67c96ab2013-12-17 02:05:361049 r"^remoting[\\\/]host[\\\/].*",
[email protected]8232f8fd2013-12-14 00:52:311050 r"^sandbox[\\\/]linux[\\\/].*",
[email protected]0b7a21e2014-02-11 18:38:131051 r"^tools[\\\/]",
thestig22dfc4012014-09-05 08:29:441052 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",
vchigrin14251492015-01-12 08:09:021053 r"^storage[\\\/]browser[\\\/]fileapi[\\\/]" +
thestig22dfc4012014-09-05 08:29:441054 r"dump_file_system.cc$",))
[email protected]85218562013-11-22 07:41:401055 source_file_filter = lambda x: input_api.FilterSourceFile(
1056 x, white_list=(file_inclusion_pattern,), black_list=black_list)
1057
1058 log_info = []
1059 printf = []
1060
1061 for f in input_api.AffectedSourceFiles(source_file_filter):
1062 contents = input_api.ReadFile(f, 'rb')
mohan.reddyf21db962014-10-16 12:26:471063 if input_api.re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
[email protected]85218562013-11-22 07:41:401064 log_info.append(f.LocalPath())
mohan.reddyf21db962014-10-16 12:26:471065 elif input_api.re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
[email protected]85210652013-11-28 05:50:131066 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:371067
mohan.reddyf21db962014-10-16 12:26:471068 if input_api.re.search(r"\bprintf\(", contents):
[email protected]18b466b2013-12-02 22:01:371069 printf.append(f.LocalPath())
mohan.reddyf21db962014-10-16 12:26:471070 elif input_api.re.search(r"\bfprintf\((stdout|stderr)", contents):
[email protected]85218562013-11-22 07:41:401071 printf.append(f.LocalPath())
1072
1073 if log_info:
1074 return [output_api.PresubmitError(
1075 'These files spam the console log with LOG(INFO):',
1076 items=log_info)]
1077 if printf:
1078 return [output_api.PresubmitError(
1079 'These files spam the console log with printf/fprintf:',
1080 items=printf)]
1081 return []
1082
1083
[email protected]49aa76a2013-12-04 06:59:161084def _CheckForAnonymousVariables(input_api, output_api):
1085 """These types are all expected to hold locks while in scope and
1086 so should never be anonymous (which causes them to be immediately
1087 destroyed)."""
1088 they_who_must_be_named = [
1089 'base::AutoLock',
1090 'base::AutoReset',
1091 'base::AutoUnlock',
1092 'SkAutoAlphaRestore',
1093 'SkAutoBitmapShaderInstall',
1094 'SkAutoBlitterChoose',
1095 'SkAutoBounderCommit',
1096 'SkAutoCallProc',
1097 'SkAutoCanvasRestore',
1098 'SkAutoCommentBlock',
1099 'SkAutoDescriptor',
1100 'SkAutoDisableDirectionCheck',
1101 'SkAutoDisableOvalCheck',
1102 'SkAutoFree',
1103 'SkAutoGlyphCache',
1104 'SkAutoHDC',
1105 'SkAutoLockColors',
1106 'SkAutoLockPixels',
1107 'SkAutoMalloc',
1108 'SkAutoMaskFreeImage',
1109 'SkAutoMutexAcquire',
1110 'SkAutoPathBoundsUpdate',
1111 'SkAutoPDFRelease',
1112 'SkAutoRasterClipValidate',
1113 'SkAutoRef',
1114 'SkAutoTime',
1115 'SkAutoTrace',
1116 'SkAutoUnref',
1117 ]
1118 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
1119 # bad: base::AutoLock(lock.get());
1120 # not bad: base::AutoLock lock(lock.get());
1121 bad_pattern = input_api.re.compile(anonymous)
1122 # good: new base::AutoLock(lock.get())
1123 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
1124 errors = []
1125
1126 for f in input_api.AffectedFiles():
1127 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
1128 continue
1129 for linenum, line in f.ChangedContents():
1130 if bad_pattern.search(line) and not good_pattern.search(line):
1131 errors.append('%s:%d' % (f.LocalPath(), linenum))
1132
1133 if errors:
1134 return [output_api.PresubmitError(
1135 'These lines create anonymous variables that need to be named:',
1136 items=errors)]
1137 return []
1138
1139
[email protected]5fe0f8742013-11-29 01:04:591140def _CheckCygwinShell(input_api, output_api):
1141 source_file_filter = lambda x: input_api.FilterSourceFile(
1142 x, white_list=(r'.+\.(gyp|gypi)$',))
1143 cygwin_shell = []
1144
1145 for f in input_api.AffectedSourceFiles(source_file_filter):
1146 for linenum, line in f.ChangedContents():
1147 if 'msvs_cygwin_shell' in line:
1148 cygwin_shell.append(f.LocalPath())
1149 break
1150
1151 if cygwin_shell:
1152 return [output_api.PresubmitError(
1153 'These files should not use msvs_cygwin_shell (the default is 0):',
1154 items=cygwin_shell)]
1155 return []
1156
[email protected]85218562013-11-22 07:41:401157
[email protected]999261d2014-03-03 20:08:081158def _CheckUserActionUpdate(input_api, output_api):
1159 """Checks if any new user action has been added."""
[email protected]2f92dec2014-03-07 19:21:521160 if any('actions.xml' == input_api.os_path.basename(f) for f in
[email protected]999261d2014-03-03 20:08:081161 input_api.LocalPaths()):
[email protected]2f92dec2014-03-07 19:21:521162 # If actions.xml is already included in the changelist, the PRESUBMIT
1163 # for actions.xml will do a more complete presubmit check.
[email protected]999261d2014-03-03 20:08:081164 return []
1165
[email protected]999261d2014-03-03 20:08:081166 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm'))
1167 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)'
[email protected]2f92dec2014-03-07 19:21:521168 current_actions = None
[email protected]999261d2014-03-03 20:08:081169 for f in input_api.AffectedFiles(file_filter=file_filter):
1170 for line_num, line in f.ChangedContents():
1171 match = input_api.re.search(action_re, line)
1172 if match:
[email protected]2f92dec2014-03-07 19:21:521173 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1174 # loaded only once.
1175 if not current_actions:
1176 with open('tools/metrics/actions/actions.xml') as actions_f:
1177 current_actions = actions_f.read()
1178 # Search for the matched user action name in |current_actions|.
[email protected]999261d2014-03-03 20:08:081179 for action_name in match.groups():
[email protected]2f92dec2014-03-07 19:21:521180 action = 'name="{0}"'.format(action_name)
1181 if action not in current_actions:
[email protected]999261d2014-03-03 20:08:081182 return [output_api.PresubmitPromptWarning(
1183 'File %s line %d: %s is missing in '
[email protected]2f92dec2014-03-07 19:21:521184 'tools/metrics/actions/actions.xml. Please run '
1185 'tools/metrics/actions/extract_actions.py to update.'
[email protected]999261d2014-03-03 20:08:081186 % (f.LocalPath(), line_num, action_name))]
1187 return []
1188
1189
[email protected]99171a92014-06-03 08:44:471190def _GetJSONParseError(input_api, filename, eat_comments=True):
1191 try:
1192 contents = input_api.ReadFile(filename)
1193 if eat_comments:
1194 json_comment_eater = input_api.os_path.join(
1195 input_api.PresubmitLocalPath(),
1196 'tools', 'json_comment_eater', 'json_comment_eater.py')
1197 process = input_api.subprocess.Popen(
1198 [input_api.python_executable, json_comment_eater],
1199 stdin=input_api.subprocess.PIPE,
1200 stdout=input_api.subprocess.PIPE,
1201 universal_newlines=True)
1202 (contents, _) = process.communicate(input=contents)
1203
1204 input_api.json.loads(contents)
1205 except ValueError as e:
1206 return e
1207 return None
1208
1209
1210def _GetIDLParseError(input_api, filename):
1211 try:
1212 contents = input_api.ReadFile(filename)
1213 idl_schema = input_api.os_path.join(
1214 input_api.PresubmitLocalPath(),
1215 'tools', 'json_schema_compiler', 'idl_schema.py')
1216 process = input_api.subprocess.Popen(
1217 [input_api.python_executable, idl_schema],
1218 stdin=input_api.subprocess.PIPE,
1219 stdout=input_api.subprocess.PIPE,
1220 stderr=input_api.subprocess.PIPE,
1221 universal_newlines=True)
1222 (_, error) = process.communicate(input=contents)
1223 return error or None
1224 except ValueError as e:
1225 return e
1226
1227
1228def _CheckParseErrors(input_api, output_api):
1229 """Check that IDL and JSON files do not contain syntax errors."""
1230 actions = {
1231 '.idl': _GetIDLParseError,
1232 '.json': _GetJSONParseError,
1233 }
1234 # These paths contain test data and other known invalid JSON files.
1235 excluded_patterns = [
joaodasilva718f87672014-08-30 09:25:491236 r'test[\\\/]data[\\\/]',
1237 r'^components[\\\/]policy[\\\/]resources[\\\/]policy_templates\.json$',
[email protected]99171a92014-06-03 08:44:471238 ]
1239 # Most JSON files are preprocessed and support comments, but these do not.
1240 json_no_comments_patterns = [
joaodasilva718f87672014-08-30 09:25:491241 r'^testing[\\\/]',
[email protected]99171a92014-06-03 08:44:471242 ]
1243 # Only run IDL checker on files in these directories.
1244 idl_included_patterns = [
joaodasilva718f87672014-08-30 09:25:491245 r'^chrome[\\\/]common[\\\/]extensions[\\\/]api[\\\/]',
1246 r'^extensions[\\\/]common[\\\/]api[\\\/]',
[email protected]99171a92014-06-03 08:44:471247 ]
1248
1249 def get_action(affected_file):
1250 filename = affected_file.LocalPath()
1251 return actions.get(input_api.os_path.splitext(filename)[1])
1252
1253 def MatchesFile(patterns, path):
1254 for pattern in patterns:
1255 if input_api.re.search(pattern, path):
1256 return True
1257 return False
1258
1259 def FilterFile(affected_file):
1260 action = get_action(affected_file)
1261 if not action:
1262 return False
1263 path = affected_file.LocalPath()
1264
1265 if MatchesFile(excluded_patterns, path):
1266 return False
1267
1268 if (action == _GetIDLParseError and
1269 not MatchesFile(idl_included_patterns, path)):
1270 return False
1271 return True
1272
1273 results = []
1274 for affected_file in input_api.AffectedFiles(
1275 file_filter=FilterFile, include_deletes=False):
1276 action = get_action(affected_file)
1277 kwargs = {}
1278 if (action == _GetJSONParseError and
1279 MatchesFile(json_no_comments_patterns, affected_file.LocalPath())):
1280 kwargs['eat_comments'] = False
1281 parse_error = action(input_api,
1282 affected_file.AbsoluteLocalPath(),
1283 **kwargs)
1284 if parse_error:
1285 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
1286 (affected_file.LocalPath(), parse_error)))
1287 return results
1288
1289
[email protected]760deea2013-12-10 19:33:491290def _CheckJavaStyle(input_api, output_api):
1291 """Runs checkstyle on changed java files and returns errors if any exist."""
mohan.reddyf21db962014-10-16 12:26:471292 import sys
[email protected]760deea2013-12-10 19:33:491293 original_sys_path = sys.path
1294 try:
1295 sys.path = sys.path + [input_api.os_path.join(
1296 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1297 import checkstyle
1298 finally:
1299 # Restore sys.path to what it was before.
1300 sys.path = original_sys_path
1301
1302 return checkstyle.RunCheckstyle(
davileen72d76532015-01-20 22:30:091303 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml',
newtd8b7d30e92015-01-23 18:10:511304 black_list=_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST)
[email protected]760deea2013-12-10 19:33:491305
1306
dgn4401aa52015-04-29 16:26:171307def _CheckNoNewUtilLogUsage(input_api, output_api):
1308 """Checks that new logs are using org.chromium.base.Log."""
1309
1310 chromium_log_import_pattern = input_api.re.compile(
1311 r'^import org\.chromium\.base\.Log;$', input_api.re.MULTILINE);
1312 log_pattern = input_api.re.compile(r'^\s*(android\.util\.)?Log\.\w')
1313 sources = lambda x: input_api.FilterSourceFile(x, white_list=(r'.*\.java$',))
1314
1315 errors = []
1316
1317 for f in input_api.AffectedSourceFiles(sources):
1318 if chromium_log_import_pattern.search(input_api.ReadFile(f)) is not None:
1319 # Uses org.chromium.base.Log already
1320 continue
1321
1322 for line_num, line in f.ChangedContents():
1323 if log_pattern.search(line):
1324 errors.append("%s:%d" % (f.LocalPath(), line_num))
1325
1326 results = []
1327 if len(errors):
1328 results.append(output_api.PresubmitPromptWarning(
1329 'Please use org.chromium.base.Log for new logs.\n' +
1330 'See base/android/java/src/org/chromium/base/README_logging.md ' +
1331 'or contact [email protected] for more info.',
1332 errors))
1333 return results
1334
1335
mnaganov9b9b1fe82014-12-11 16:30:361336def _CheckForCopyrightedCode(input_api, output_api):
1337 """Verifies that newly added code doesn't contain copyrighted material
1338 and is properly licensed under the standard Chromium license.
1339
1340 As there can be false positives, we maintain a whitelist file. This check
1341 also verifies that the whitelist file is up to date.
1342 """
1343 import sys
1344 original_sys_path = sys.path
1345 try:
1346 sys.path = sys.path + [input_api.os_path.join(
1347 input_api.PresubmitLocalPath(), 'android_webview', 'tools')]
1348 import copyright_scanner
1349 finally:
1350 # Restore sys.path to what it was before.
1351 sys.path = original_sys_path
1352
1353 return copyright_scanner.ScanAtPresubmit(input_api, output_api)
1354
1355
glidere61efad2015-02-18 17:39:431356def _CheckSingletonInHeaders(input_api, output_api):
1357 """Checks to make sure no header files have |Singleton<|."""
1358 def FileFilter(affected_file):
1359 # It's ok for base/memory/singleton.h to have |Singleton<|.
1360 black_list = (_EXCLUDED_PATHS +
1361 input_api.DEFAULT_BLACK_LIST +
1362 (r"^base[\\\/]memory[\\\/]singleton\.h$",))
1363 return input_api.FilterSourceFile(affected_file, black_list=black_list)
1364
1365 pattern = input_api.re.compile(r'(?<!class\s)Singleton\s*<')
1366 files = []
1367 for f in input_api.AffectedSourceFiles(FileFilter):
1368 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
1369 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
1370 contents = input_api.ReadFile(f)
1371 for line in contents.splitlines(False):
1372 if (not input_api.re.match(r'//', line) and # Strip C++ comment.
1373 pattern.search(line)):
1374 files.append(f)
1375 break
1376
1377 if files:
1378 return [ output_api.PresubmitError(
1379 'Found Singleton<T> in the following header files.\n' +
1380 'Please move them to an appropriate source file so that the ' +
1381 'template gets instantiated in a single compilation unit.',
1382 files) ]
1383 return []
1384
1385
[email protected]fd20b902014-05-09 02:14:531386_DEPRECATED_CSS = [
1387 # Values
1388 ( "-webkit-box", "flex" ),
1389 ( "-webkit-inline-box", "inline-flex" ),
1390 ( "-webkit-flex", "flex" ),
1391 ( "-webkit-inline-flex", "inline-flex" ),
1392 ( "-webkit-min-content", "min-content" ),
1393 ( "-webkit-max-content", "max-content" ),
1394
1395 # Properties
1396 ( "-webkit-background-clip", "background-clip" ),
1397 ( "-webkit-background-origin", "background-origin" ),
1398 ( "-webkit-background-size", "background-size" ),
1399 ( "-webkit-box-shadow", "box-shadow" ),
1400
1401 # Functions
1402 ( "-webkit-gradient", "gradient" ),
1403 ( "-webkit-repeating-gradient", "repeating-gradient" ),
1404 ( "-webkit-linear-gradient", "linear-gradient" ),
1405 ( "-webkit-repeating-linear-gradient", "repeating-linear-gradient" ),
1406 ( "-webkit-radial-gradient", "radial-gradient" ),
1407 ( "-webkit-repeating-radial-gradient", "repeating-radial-gradient" ),
1408]
1409
1410def _CheckNoDeprecatedCSS(input_api, output_api):
1411 """ Make sure that we don't use deprecated CSS
[email protected]9a48e3f82014-05-22 00:06:251412 properties, functions or values. Our external
1413 documentation is ignored by the hooks as it
1414 needs to be consumed by WebKit. """
[email protected]fd20b902014-05-09 02:14:531415 results = []
dbeam070cfe62014-10-22 06:44:021416 file_inclusion_pattern = (r".+\.css$",)
[email protected]9a48e3f82014-05-22 00:06:251417 black_list = (_EXCLUDED_PATHS +
1418 _TEST_CODE_EXCLUDED_PATHS +
1419 input_api.DEFAULT_BLACK_LIST +
1420 (r"^chrome/common/extensions/docs",
1421 r"^chrome/docs",
1422 r"^native_client_sdk"))
1423 file_filter = lambda f: input_api.FilterSourceFile(
1424 f, white_list=file_inclusion_pattern, black_list=black_list)
[email protected]fd20b902014-05-09 02:14:531425 for fpath in input_api.AffectedFiles(file_filter=file_filter):
1426 for line_num, line in fpath.ChangedContents():
1427 for (deprecated_value, value) in _DEPRECATED_CSS:
dbeam070cfe62014-10-22 06:44:021428 if deprecated_value in line:
[email protected]fd20b902014-05-09 02:14:531429 results.append(output_api.PresubmitError(
1430 "%s:%d: Use of deprecated CSS %s, use %s instead" %
1431 (fpath.LocalPath(), line_num, deprecated_value, value)))
1432 return results
1433
mohan.reddyf21db962014-10-16 12:26:471434
dbeam070cfe62014-10-22 06:44:021435_DEPRECATED_JS = [
1436 ( "__lookupGetter__", "Object.getOwnPropertyDescriptor" ),
1437 ( "__defineGetter__", "Object.defineProperty" ),
1438 ( "__defineSetter__", "Object.defineProperty" ),
1439]
1440
1441def _CheckNoDeprecatedJS(input_api, output_api):
1442 """Make sure that we don't use deprecated JS in Chrome code."""
1443 results = []
1444 file_inclusion_pattern = (r".+\.js$",) # TODO(dbeam): .html?
1445 black_list = (_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS +
1446 input_api.DEFAULT_BLACK_LIST)
1447 file_filter = lambda f: input_api.FilterSourceFile(
1448 f, white_list=file_inclusion_pattern, black_list=black_list)
1449 for fpath in input_api.AffectedFiles(file_filter=file_filter):
1450 for lnum, line in fpath.ChangedContents():
1451 for (deprecated, replacement) in _DEPRECATED_JS:
1452 if deprecated in line:
1453 results.append(output_api.PresubmitError(
1454 "%s:%d: Use of deprecated JS %s, use %s instead" %
1455 (fpath.LocalPath(), lnum, deprecated, replacement)))
1456 return results
1457
1458
[email protected]22c9bd72011-03-27 16:47:391459def _CommonChecks(input_api, output_api):
1460 """Checks common to both upload and commit."""
1461 results = []
1462 results.extend(input_api.canned_checks.PanProjectChecks(
[email protected]3de922f2013-12-20 13:27:381463 input_api, output_api,
1464 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
[email protected]66daa702011-05-28 14:41:461465 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]55459852011-08-10 15:17:191466 results.extend(
[email protected]760deea2013-12-10 19:33:491467 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
[email protected]10689ca2011-09-02 02:31:541468 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
[email protected]72df4e782012-06-21 16:28:181469 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
[email protected]8ea5d4b2011-09-13 21:49:221470 results.extend(_CheckNoNewWStrings(input_api, output_api))
[email protected]2a8ac9c2011-10-19 17:20:441471 results.extend(_CheckNoDEPSGIT(input_api, output_api))
[email protected]127f18ec2012-06-16 05:05:591472 results.extend(_CheckNoBannedFunctions(input_api, output_api))
[email protected]6c063c62012-07-11 19:11:061473 results.extend(_CheckNoPragmaOnce(input_api, output_api))
[email protected]e7479052012-09-19 00:26:121474 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
[email protected]55f9f382012-07-31 11:02:181475 results.extend(_CheckUnwantedDependencies(input_api, output_api))
[email protected]fbcafe5a2012-08-08 15:31:221476 results.extend(_CheckFilePermissions(input_api, output_api))
[email protected]c8278b32012-10-30 20:35:491477 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
[email protected]2309b0fa02012-11-16 12:18:271478 results.extend(_CheckIncludeOrder(input_api, output_api))
[email protected]70ca77752012-11-20 03:45:031479 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
[email protected]b8079ae4a2012-12-05 19:56:491480 results.extend(_CheckPatchFiles(input_api, output_api))
[email protected]06e6d0ff2012-12-11 01:36:441481 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
[email protected]d2530012013-01-25 16:39:271482 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
[email protected]b00342e7f2013-03-26 16:21:541483 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
lliabraa35bab3932014-10-01 12:16:441484 results.extend(_CheckForInvalidIfDefinedMacros(input_api, output_api))
danakj3c84d0c2014-10-06 15:35:461485 # TODO(danakj): Remove this when base/move.h is removed.
1486 results.extend(_CheckForUsingSideEffectsOfPass(input_api, output_api))
[email protected]e871964c2013-05-13 14:14:551487 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
[email protected]9f919cc2013-07-31 03:04:041488 results.extend(
1489 input_api.canned_checks.CheckChangeHasNoTabs(
1490 input_api,
1491 output_api,
1492 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
[email protected]85218562013-11-22 07:41:401493 results.extend(_CheckSpamLogging(input_api, output_api))
[email protected]49aa76a2013-12-04 06:59:161494 results.extend(_CheckForAnonymousVariables(input_api, output_api))
[email protected]5fe0f8742013-11-29 01:04:591495 results.extend(_CheckCygwinShell(input_api, output_api))
[email protected]999261d2014-03-03 20:08:081496 results.extend(_CheckUserActionUpdate(input_api, output_api))
[email protected]fd20b902014-05-09 02:14:531497 results.extend(_CheckNoDeprecatedCSS(input_api, output_api))
dbeam070cfe62014-10-22 06:44:021498 results.extend(_CheckNoDeprecatedJS(input_api, output_api))
[email protected]99171a92014-06-03 08:44:471499 results.extend(_CheckParseErrors(input_api, output_api))
mlamouria82272622014-09-16 18:45:041500 results.extend(_CheckForIPCRules(input_api, output_api))
mnaganov9b9b1fe82014-12-11 16:30:361501 results.extend(_CheckForCopyrightedCode(input_api, output_api))
mostynbb639aca52015-01-07 20:31:231502 results.extend(_CheckForWindowsLineEndings(input_api, output_api))
glidere61efad2015-02-18 17:39:431503 results.extend(_CheckSingletonInHeaders(input_api, output_api))
[email protected]2299dcf2012-11-15 19:56:241504
1505 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1506 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1507 input_api, output_api,
1508 input_api.PresubmitLocalPath(),
[email protected]6be63382013-01-21 15:42:381509 whitelist=[r'^PRESUBMIT_test\.py$']))
[email protected]22c9bd72011-03-27 16:47:391510 return results
[email protected]1f7b4172010-01-28 01:17:341511
[email protected]b337cb5b2011-01-23 21:24:051512
[email protected]66daa702011-05-28 14:41:461513def _CheckAuthorizedAuthor(input_api, output_api):
1514 """For non-googler/chromites committers, verify the author's email address is
1515 in AUTHORS.
1516 """
[email protected]9bb9cb82011-06-13 20:43:011517 # TODO(maruel): Add it to input_api?
1518 import fnmatch
1519
[email protected]66daa702011-05-28 14:41:461520 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:011521 if not author:
1522 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:461523 return []
[email protected]c99663292011-05-31 19:46:081524 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:461525 input_api.PresubmitLocalPath(), 'AUTHORS')
1526 valid_authors = (
1527 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1528 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:181529 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]d8b50be2011-06-15 14:19:441530 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]5861efb2013-01-07 18:33:231531 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
[email protected]66daa702011-05-28 14:41:461532 return [output_api.PresubmitPromptWarning(
1533 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1534 '\n'
1535 'http://www.chromium.org/developers/contributing-code and read the '
1536 '"Legal" section\n'
1537 'If you are a chromite, verify the contributor signed the CLA.') %
1538 author)]
1539 return []
1540
1541
[email protected]b8079ae4a2012-12-05 19:56:491542def _CheckPatchFiles(input_api, output_api):
1543 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1544 if f.LocalPath().endswith(('.orig', '.rej'))]
1545 if problems:
1546 return [output_api.PresubmitError(
1547 "Don't commit .rej and .orig files.", problems)]
[email protected]2fdd1f362013-01-16 03:56:031548 else:
1549 return []
[email protected]b8079ae4a2012-12-05 19:56:491550
1551
[email protected]b00342e7f2013-03-26 16:21:541552def _DidYouMeanOSMacro(bad_macro):
1553 try:
1554 return {'A': 'OS_ANDROID',
1555 'B': 'OS_BSD',
1556 'C': 'OS_CHROMEOS',
1557 'F': 'OS_FREEBSD',
1558 'L': 'OS_LINUX',
1559 'M': 'OS_MACOSX',
1560 'N': 'OS_NACL',
1561 'O': 'OS_OPENBSD',
1562 'P': 'OS_POSIX',
1563 'S': 'OS_SOLARIS',
1564 'W': 'OS_WIN'}[bad_macro[3].upper()]
1565 except KeyError:
1566 return ''
1567
1568
1569def _CheckForInvalidOSMacrosInFile(input_api, f):
1570 """Check for sensible looking, totally invalid OS macros."""
1571 preprocessor_statement = input_api.re.compile(r'^\s*#')
1572 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1573 results = []
1574 for lnum, line in f.ChangedContents():
1575 if preprocessor_statement.search(line):
1576 for match in os_macro.finditer(line):
1577 if not match.group(1) in _VALID_OS_MACROS:
1578 good = _DidYouMeanOSMacro(match.group(1))
1579 did_you_mean = ' (did you mean %s?)' % good if good else ''
1580 results.append(' %s:%d %s%s' % (f.LocalPath(),
1581 lnum,
1582 match.group(1),
1583 did_you_mean))
1584 return results
1585
1586
1587def _CheckForInvalidOSMacros(input_api, output_api):
1588 """Check all affected files for invalid OS macros."""
1589 bad_macros = []
1590 for f in input_api.AffectedFiles():
1591 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1592 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1593
1594 if not bad_macros:
1595 return []
1596
1597 return [output_api.PresubmitError(
1598 'Possibly invalid OS macro[s] found. Please fix your code\n'
1599 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1600
lliabraa35bab3932014-10-01 12:16:441601
1602def _CheckForInvalidIfDefinedMacrosInFile(input_api, f):
1603 """Check all affected files for invalid "if defined" macros."""
1604 ALWAYS_DEFINED_MACROS = (
1605 "TARGET_CPU_PPC",
1606 "TARGET_CPU_PPC64",
1607 "TARGET_CPU_68K",
1608 "TARGET_CPU_X86",
1609 "TARGET_CPU_ARM",
1610 "TARGET_CPU_MIPS",
1611 "TARGET_CPU_SPARC",
1612 "TARGET_CPU_ALPHA",
1613 "TARGET_IPHONE_SIMULATOR",
1614 "TARGET_OS_EMBEDDED",
1615 "TARGET_OS_IPHONE",
1616 "TARGET_OS_MAC",
1617 "TARGET_OS_UNIX",
1618 "TARGET_OS_WIN32",
1619 )
1620 ifdef_macro = input_api.re.compile(r'^\s*#.*(?:ifdef\s|defined\()([^\s\)]+)')
1621 results = []
1622 for lnum, line in f.ChangedContents():
1623 for match in ifdef_macro.finditer(line):
1624 if match.group(1) in ALWAYS_DEFINED_MACROS:
1625 always_defined = ' %s is always defined. ' % match.group(1)
1626 did_you_mean = 'Did you mean \'#if %s\'?' % match.group(1)
1627 results.append(' %s:%d %s\n\t%s' % (f.LocalPath(),
1628 lnum,
1629 always_defined,
1630 did_you_mean))
1631 return results
1632
1633
1634def _CheckForInvalidIfDefinedMacros(input_api, output_api):
1635 """Check all affected files for invalid "if defined" macros."""
1636 bad_macros = []
1637 for f in input_api.AffectedFiles():
1638 if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')):
1639 bad_macros.extend(_CheckForInvalidIfDefinedMacrosInFile(input_api, f))
1640
1641 if not bad_macros:
1642 return []
1643
1644 return [output_api.PresubmitError(
1645 'Found ifdef check on always-defined macro[s]. Please fix your code\n'
1646 'or check the list of ALWAYS_DEFINED_MACROS in src/PRESUBMIT.py.',
1647 bad_macros)]
1648
1649
danakj3c84d0c2014-10-06 15:35:461650def _CheckForUsingSideEffectsOfPass(input_api, output_api):
1651 """Check all affected files for using side effects of Pass."""
1652 errors = []
1653 for f in input_api.AffectedFiles():
1654 if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')):
1655 for lnum, line in f.ChangedContents():
1656 # Disallow Foo(*my_scoped_thing.Pass()); See crbug.com/418297.
mohan.reddyf21db962014-10-16 12:26:471657 if input_api.re.search(r'\*[a-zA-Z0-9_]+\.Pass\(\)', line):
danakj3c84d0c2014-10-06 15:35:461658 errors.append(output_api.PresubmitError(
1659 ('%s:%d uses *foo.Pass() to delete the contents of scoped_ptr. ' +
1660 'See crbug.com/418297.') % (f.LocalPath(), lnum)))
1661 return errors
1662
1663
mlamouria82272622014-09-16 18:45:041664def _CheckForIPCRules(input_api, output_api):
1665 """Check for same IPC rules described in
1666 http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc
1667 """
1668 base_pattern = r'IPC_ENUM_TRAITS\('
1669 inclusion_pattern = input_api.re.compile(r'(%s)' % base_pattern)
1670 comment_pattern = input_api.re.compile(r'//.*(%s)' % base_pattern)
1671
1672 problems = []
1673 for f in input_api.AffectedSourceFiles(None):
1674 local_path = f.LocalPath()
1675 if not local_path.endswith('.h'):
1676 continue
1677 for line_number, line in f.ChangedContents():
1678 if inclusion_pattern.search(line) and not comment_pattern.search(line):
1679 problems.append(
1680 '%s:%d\n %s' % (local_path, line_number, line.strip()))
1681
1682 if problems:
1683 return [output_api.PresubmitPromptWarning(
1684 _IPC_ENUM_TRAITS_DEPRECATED, problems)]
1685 else:
1686 return []
1687
[email protected]b00342e7f2013-03-26 16:21:541688
mostynbb639aca52015-01-07 20:31:231689def _CheckForWindowsLineEndings(input_api, output_api):
1690 """Check source code and known ascii text files for Windows style line
1691 endings.
1692 """
earthdok1b5e0ee2015-03-10 15:19:101693 known_text_files = r'.*\.(txt|html|htm|mhtml|py|gyp|gypi|gn|isolate)$'
mostynbb639aca52015-01-07 20:31:231694
1695 file_inclusion_pattern = (
1696 known_text_files,
1697 r'.+%s' % _IMPLEMENTATION_EXTENSIONS
1698 )
1699
1700 filter = lambda f: input_api.FilterSourceFile(
1701 f, white_list=file_inclusion_pattern, black_list=None)
1702 files = [f.LocalPath() for f in
1703 input_api.AffectedSourceFiles(filter)]
1704
1705 problems = []
1706
1707 for file in files:
1708 fp = open(file, 'r')
1709 for line in fp:
1710 if line.endswith('\r\n'):
1711 problems.append(file)
1712 break
1713 fp.close()
1714
1715 if problems:
1716 return [output_api.PresubmitPromptWarning('Are you sure that you want '
1717 'these files to contain Windows style line endings?\n' +
1718 '\n'.join(problems))]
1719
1720 return []
1721
1722
[email protected]1f7b4172010-01-28 01:17:341723def CheckChangeOnUpload(input_api, output_api):
1724 results = []
1725 results.extend(_CommonChecks(input_api, output_api))
tandriief664692014-09-23 14:51:471726 results.extend(_CheckValidHostsInDEPS(input_api, output_api))
aurimas8d3bc1c52014-10-15 01:02:171727 results.extend(_CheckJavaStyle(input_api, output_api))
scottmg39b29952014-12-08 18:31:281728 results.extend(
1729 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
mcasasb7440c282015-02-04 14:52:191730 results.extend(_CheckUmaHistogramChanges(input_api, output_api))
dgnbbbc31f52015-05-21 09:53:161731 results.extend(_CheckNoNewUtilLogUsage(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541732 return results
[email protected]ca8d1982009-02-19 16:33:121733
1734
[email protected]1bfb8322014-04-23 01:02:411735def GetTryServerMasterForBot(bot):
1736 """Returns the Try Server master for the given bot.
1737
[email protected]0bb112362014-07-26 04:38:321738 It tries to guess the master from the bot name, but may still fail
1739 and return None. There is no longer a default master.
1740 """
1741 # Potentially ambiguous bot names are listed explicitly.
1742 master_map = {
[email protected]0bb112362014-07-26 04:38:321743 'chromium_presubmit': 'tryserver.chromium.linux',
1744 'blink_presubmit': 'tryserver.chromium.linux',
1745 'tools_build_presubmit': 'tryserver.chromium.linux',
[email protected]1bfb8322014-04-23 01:02:411746 }
[email protected]0bb112362014-07-26 04:38:321747 master = master_map.get(bot)
1748 if not master:
sergiyb37fd293f2015-02-26 06:55:011749 if 'linux' in bot or 'android' in bot or 'presubmit' in bot:
[email protected]0bb112362014-07-26 04:38:321750 master = 'tryserver.chromium.linux'
1751 elif 'win' in bot:
1752 master = 'tryserver.chromium.win'
1753 elif 'mac' in bot or 'ios' in bot:
1754 master = 'tryserver.chromium.mac'
1755 return master
[email protected]1bfb8322014-04-23 01:02:411756
1757
Paweł Hajdan, Jr55083782014-12-19 20:32:561758def GetDefaultTryConfigs(bots):
1759 """Returns a list of ('bot', set(['tests']), filtered by [bots].
[email protected]38c6a512013-12-18 23:48:011760 """
1761
Paweł Hajdan, Jr55083782014-12-19 20:32:561762 builders_and_tests = dict((bot, set(['defaulttests'])) for bot in bots)
[email protected]1bfb8322014-04-23 01:02:411763
1764 # Build up the mapping from tryserver master to bot/test.
1765 out = dict()
Paweł Hajdan, Jr55083782014-12-19 20:32:561766 for bot, tests in builders_and_tests.iteritems():
[email protected]1bfb8322014-04-23 01:02:411767 out.setdefault(GetTryServerMasterForBot(bot), {})[bot] = tests
1768 return out
[email protected]38c6a512013-12-18 23:48:011769
1770
[email protected]ca8d1982009-02-19 16:33:121771def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:541772 results = []
[email protected]1f7b4172010-01-28 01:17:341773 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:511774 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1775 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1776 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:541777 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:271778 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:341779 input_api,
1780 output_api,
[email protected]2fdd1f362013-01-16 03:56:031781 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:271782
[email protected]3e4eb112011-01-18 03:29:541783 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1784 input_api, output_api))
[email protected]c4b47562011-12-05 23:39:411785 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1786 input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541787 return results
[email protected]ca8d1982009-02-19 16:33:121788
1789
[email protected]7468ac522014-03-12 23:35:571790def GetPreferredTryMasters(project, change):
Paweł Hajdan, Jref2afd42015-01-07 15:59:521791 import json
sergiyb57a71e32015-06-03 18:44:001792 import os.path
1793 import platform
1794 import subprocess
smut3ef206e12015-03-20 09:30:001795
sergiyb57a71e32015-06-03 18:44:001796 cq_config_path = os.path.join(
1797 change.RepositoryRoot(), 'infra', 'config', 'cq.cfg')
1798 # commit_queue.py below is a script in depot_tools directory, which has a
1799 # 'builders' command to retrieve a list of CQ builders from the CQ config.
1800 is_win = platform.system() == 'Windows'
1801 masters = json.loads(subprocess.check_output(
1802 ['commit_queue', 'builders', cq_config_path], shell=is_win))
[email protected]911753b2012-08-02 12:11:541803
sergiyb57a71e32015-06-03 18:44:001804 # Explicitly iterate over copies of keys since we mutate them.
1805 for master in masters.keys():
1806 for builder in masters[master].keys():
1807 # Do not trigger presubmit builders, since they're likely to fail
1808 # (e.g. OWNERS checks before finished code review), and we're
1809 # running local presubmit anyway.
1810 if 'presubmit' in builder:
1811 masters[master].pop(builder)
1812 else:
1813 # Convert testfilter format to the one expected by git-cl-try.
1814 testfilter = masters[master][builder].get('testfilter', 'defaulttests')
1815 masters[master][builder] = [testfilter]
Paweł Hajdan, Jr4026dbc2015-01-14 09:22:321816
sergiyb57a71e32015-06-03 18:44:001817 return masters