blob: a3e3af04ec62b142cad6c4040728969bd962e000 [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
[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]eea609a2011-11-18 13:10:1211
[email protected]9d16ad12011-12-14 20:49:4712import re
[email protected]55f9f382012-07-31 11:02:1813import sys
[email protected]9d16ad12011-12-14 20:49:4714
15
[email protected]379e7dd2010-01-28 17:39:2116_EXCLUDED_PATHS = (
[email protected]3e4eb112011-01-18 03:29:5417 r"^breakpad[\\\/].*",
[email protected]40d1dbb2012-10-26 07:18:0018 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
19 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
[email protected]8886ffcb2013-02-12 04:56:2820 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
[email protected]a18130a2012-01-03 17:52:0821 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
[email protected]3e4eb112011-01-18 03:29:5422 r"^skia[\\\/].*",
23 r"^v8[\\\/].*",
24 r".*MakeFile$",
[email protected]1084ccc2012-03-14 03:22:5325 r".+_autogen\.h$",
[email protected]ce145c02012-09-06 09:49:3426 r".+[\\\/]pnacl_shim\.c$",
[email protected]e07b6ac72013-08-20 00:30:4227 r"^gpu[\\\/]config[\\\/].*_list_json\.cc$",
[email protected]d2600602014-02-19 00:09:1928 r"^chrome[\\\/]browser[\\\/]resources[\\\/]pdf[\\\/]index.js"
[email protected]4306417642009-06-11 00:33:4029)
[email protected]ca8d1982009-02-19 16:33:1230
[email protected]de28fed2e2014-02-01 14:36:3231# TestRunner and NetscapePlugIn library is temporarily excluded from pan-project
32# checks until it's transitioned to chromium coding style.
[email protected]3de922f2013-12-20 13:27:3833_TESTRUNNER_PATHS = (
34 r"^content[\\\/]shell[\\\/]renderer[\\\/]test_runner[\\\/].*",
[email protected]de28fed2e2014-02-01 14:36:3235 r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*",
[email protected]3de922f2013-12-20 13:27:3836)
37
[email protected]06e6d0ff2012-12-11 01:36:4438# Fragment of a regular expression that matches C++ and Objective-C++
39# implementation files.
40_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
41
42# Regular expression that matches code only used for test binaries
43# (best effort).
44_TEST_CODE_EXCLUDED_PATHS = (
joaodasilva718f87672014-08-30 09:25:4945 r'.*[\\\/](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4446 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
[email protected]6e04f8c2014-01-29 18:08:3247 r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
[email protected]e2d7e6f2013-04-23 12:57:1248 _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4449 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
joaodasilva718f87672014-08-30 09:25:4950 r'.*[\\\/](test|tool(s)?)[\\\/].*',
[email protected]ef070cc2013-05-03 11:53:0551 # content_shell is used for running layout tests.
joaodasilva718f87672014-08-30 09:25:4952 r'content[\\\/]shell[\\\/].*',
[email protected]06e6d0ff2012-12-11 01:36:4453 # At request of folks maintaining this folder.
joaodasilva718f87672014-08-30 09:25:4954 r'chrome[\\\/]browser[\\\/]automation[\\\/].*',
[email protected]7b054982013-11-27 00:44:4755 # Non-production example code.
joaodasilva718f87672014-08-30 09:25:4956 r'mojo[\\\/]examples[\\\/].*',
[email protected]8176de12014-06-20 19:07:0857 # Launcher for running iOS tests on the simulator.
joaodasilva718f87672014-08-30 09:25:4958 r'testing[\\\/]iossim[\\\/]iossim\.mm$',
[email protected]06e6d0ff2012-12-11 01:36:4459)
[email protected]ca8d1982009-02-19 16:33:1260
[email protected]eea609a2011-11-18 13:10:1261_TEST_ONLY_WARNING = (
62 'You might be calling functions intended only for testing from\n'
63 'production code. It is OK to ignore this warning if you know what\n'
64 'you are doing, as the heuristics used to detect the situation are\n'
[email protected]b0149772014-03-27 16:47:5865 'not perfect. The commit queue will not block on this warning.')
[email protected]eea609a2011-11-18 13:10:1266
67
[email protected]cf9b78f2012-11-14 11:40:2868_INCLUDE_ORDER_WARNING = (
69 'Your #include order seems to be broken. Send mail to\n'
70 '[email protected] if this is not the case.')
71
72
[email protected]127f18ec2012-06-16 05:05:5973_BANNED_OBJC_FUNCTIONS = (
74 (
75 'addTrackingRect:',
[email protected]23e6cbc2012-06-16 18:51:2076 (
77 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
[email protected]127f18ec2012-06-16 05:05:5978 'prohibited. Please use CrTrackingArea instead.',
79 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
80 ),
81 False,
82 ),
83 (
[email protected]eaae1972014-04-16 04:17:2684 r'/NSTrackingArea\W',
[email protected]23e6cbc2012-06-16 18:51:2085 (
86 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
[email protected]127f18ec2012-06-16 05:05:5987 'instead.',
88 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
89 ),
90 False,
91 ),
92 (
93 'convertPointFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2094 (
95 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5996 'Please use |convertPoint:(point) fromView:nil| instead.',
97 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
98 ),
99 True,
100 ),
101 (
102 'convertPointToBase:',
[email protected]23e6cbc2012-06-16 18:51:20103 (
104 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59105 'Please use |convertPoint:(point) toView:nil| instead.',
106 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
107 ),
108 True,
109 ),
110 (
111 'convertRectFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20112 (
113 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59114 'Please use |convertRect:(point) fromView:nil| instead.',
115 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
116 ),
117 True,
118 ),
119 (
120 'convertRectToBase:',
[email protected]23e6cbc2012-06-16 18:51:20121 (
122 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59123 'Please use |convertRect:(point) toView:nil| instead.',
124 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
125 ),
126 True,
127 ),
128 (
129 'convertSizeFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20130 (
131 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59132 'Please use |convertSize:(point) fromView:nil| instead.',
133 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
134 ),
135 True,
136 ),
137 (
138 'convertSizeToBase:',
[email protected]23e6cbc2012-06-16 18:51:20139 (
140 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59141 'Please use |convertSize:(point) toView:nil| instead.',
142 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
143 ),
144 True,
145 ),
146)
147
148
149_BANNED_CPP_FUNCTIONS = (
[email protected]23e6cbc2012-06-16 18:51:20150 # Make sure that gtest's FRIEND_TEST() macro is not used; the
151 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
[email protected]e00ccc92012-11-01 17:32:30152 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
[email protected]23e6cbc2012-06-16 18:51:20153 (
154 'FRIEND_TEST(',
155 (
[email protected]e3c945502012-06-26 20:01:49156 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
[email protected]23e6cbc2012-06-16 18:51:20157 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
158 ),
159 False,
[email protected]7345da02012-11-27 14:31:49160 (),
[email protected]23e6cbc2012-06-16 18:51:20161 ),
162 (
163 'ScopedAllowIO',
164 (
[email protected]e3c945502012-06-26 20:01:49165 'New code should not use ScopedAllowIO. Post a task to the blocking',
166 'pool or the FILE thread instead.',
[email protected]23e6cbc2012-06-16 18:51:20167 ),
[email protected]e3c945502012-06-26 20:01:49168 True,
[email protected]7345da02012-11-27 14:31:49169 (
thestig75844fdb2014-09-09 19:47:10170 r"^base[\\\/]process[\\\/]process_metrics_linux\.cc$",
[email protected]b01b9e22014-06-03 22:20:19171 r"^chrome[\\\/]browser[\\\/]chromeos[\\\/]boot_times_loader\.cc$",
philipj3f9d5bde2014-08-28 14:09:09172 r"^components[\\\/]crash[\\\/]app[\\\/]breakpad_mac\.mm$",
[email protected]de7d61ff2013-08-20 11:30:41173 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
174 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
[email protected]ac1df702014-03-21 20:45:27175 r"^mojo[\\\/]system[\\\/]raw_shared_buffer_posix\.cc$",
[email protected]398ad132013-04-02 15:11:01176 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
[email protected]1f52a572014-05-12 23:21:54177 r"^net[\\\/]url_request[\\\/]test_url_fetcher_factory\.cc$",
[email protected]7345da02012-11-27 14:31:49178 ),
[email protected]23e6cbc2012-06-16 18:51:20179 ),
[email protected]52657f62013-05-20 05:30:31180 (
181 'SkRefPtr',
182 (
183 'The use of SkRefPtr is prohibited. ',
184 'Please use skia::RefPtr instead.'
185 ),
186 True,
187 (),
188 ),
189 (
190 'SkAutoRef',
191 (
192 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
193 'Please use skia::RefPtr instead.'
194 ),
195 True,
196 (),
197 ),
198 (
199 'SkAutoTUnref',
200 (
201 'The use of SkAutoTUnref is dangerous because it implicitly ',
202 'converts to a raw pointer. Please use skia::RefPtr instead.'
203 ),
204 True,
205 (),
206 ),
207 (
208 'SkAutoUnref',
209 (
210 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
211 'because it implicitly converts to a raw pointer. ',
212 'Please use skia::RefPtr instead.'
213 ),
214 True,
215 (),
216 ),
[email protected]d89eec82013-12-03 14:10:59217 (
218 r'/HANDLE_EINTR\(.*close',
219 (
220 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
221 'descriptor will be closed, and it is incorrect to retry the close.',
222 'Either call close directly and ignore its return value, or wrap close',
223 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
224 ),
225 True,
226 (),
227 ),
228 (
229 r'/IGNORE_EINTR\((?!.*close)',
230 (
231 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
232 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
233 ),
234 True,
235 (
236 # Files that #define IGNORE_EINTR.
237 r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
238 r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
239 ),
240 ),
[email protected]ec5b3f02014-04-04 18:43:43241 (
242 r'/v8::Extension\(',
243 (
244 'Do not introduce new v8::Extensions into the code base, use',
245 'gin::Wrappable instead. See http://crbug.com/334679',
246 ),
247 True,
[email protected]f55c90ee62014-04-12 00:50:03248 (
joaodasilva718f87672014-08-30 09:25:49249 r'extensions[\\\/]renderer[\\\/]safe_builtins\.*',
[email protected]f55c90ee62014-04-12 00:50:03250 ),
[email protected]ec5b3f02014-04-04 18:43:43251 ),
[email protected]127f18ec2012-06-16 05:05:59252)
253
254
[email protected]b00342e7f2013-03-26 16:21:54255_VALID_OS_MACROS = (
256 # Please keep sorted.
257 'OS_ANDROID',
[email protected]f4440b42014-03-19 05:47:01258 'OS_ANDROID_HOST',
[email protected]b00342e7f2013-03-26 16:21:54259 'OS_BSD',
260 'OS_CAT', # For testing.
261 'OS_CHROMEOS',
262 'OS_FREEBSD',
263 'OS_IOS',
264 'OS_LINUX',
265 'OS_MACOSX',
266 'OS_NACL',
267 'OS_OPENBSD',
268 'OS_POSIX',
[email protected]eda7afa12014-02-06 12:27:37269 'OS_QNX',
[email protected]b00342e7f2013-03-26 16:21:54270 'OS_SOLARIS',
[email protected]b00342e7f2013-03-26 16:21:54271 'OS_WIN',
272)
273
274
[email protected]55459852011-08-10 15:17:19275def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
276 """Attempts to prevent use of functions intended only for testing in
277 non-testing code. For now this is just a best-effort implementation
278 that ignores header files and may have some false positives. A
279 better implementation would probably need a proper C++ parser.
280 """
281 # We only scan .cc files and the like, as the declaration of
282 # for-testing functions in header files are hard to distinguish from
283 # calls to such functions without a proper C++ parser.
[email protected]06e6d0ff2012-12-11 01:36:44284 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
[email protected]55459852011-08-10 15:17:19285
[email protected]23501822014-05-14 02:06:09286 base_function_pattern = r'[ :]test::[^\s]+|ForTest(ing)?|for_test(ing)?'
[email protected]55459852011-08-10 15:17:19287 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
[email protected]23501822014-05-14 02:06:09288 comment_pattern = input_api.re.compile(r'//.*(%s)' % base_function_pattern)
[email protected]55459852011-08-10 15:17:19289 exclusion_pattern = input_api.re.compile(
290 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
291 base_function_pattern, base_function_pattern))
292
293 def FilterFile(affected_file):
[email protected]06e6d0ff2012-12-11 01:36:44294 black_list = (_EXCLUDED_PATHS +
295 _TEST_CODE_EXCLUDED_PATHS +
296 input_api.DEFAULT_BLACK_LIST)
[email protected]55459852011-08-10 15:17:19297 return input_api.FilterSourceFile(
298 affected_file,
299 white_list=(file_inclusion_pattern, ),
300 black_list=black_list)
301
302 problems = []
303 for f in input_api.AffectedSourceFiles(FilterFile):
304 local_path = f.LocalPath()
[email protected]825d27182014-01-02 21:24:24305 for line_number, line in f.ChangedContents():
[email protected]2fdd1f362013-01-16 03:56:03306 if (inclusion_pattern.search(line) and
[email protected]de4f7d22013-05-23 14:27:46307 not comment_pattern.search(line) and
[email protected]2fdd1f362013-01-16 03:56:03308 not exclusion_pattern.search(line)):
[email protected]55459852011-08-10 15:17:19309 problems.append(
[email protected]2fdd1f362013-01-16 03:56:03310 '%s:%d\n %s' % (local_path, line_number, line.strip()))
[email protected]55459852011-08-10 15:17:19311
312 if problems:
[email protected]f7051d52013-04-02 18:31:42313 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
[email protected]2fdd1f362013-01-16 03:56:03314 else:
315 return []
[email protected]55459852011-08-10 15:17:19316
317
[email protected]10689ca2011-09-02 02:31:54318def _CheckNoIOStreamInHeaders(input_api, output_api):
319 """Checks to make sure no .h files include <iostream>."""
320 files = []
321 pattern = input_api.re.compile(r'^#include\s*<iostream>',
322 input_api.re.MULTILINE)
323 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
324 if not f.LocalPath().endswith('.h'):
325 continue
326 contents = input_api.ReadFile(f)
327 if pattern.search(contents):
328 files.append(f)
329
330 if len(files):
331 return [ output_api.PresubmitError(
[email protected]6c063c62012-07-11 19:11:06332 'Do not #include <iostream> in header files, since it inserts static '
333 'initialization into every file including the header. Instead, '
[email protected]10689ca2011-09-02 02:31:54334 '#include <ostream>. See http://crbug.com/94794',
335 files) ]
336 return []
337
338
[email protected]72df4e782012-06-21 16:28:18339def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
340 """Checks to make sure no source files use UNIT_TEST"""
341 problems = []
342 for f in input_api.AffectedFiles():
343 if (not f.LocalPath().endswith(('.cc', '.mm'))):
344 continue
345
346 for line_num, line in f.ChangedContents():
[email protected]549f86a2013-11-19 13:00:04347 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
[email protected]72df4e782012-06-21 16:28:18348 problems.append(' %s:%d' % (f.LocalPath(), line_num))
349
350 if not problems:
351 return []
352 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
353 '\n'.join(problems))]
354
355
[email protected]8ea5d4b2011-09-13 21:49:22356def _CheckNoNewWStrings(input_api, output_api):
357 """Checks to make sure we don't introduce use of wstrings."""
[email protected]55463aa62011-10-12 00:48:27358 problems = []
[email protected]8ea5d4b2011-09-13 21:49:22359 for f in input_api.AffectedFiles():
[email protected]b5c24292011-11-28 14:38:20360 if (not f.LocalPath().endswith(('.cc', '.h')) or
[email protected]24be83c2013-08-29 23:01:23361 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
[email protected]b5c24292011-11-28 14:38:20362 continue
[email protected]8ea5d4b2011-09-13 21:49:22363
[email protected]a11dbe9b2012-08-07 01:32:58364 allowWString = False
[email protected]b5c24292011-11-28 14:38:20365 for line_num, line in f.ChangedContents():
[email protected]a11dbe9b2012-08-07 01:32:58366 if 'presubmit: allow wstring' in line:
367 allowWString = True
368 elif not allowWString and 'wstring' in line:
[email protected]55463aa62011-10-12 00:48:27369 problems.append(' %s:%d' % (f.LocalPath(), line_num))
[email protected]a11dbe9b2012-08-07 01:32:58370 allowWString = False
371 else:
372 allowWString = False
[email protected]8ea5d4b2011-09-13 21:49:22373
[email protected]55463aa62011-10-12 00:48:27374 if not problems:
375 return []
376 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
[email protected]a11dbe9b2012-08-07 01:32:58377 ' If you are calling a cross-platform API that accepts a wstring, '
378 'fix the API.\n' +
[email protected]55463aa62011-10-12 00:48:27379 '\n'.join(problems))]
[email protected]8ea5d4b2011-09-13 21:49:22380
381
[email protected]2a8ac9c2011-10-19 17:20:44382def _CheckNoDEPSGIT(input_api, output_api):
383 """Make sure .DEPS.git is never modified manually."""
384 if any(f.LocalPath().endswith('.DEPS.git') for f in
385 input_api.AffectedFiles()):
386 return [output_api.PresubmitError(
387 'Never commit changes to .DEPS.git. This file is maintained by an\n'
388 'automated system based on what\'s in DEPS and your changes will be\n'
389 'overwritten.\n'
[email protected]cb706912014-06-28 20:46:34390 '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:44391 'for more information')]
392 return []
393
394
[email protected]127f18ec2012-06-16 05:05:59395def _CheckNoBannedFunctions(input_api, output_api):
396 """Make sure that banned functions are not used."""
397 warnings = []
398 errors = []
399
400 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
401 for f in input_api.AffectedFiles(file_filter=file_filter):
402 for line_num, line in f.ChangedContents():
403 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
[email protected]eaae1972014-04-16 04:17:26404 matched = False
405 if func_name[0:1] == '/':
406 regex = func_name[1:]
407 if input_api.re.search(regex, line):
408 matched = True
409 elif func_name in line:
410 matched = True
411 if matched:
[email protected]127f18ec2012-06-16 05:05:59412 problems = warnings;
413 if error:
414 problems = errors;
415 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
416 for message_line in message:
417 problems.append(' %s' % message_line)
418
419 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
420 for f in input_api.AffectedFiles(file_filter=file_filter):
421 for line_num, line in f.ChangedContents():
[email protected]7345da02012-11-27 14:31:49422 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
423 def IsBlacklisted(affected_file, blacklist):
424 local_path = affected_file.LocalPath()
425 for item in blacklist:
426 if input_api.re.match(item, local_path):
427 return True
428 return False
429 if IsBlacklisted(f, excluded_paths):
430 continue
[email protected]d89eec82013-12-03 14:10:59431 matched = False
432 if func_name[0:1] == '/':
433 regex = func_name[1:]
434 if input_api.re.search(regex, line):
435 matched = True
436 elif func_name in line:
437 matched = True
438 if matched:
[email protected]127f18ec2012-06-16 05:05:59439 problems = warnings;
440 if error:
441 problems = errors;
442 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
443 for message_line in message:
444 problems.append(' %s' % message_line)
445
446 result = []
447 if (warnings):
448 result.append(output_api.PresubmitPromptWarning(
449 'Banned functions were used.\n' + '\n'.join(warnings)))
450 if (errors):
451 result.append(output_api.PresubmitError(
452 'Banned functions were used.\n' + '\n'.join(errors)))
453 return result
454
455
[email protected]6c063c62012-07-11 19:11:06456def _CheckNoPragmaOnce(input_api, output_api):
457 """Make sure that banned functions are not used."""
458 files = []
459 pattern = input_api.re.compile(r'^#pragma\s+once',
460 input_api.re.MULTILINE)
461 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
462 if not f.LocalPath().endswith('.h'):
463 continue
464 contents = input_api.ReadFile(f)
465 if pattern.search(contents):
466 files.append(f)
467
468 if files:
469 return [output_api.PresubmitError(
470 'Do not use #pragma once in header files.\n'
471 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
472 files)]
473 return []
474
[email protected]127f18ec2012-06-16 05:05:59475
[email protected]e7479052012-09-19 00:26:12476def _CheckNoTrinaryTrueFalse(input_api, output_api):
477 """Checks to make sure we don't introduce use of foo ? true : false."""
478 problems = []
479 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
480 for f in input_api.AffectedFiles():
481 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
482 continue
483
484 for line_num, line in f.ChangedContents():
485 if pattern.match(line):
486 problems.append(' %s:%d' % (f.LocalPath(), line_num))
487
488 if not problems:
489 return []
490 return [output_api.PresubmitPromptWarning(
491 'Please consider avoiding the "? true : false" pattern if possible.\n' +
492 '\n'.join(problems))]
493
494
[email protected]55f9f382012-07-31 11:02:18495def _CheckUnwantedDependencies(input_api, output_api):
496 """Runs checkdeps on #include statements added in this
497 change. Breaking - rules is an error, breaking ! rules is a
498 warning.
499 """
500 # We need to wait until we have an input_api object and use this
501 # roundabout construct to import checkdeps because this file is
502 # eval-ed and thus doesn't have __file__.
503 original_sys_path = sys.path
504 try:
505 sys.path = sys.path + [input_api.os_path.join(
[email protected]5298cc982014-05-29 20:53:47506 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')]
[email protected]55f9f382012-07-31 11:02:18507 import checkdeps
508 from cpp_checker import CppChecker
509 from rules import Rule
510 finally:
511 # Restore sys.path to what it was before.
512 sys.path = original_sys_path
513
514 added_includes = []
515 for f in input_api.AffectedFiles():
516 if not CppChecker.IsCppFile(f.LocalPath()):
517 continue
518
519 changed_lines = [line for line_num, line in f.ChangedContents()]
520 added_includes.append([f.LocalPath(), changed_lines])
521
[email protected]26385172013-05-09 23:11:35522 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
[email protected]55f9f382012-07-31 11:02:18523
524 error_descriptions = []
525 warning_descriptions = []
526 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
527 added_includes):
528 description_with_path = '%s\n %s' % (path, rule_description)
529 if rule_type == Rule.DISALLOW:
530 error_descriptions.append(description_with_path)
531 else:
532 warning_descriptions.append(description_with_path)
533
534 results = []
535 if error_descriptions:
536 results.append(output_api.PresubmitError(
537 'You added one or more #includes that violate checkdeps rules.',
538 error_descriptions))
539 if warning_descriptions:
[email protected]f7051d52013-04-02 18:31:42540 results.append(output_api.PresubmitPromptOrNotify(
[email protected]55f9f382012-07-31 11:02:18541 'You added one or more #includes of files that are temporarily\n'
542 'allowed but being removed. Can you avoid introducing the\n'
543 '#include? See relevant DEPS file(s) for details and contacts.',
544 warning_descriptions))
545 return results
546
547
[email protected]fbcafe5a2012-08-08 15:31:22548def _CheckFilePermissions(input_api, output_api):
549 """Check that all files have their permissions properly set."""
[email protected]791507202014-02-03 23:19:15550 if input_api.platform == 'win32':
551 return []
[email protected]fbcafe5a2012-08-08 15:31:22552 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
553 input_api.change.RepositoryRoot()]
554 for f in input_api.AffectedFiles():
555 args += ['--file', f.LocalPath()]
[email protected]f0d330f2014-01-30 01:44:34556 checkperms = input_api.subprocess.Popen(args,
557 stdout=input_api.subprocess.PIPE)
558 errors = checkperms.communicate()[0].strip()
[email protected]fbcafe5a2012-08-08 15:31:22559 if errors:
[email protected]f0d330f2014-01-30 01:44:34560 return [output_api.PresubmitError('checkperms.py failed.',
561 errors.splitlines())]
562 return []
[email protected]fbcafe5a2012-08-08 15:31:22563
564
[email protected]c8278b32012-10-30 20:35:49565def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
566 """Makes sure we don't include ui/aura/window_property.h
567 in header files.
568 """
569 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
570 errors = []
571 for f in input_api.AffectedFiles():
572 if not f.LocalPath().endswith('.h'):
573 continue
574 for line_num, line in f.ChangedContents():
575 if pattern.match(line):
576 errors.append(' %s:%d' % (f.LocalPath(), line_num))
577
578 results = []
579 if errors:
580 results.append(output_api.PresubmitError(
581 'Header files should not include ui/aura/window_property.h', errors))
582 return results
583
584
[email protected]cf9b78f2012-11-14 11:40:28585def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
586 """Checks that the lines in scope occur in the right order.
587
588 1. C system files in alphabetical order
589 2. C++ system files in alphabetical order
590 3. Project's .h files
591 """
592
593 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
594 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
595 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
596
597 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
598
599 state = C_SYSTEM_INCLUDES
600
601 previous_line = ''
[email protected]728b9bb2012-11-14 20:38:57602 previous_line_num = 0
[email protected]cf9b78f2012-11-14 11:40:28603 problem_linenums = []
604 for line_num, line in scope:
605 if c_system_include_pattern.match(line):
606 if state != C_SYSTEM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57607 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28608 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57609 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28610 elif cpp_system_include_pattern.match(line):
611 if state == C_SYSTEM_INCLUDES:
612 state = CPP_SYSTEM_INCLUDES
613 elif state == CUSTOM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57614 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28615 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57616 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28617 elif custom_include_pattern.match(line):
618 if state != CUSTOM_INCLUDES:
619 state = CUSTOM_INCLUDES
620 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57621 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28622 else:
623 problem_linenums.append(line_num)
624 previous_line = line
[email protected]728b9bb2012-11-14 20:38:57625 previous_line_num = line_num
[email protected]cf9b78f2012-11-14 11:40:28626
627 warnings = []
[email protected]728b9bb2012-11-14 20:38:57628 for (line_num, previous_line_num) in problem_linenums:
629 if line_num in changed_linenums or previous_line_num in changed_linenums:
[email protected]cf9b78f2012-11-14 11:40:28630 warnings.append(' %s:%d' % (file_path, line_num))
631 return warnings
632
633
[email protected]ac294a12012-12-06 16:38:43634def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
[email protected]cf9b78f2012-11-14 11:40:28635 """Checks the #include order for the given file f."""
636
[email protected]2299dcf2012-11-15 19:56:24637 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
[email protected]23093b62013-09-20 12:16:30638 # Exclude the following includes from the check:
639 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
640 # specific order.
641 # 2) <atlbase.h>, "build/build_config.h"
642 excluded_include_pattern = input_api.re.compile(
643 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
[email protected]2299dcf2012-11-15 19:56:24644 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
[email protected]3e83618c2013-10-09 22:32:33645 # Match the final or penultimate token if it is xxxtest so we can ignore it
646 # when considering the special first include.
647 test_file_tag_pattern = input_api.re.compile(
648 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
[email protected]0e5c1852012-12-18 20:17:11649 if_pattern = input_api.re.compile(
650 r'\s*#\s*(if|elif|else|endif|define|undef).*')
651 # Some files need specialized order of includes; exclude such files from this
652 # check.
653 uncheckable_includes_pattern = input_api.re.compile(
654 r'\s*#include '
655 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
[email protected]cf9b78f2012-11-14 11:40:28656
657 contents = f.NewContents()
658 warnings = []
659 line_num = 0
660
[email protected]ac294a12012-12-06 16:38:43661 # Handle the special first include. If the first include file is
662 # some/path/file.h, the corresponding including file can be some/path/file.cc,
663 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
664 # etc. It's also possible that no special first include exists.
[email protected]3e83618c2013-10-09 22:32:33665 # If the included file is some/path/file_platform.h the including file could
666 # also be some/path/file_xxxtest_platform.h.
667 including_file_base_name = test_file_tag_pattern.sub(
668 '', input_api.os_path.basename(f.LocalPath()))
669
[email protected]ac294a12012-12-06 16:38:43670 for line in contents:
671 line_num += 1
672 if system_include_pattern.match(line):
673 # No special first include -> process the line again along with normal
674 # includes.
675 line_num -= 1
676 break
677 match = custom_include_pattern.match(line)
678 if match:
679 match_dict = match.groupdict()
[email protected]3e83618c2013-10-09 22:32:33680 header_basename = test_file_tag_pattern.sub(
681 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
682
683 if header_basename not in including_file_base_name:
[email protected]2299dcf2012-11-15 19:56:24684 # No special first include -> process the line again along with normal
685 # includes.
686 line_num -= 1
[email protected]ac294a12012-12-06 16:38:43687 break
[email protected]cf9b78f2012-11-14 11:40:28688
689 # Split into scopes: Each region between #if and #endif is its own scope.
690 scopes = []
691 current_scope = []
692 for line in contents[line_num:]:
693 line_num += 1
[email protected]0e5c1852012-12-18 20:17:11694 if uncheckable_includes_pattern.match(line):
[email protected]4436c9e2014-01-07 23:19:54695 continue
[email protected]2309b0fa02012-11-16 12:18:27696 if if_pattern.match(line):
[email protected]cf9b78f2012-11-14 11:40:28697 scopes.append(current_scope)
698 current_scope = []
[email protected]962f117e2012-11-22 18:11:56699 elif ((system_include_pattern.match(line) or
700 custom_include_pattern.match(line)) and
701 not excluded_include_pattern.match(line)):
[email protected]cf9b78f2012-11-14 11:40:28702 current_scope.append((line_num, line))
703 scopes.append(current_scope)
704
705 for scope in scopes:
706 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
707 changed_linenums))
708 return warnings
709
710
711def _CheckIncludeOrder(input_api, output_api):
712 """Checks that the #include order is correct.
713
714 1. The corresponding header for source files.
715 2. C system files in alphabetical order
716 3. C++ system files in alphabetical order
717 4. Project's .h files in alphabetical order
718
[email protected]ac294a12012-12-06 16:38:43719 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
720 these rules separately.
[email protected]cf9b78f2012-11-14 11:40:28721 """
[email protected]e120b012014-08-15 19:08:35722 def FileFilterIncludeOrder(affected_file):
723 black_list = (_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST)
724 return input_api.FilterSourceFile(affected_file, black_list=black_list)
[email protected]cf9b78f2012-11-14 11:40:28725
726 warnings = []
[email protected]e120b012014-08-15 19:08:35727 for f in input_api.AffectedFiles(file_filter=FileFilterIncludeOrder):
[email protected]ac294a12012-12-06 16:38:43728 if f.LocalPath().endswith(('.cc', '.h')):
729 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
730 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
[email protected]cf9b78f2012-11-14 11:40:28731
732 results = []
733 if warnings:
[email protected]f7051d52013-04-02 18:31:42734 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
[email protected]120cf540d2012-12-10 17:55:53735 warnings))
[email protected]cf9b78f2012-11-14 11:40:28736 return results
737
738
[email protected]70ca77752012-11-20 03:45:03739def _CheckForVersionControlConflictsInFile(input_api, f):
740 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
741 errors = []
742 for line_num, line in f.ChangedContents():
743 if pattern.match(line):
744 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
745 return errors
746
747
748def _CheckForVersionControlConflicts(input_api, output_api):
749 """Usually this is not intentional and will cause a compile failure."""
750 errors = []
751 for f in input_api.AffectedFiles():
752 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
753
754 results = []
755 if errors:
756 results.append(output_api.PresubmitError(
757 'Version control conflict markers found, please resolve.', errors))
758 return results
759
760
[email protected]06e6d0ff2012-12-11 01:36:44761def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
762 def FilterFile(affected_file):
763 """Filter function for use with input_api.AffectedSourceFiles,
764 below. This filters out everything except non-test files from
765 top-level directories that generally speaking should not hard-code
766 service URLs (e.g. src/android_webview/, src/content/ and others).
767 """
768 return input_api.FilterSourceFile(
769 affected_file,
[email protected]78bb39d62012-12-11 15:11:56770 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
[email protected]06e6d0ff2012-12-11 01:36:44771 black_list=(_EXCLUDED_PATHS +
772 _TEST_CODE_EXCLUDED_PATHS +
773 input_api.DEFAULT_BLACK_LIST))
774
[email protected]de4f7d22013-05-23 14:27:46775 base_pattern = '"[^"]*google\.com[^"]*"'
776 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
777 pattern = input_api.re.compile(base_pattern)
[email protected]06e6d0ff2012-12-11 01:36:44778 problems = [] # items are (filename, line_number, line)
779 for f in input_api.AffectedSourceFiles(FilterFile):
780 for line_num, line in f.ChangedContents():
[email protected]de4f7d22013-05-23 14:27:46781 if not comment_pattern.search(line) and pattern.search(line):
[email protected]06e6d0ff2012-12-11 01:36:44782 problems.append((f.LocalPath(), line_num, line))
783
784 if problems:
[email protected]f7051d52013-04-02 18:31:42785 return [output_api.PresubmitPromptOrNotify(
[email protected]06e6d0ff2012-12-11 01:36:44786 'Most layers below src/chrome/ should not hardcode service URLs.\n'
[email protected]b0149772014-03-27 16:47:58787 'Are you sure this is correct?',
[email protected]06e6d0ff2012-12-11 01:36:44788 [' %s:%d: %s' % (
789 problem[0], problem[1], problem[2]) for problem in problems])]
[email protected]2fdd1f362013-01-16 03:56:03790 else:
791 return []
[email protected]06e6d0ff2012-12-11 01:36:44792
793
[email protected]d2530012013-01-25 16:39:27794def _CheckNoAbbreviationInPngFileName(input_api, output_api):
795 """Makes sure there are no abbreviations in the name of PNG files.
796 """
[email protected]4053a48e2013-01-25 21:43:04797 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
[email protected]d2530012013-01-25 16:39:27798 errors = []
799 for f in input_api.AffectedFiles(include_deletes=False):
800 if pattern.match(f.LocalPath()):
801 errors.append(' %s' % f.LocalPath())
802
803 results = []
804 if errors:
805 results.append(output_api.PresubmitError(
806 'The name of PNG files should not have abbreviations. \n'
807 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
808 'Contact [email protected] if you have questions.', errors))
809 return results
810
811
[email protected]14a6131c2014-01-08 01:15:41812def _FilesToCheckForIncomingDeps(re, changed_lines):
[email protected]f32e2d1e2013-07-26 21:39:08813 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
[email protected]14a6131c2014-01-08 01:15:41814 a set of DEPS entries that we should look up.
815
816 For a directory (rather than a specific filename) we fake a path to
817 a specific filename by adding /DEPS. This is chosen as a file that
818 will seldom or never be subject to per-file include_rules.
819 """
[email protected]2b438d62013-11-14 17:54:14820 # We ignore deps entries on auto-generated directories.
821 AUTO_GENERATED_DIRS = ['grit', 'jni']
[email protected]f32e2d1e2013-07-26 21:39:08822
823 # This pattern grabs the path without basename in the first
824 # parentheses, and the basename (if present) in the second. It
825 # relies on the simple heuristic that if there is a basename it will
826 # be a header file ending in ".h".
827 pattern = re.compile(
828 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
[email protected]2b438d62013-11-14 17:54:14829 results = set()
[email protected]f32e2d1e2013-07-26 21:39:08830 for changed_line in changed_lines:
831 m = pattern.match(changed_line)
832 if m:
833 path = m.group(1)
[email protected]2b438d62013-11-14 17:54:14834 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
[email protected]14a6131c2014-01-08 01:15:41835 if m.group(2):
836 results.add('%s%s' % (path, m.group(2)))
837 else:
838 results.add('%s/DEPS' % path)
[email protected]f32e2d1e2013-07-26 21:39:08839 return results
840
841
[email protected]e871964c2013-05-13 14:14:55842def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
843 """When a dependency prefixed with + is added to a DEPS file, we
844 want to make sure that the change is reviewed by an OWNER of the
845 target file or directory, to avoid layering violations from being
846 introduced. This check verifies that this happens.
847 """
848 changed_lines = set()
849 for f in input_api.AffectedFiles():
850 filename = input_api.os_path.basename(f.LocalPath())
851 if filename == 'DEPS':
852 changed_lines |= set(line.strip()
853 for line_num, line
854 in f.ChangedContents())
855 if not changed_lines:
856 return []
857
[email protected]14a6131c2014-01-08 01:15:41858 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
859 changed_lines)
[email protected]e871964c2013-05-13 14:14:55860 if not virtual_depended_on_files:
861 return []
862
863 if input_api.is_committing:
864 if input_api.tbr:
865 return [output_api.PresubmitNotifyResult(
866 '--tbr was specified, skipping OWNERS check for DEPS additions')]
867 if not input_api.change.issue:
868 return [output_api.PresubmitError(
869 "DEPS approval by OWNERS check failed: this change has "
870 "no Rietveld issue number, so we can't check it for approvals.")]
871 output = output_api.PresubmitError
872 else:
873 output = output_api.PresubmitNotifyResult
874
875 owners_db = input_api.owners_db
876 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
877 input_api,
878 owners_db.email_regexp,
879 approval_needed=input_api.is_committing)
880
881 owner_email = owner_email or input_api.change.author_email
882
[email protected]de4f7d22013-05-23 14:27:46883 reviewers_plus_owner = set(reviewers)
[email protected]e71c6082013-05-22 02:28:51884 if owner_email:
[email protected]de4f7d22013-05-23 14:27:46885 reviewers_plus_owner.add(owner_email)
[email protected]e871964c2013-05-13 14:14:55886 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
887 reviewers_plus_owner)
[email protected]14a6131c2014-01-08 01:15:41888
889 # We strip the /DEPS part that was added by
890 # _FilesToCheckForIncomingDeps to fake a path to a file in a
891 # directory.
892 def StripDeps(path):
893 start_deps = path.rfind('/DEPS')
894 if start_deps != -1:
895 return path[:start_deps]
896 else:
897 return path
898 unapproved_dependencies = ["'+%s'," % StripDeps(path)
[email protected]e871964c2013-05-13 14:14:55899 for path in missing_files]
900
901 if unapproved_dependencies:
902 output_list = [
[email protected]14a6131c2014-01-08 01:15:41903 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
[email protected]e871964c2013-05-13 14:14:55904 '\n '.join(sorted(unapproved_dependencies)))]
905 if not input_api.is_committing:
906 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
907 output_list.append(output(
908 'Suggested missing target path OWNERS:\n %s' %
909 '\n '.join(suggested_owners or [])))
910 return output_list
911
912 return []
913
914
[email protected]85218562013-11-22 07:41:40915def _CheckSpamLogging(input_api, output_api):
916 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
917 black_list = (_EXCLUDED_PATHS +
918 _TEST_CODE_EXCLUDED_PATHS +
919 input_api.DEFAULT_BLACK_LIST +
[email protected]6f742dd02013-11-26 23:19:50920 (r"^base[\\\/]logging\.h$",
[email protected]80f360a2014-01-23 01:36:19921 r"^base[\\\/]logging\.cc$",
[email protected]8dc338c2013-12-09 16:28:48922 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
[email protected]6e268db2013-12-04 01:41:46923 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
[email protected]4de75262013-12-18 23:16:12924 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
925 r"startup_browser_creator\.cc$",
[email protected]fe0e6e12013-12-04 05:52:58926 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
[email protected]8cf6f842014-08-08 21:33:16927 r"chrome[\\\/]browser[\\\/]diagnostics[\\\/]" +
[email protected]f5b9a3f342014-08-08 22:06:03928 r"diagnostics_writer\.cc$",
[email protected]9f13b602014-08-07 02:59:15929 r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
930 r"^chromecast[\\\/]",
931 r"^cloud_print[\\\/]",
[email protected]9056e732014-01-08 06:25:25932 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
933 r"gl_helper_benchmark\.cc$",
thestigc9e38a22014-09-13 01:02:11934 r"^courgette[\\\/]courgette_tool\.cc$",
[email protected]9f13b602014-08-07 02:59:15935 r"^extensions[\\\/]renderer[\\\/]logging_native_handler\.cc$",
[email protected]9c36d922014-03-24 16:47:52936 r"^native_client_sdk[\\\/]",
[email protected]cdbdced2013-11-27 21:35:50937 r"^remoting[\\\/]base[\\\/]logging\.h$",
[email protected]67c96ab2013-12-17 02:05:36938 r"^remoting[\\\/]host[\\\/].*",
[email protected]8232f8fd2013-12-14 00:52:31939 r"^sandbox[\\\/]linux[\\\/].*",
[email protected]0b7a21e2014-02-11 18:38:13940 r"^tools[\\\/]",
thestig22dfc4012014-09-05 08:29:44941 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",
942 r"^webkit[\\\/]browser[\\\/]fileapi[\\\/]" +
943 r"dump_file_system.cc$",))
[email protected]85218562013-11-22 07:41:40944 source_file_filter = lambda x: input_api.FilterSourceFile(
945 x, white_list=(file_inclusion_pattern,), black_list=black_list)
946
947 log_info = []
948 printf = []
949
950 for f in input_api.AffectedSourceFiles(source_file_filter):
951 contents = input_api.ReadFile(f, 'rb')
952 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
953 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37954 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
[email protected]85210652013-11-28 05:50:13955 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37956
957 if re.search(r"\bprintf\(", contents):
958 printf.append(f.LocalPath())
959 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
[email protected]85218562013-11-22 07:41:40960 printf.append(f.LocalPath())
961
962 if log_info:
963 return [output_api.PresubmitError(
964 'These files spam the console log with LOG(INFO):',
965 items=log_info)]
966 if printf:
967 return [output_api.PresubmitError(
968 'These files spam the console log with printf/fprintf:',
969 items=printf)]
970 return []
971
972
[email protected]49aa76a2013-12-04 06:59:16973def _CheckForAnonymousVariables(input_api, output_api):
974 """These types are all expected to hold locks while in scope and
975 so should never be anonymous (which causes them to be immediately
976 destroyed)."""
977 they_who_must_be_named = [
978 'base::AutoLock',
979 'base::AutoReset',
980 'base::AutoUnlock',
981 'SkAutoAlphaRestore',
982 'SkAutoBitmapShaderInstall',
983 'SkAutoBlitterChoose',
984 'SkAutoBounderCommit',
985 'SkAutoCallProc',
986 'SkAutoCanvasRestore',
987 'SkAutoCommentBlock',
988 'SkAutoDescriptor',
989 'SkAutoDisableDirectionCheck',
990 'SkAutoDisableOvalCheck',
991 'SkAutoFree',
992 'SkAutoGlyphCache',
993 'SkAutoHDC',
994 'SkAutoLockColors',
995 'SkAutoLockPixels',
996 'SkAutoMalloc',
997 'SkAutoMaskFreeImage',
998 'SkAutoMutexAcquire',
999 'SkAutoPathBoundsUpdate',
1000 'SkAutoPDFRelease',
1001 'SkAutoRasterClipValidate',
1002 'SkAutoRef',
1003 'SkAutoTime',
1004 'SkAutoTrace',
1005 'SkAutoUnref',
1006 ]
1007 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
1008 # bad: base::AutoLock(lock.get());
1009 # not bad: base::AutoLock lock(lock.get());
1010 bad_pattern = input_api.re.compile(anonymous)
1011 # good: new base::AutoLock(lock.get())
1012 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
1013 errors = []
1014
1015 for f in input_api.AffectedFiles():
1016 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
1017 continue
1018 for linenum, line in f.ChangedContents():
1019 if bad_pattern.search(line) and not good_pattern.search(line):
1020 errors.append('%s:%d' % (f.LocalPath(), linenum))
1021
1022 if errors:
1023 return [output_api.PresubmitError(
1024 'These lines create anonymous variables that need to be named:',
1025 items=errors)]
1026 return []
1027
1028
[email protected]5fe0f8742013-11-29 01:04:591029def _CheckCygwinShell(input_api, output_api):
1030 source_file_filter = lambda x: input_api.FilterSourceFile(
1031 x, white_list=(r'.+\.(gyp|gypi)$',))
1032 cygwin_shell = []
1033
1034 for f in input_api.AffectedSourceFiles(source_file_filter):
1035 for linenum, line in f.ChangedContents():
1036 if 'msvs_cygwin_shell' in line:
1037 cygwin_shell.append(f.LocalPath())
1038 break
1039
1040 if cygwin_shell:
1041 return [output_api.PresubmitError(
1042 'These files should not use msvs_cygwin_shell (the default is 0):',
1043 items=cygwin_shell)]
1044 return []
1045
[email protected]85218562013-11-22 07:41:401046
[email protected]999261d2014-03-03 20:08:081047def _CheckUserActionUpdate(input_api, output_api):
1048 """Checks if any new user action has been added."""
[email protected]2f92dec2014-03-07 19:21:521049 if any('actions.xml' == input_api.os_path.basename(f) for f in
[email protected]999261d2014-03-03 20:08:081050 input_api.LocalPaths()):
[email protected]2f92dec2014-03-07 19:21:521051 # If actions.xml is already included in the changelist, the PRESUBMIT
1052 # for actions.xml will do a more complete presubmit check.
[email protected]999261d2014-03-03 20:08:081053 return []
1054
[email protected]999261d2014-03-03 20:08:081055 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm'))
1056 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)'
[email protected]2f92dec2014-03-07 19:21:521057 current_actions = None
[email protected]999261d2014-03-03 20:08:081058 for f in input_api.AffectedFiles(file_filter=file_filter):
1059 for line_num, line in f.ChangedContents():
1060 match = input_api.re.search(action_re, line)
1061 if match:
[email protected]2f92dec2014-03-07 19:21:521062 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1063 # loaded only once.
1064 if not current_actions:
1065 with open('tools/metrics/actions/actions.xml') as actions_f:
1066 current_actions = actions_f.read()
1067 # Search for the matched user action name in |current_actions|.
[email protected]999261d2014-03-03 20:08:081068 for action_name in match.groups():
[email protected]2f92dec2014-03-07 19:21:521069 action = 'name="{0}"'.format(action_name)
1070 if action not in current_actions:
[email protected]999261d2014-03-03 20:08:081071 return [output_api.PresubmitPromptWarning(
1072 'File %s line %d: %s is missing in '
[email protected]2f92dec2014-03-07 19:21:521073 'tools/metrics/actions/actions.xml. Please run '
1074 'tools/metrics/actions/extract_actions.py to update.'
[email protected]999261d2014-03-03 20:08:081075 % (f.LocalPath(), line_num, action_name))]
1076 return []
1077
1078
[email protected]99171a92014-06-03 08:44:471079def _GetJSONParseError(input_api, filename, eat_comments=True):
1080 try:
1081 contents = input_api.ReadFile(filename)
1082 if eat_comments:
1083 json_comment_eater = input_api.os_path.join(
1084 input_api.PresubmitLocalPath(),
1085 'tools', 'json_comment_eater', 'json_comment_eater.py')
1086 process = input_api.subprocess.Popen(
1087 [input_api.python_executable, json_comment_eater],
1088 stdin=input_api.subprocess.PIPE,
1089 stdout=input_api.subprocess.PIPE,
1090 universal_newlines=True)
1091 (contents, _) = process.communicate(input=contents)
1092
1093 input_api.json.loads(contents)
1094 except ValueError as e:
1095 return e
1096 return None
1097
1098
1099def _GetIDLParseError(input_api, filename):
1100 try:
1101 contents = input_api.ReadFile(filename)
1102 idl_schema = input_api.os_path.join(
1103 input_api.PresubmitLocalPath(),
1104 'tools', 'json_schema_compiler', 'idl_schema.py')
1105 process = input_api.subprocess.Popen(
1106 [input_api.python_executable, idl_schema],
1107 stdin=input_api.subprocess.PIPE,
1108 stdout=input_api.subprocess.PIPE,
1109 stderr=input_api.subprocess.PIPE,
1110 universal_newlines=True)
1111 (_, error) = process.communicate(input=contents)
1112 return error or None
1113 except ValueError as e:
1114 return e
1115
1116
1117def _CheckParseErrors(input_api, output_api):
1118 """Check that IDL and JSON files do not contain syntax errors."""
1119 actions = {
1120 '.idl': _GetIDLParseError,
1121 '.json': _GetJSONParseError,
1122 }
1123 # These paths contain test data and other known invalid JSON files.
1124 excluded_patterns = [
joaodasilva718f87672014-08-30 09:25:491125 r'test[\\\/]data[\\\/]',
1126 r'^components[\\\/]policy[\\\/]resources[\\\/]policy_templates\.json$',
[email protected]99171a92014-06-03 08:44:471127 ]
1128 # Most JSON files are preprocessed and support comments, but these do not.
1129 json_no_comments_patterns = [
joaodasilva718f87672014-08-30 09:25:491130 r'^testing[\\\/]',
[email protected]99171a92014-06-03 08:44:471131 ]
1132 # Only run IDL checker on files in these directories.
1133 idl_included_patterns = [
joaodasilva718f87672014-08-30 09:25:491134 r'^chrome[\\\/]common[\\\/]extensions[\\\/]api[\\\/]',
1135 r'^extensions[\\\/]common[\\\/]api[\\\/]',
[email protected]99171a92014-06-03 08:44:471136 ]
1137
1138 def get_action(affected_file):
1139 filename = affected_file.LocalPath()
1140 return actions.get(input_api.os_path.splitext(filename)[1])
1141
1142 def MatchesFile(patterns, path):
1143 for pattern in patterns:
1144 if input_api.re.search(pattern, path):
1145 return True
1146 return False
1147
1148 def FilterFile(affected_file):
1149 action = get_action(affected_file)
1150 if not action:
1151 return False
1152 path = affected_file.LocalPath()
1153
1154 if MatchesFile(excluded_patterns, path):
1155 return False
1156
1157 if (action == _GetIDLParseError and
1158 not MatchesFile(idl_included_patterns, path)):
1159 return False
1160 return True
1161
1162 results = []
1163 for affected_file in input_api.AffectedFiles(
1164 file_filter=FilterFile, include_deletes=False):
1165 action = get_action(affected_file)
1166 kwargs = {}
1167 if (action == _GetJSONParseError and
1168 MatchesFile(json_no_comments_patterns, affected_file.LocalPath())):
1169 kwargs['eat_comments'] = False
1170 parse_error = action(input_api,
1171 affected_file.AbsoluteLocalPath(),
1172 **kwargs)
1173 if parse_error:
1174 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
1175 (affected_file.LocalPath(), parse_error)))
1176 return results
1177
1178
[email protected]760deea2013-12-10 19:33:491179def _CheckJavaStyle(input_api, output_api):
1180 """Runs checkstyle on changed java files and returns errors if any exist."""
1181 original_sys_path = sys.path
1182 try:
1183 sys.path = sys.path + [input_api.os_path.join(
1184 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1185 import checkstyle
1186 finally:
1187 # Restore sys.path to what it was before.
1188 sys.path = original_sys_path
1189
1190 return checkstyle.RunCheckstyle(
1191 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1192
1193
[email protected]fd20b902014-05-09 02:14:531194_DEPRECATED_CSS = [
1195 # Values
1196 ( "-webkit-box", "flex" ),
1197 ( "-webkit-inline-box", "inline-flex" ),
1198 ( "-webkit-flex", "flex" ),
1199 ( "-webkit-inline-flex", "inline-flex" ),
1200 ( "-webkit-min-content", "min-content" ),
1201 ( "-webkit-max-content", "max-content" ),
1202
1203 # Properties
1204 ( "-webkit-background-clip", "background-clip" ),
1205 ( "-webkit-background-origin", "background-origin" ),
1206 ( "-webkit-background-size", "background-size" ),
1207 ( "-webkit-box-shadow", "box-shadow" ),
1208
1209 # Functions
1210 ( "-webkit-gradient", "gradient" ),
1211 ( "-webkit-repeating-gradient", "repeating-gradient" ),
1212 ( "-webkit-linear-gradient", "linear-gradient" ),
1213 ( "-webkit-repeating-linear-gradient", "repeating-linear-gradient" ),
1214 ( "-webkit-radial-gradient", "radial-gradient" ),
1215 ( "-webkit-repeating-radial-gradient", "repeating-radial-gradient" ),
1216]
1217
1218def _CheckNoDeprecatedCSS(input_api, output_api):
1219 """ Make sure that we don't use deprecated CSS
[email protected]9a48e3f82014-05-22 00:06:251220 properties, functions or values. Our external
1221 documentation is ignored by the hooks as it
1222 needs to be consumed by WebKit. """
[email protected]fd20b902014-05-09 02:14:531223 results = []
[email protected]9a48e3f82014-05-22 00:06:251224 file_inclusion_pattern = (r".+\.css$")
1225 black_list = (_EXCLUDED_PATHS +
1226 _TEST_CODE_EXCLUDED_PATHS +
1227 input_api.DEFAULT_BLACK_LIST +
1228 (r"^chrome/common/extensions/docs",
1229 r"^chrome/docs",
1230 r"^native_client_sdk"))
1231 file_filter = lambda f: input_api.FilterSourceFile(
1232 f, white_list=file_inclusion_pattern, black_list=black_list)
[email protected]fd20b902014-05-09 02:14:531233 for fpath in input_api.AffectedFiles(file_filter=file_filter):
1234 for line_num, line in fpath.ChangedContents():
1235 for (deprecated_value, value) in _DEPRECATED_CSS:
1236 if input_api.re.search(deprecated_value, line):
1237 results.append(output_api.PresubmitError(
1238 "%s:%d: Use of deprecated CSS %s, use %s instead" %
1239 (fpath.LocalPath(), line_num, deprecated_value, value)))
1240 return results
1241
[email protected]22c9bd72011-03-27 16:47:391242def _CommonChecks(input_api, output_api):
1243 """Checks common to both upload and commit."""
1244 results = []
1245 results.extend(input_api.canned_checks.PanProjectChecks(
[email protected]3de922f2013-12-20 13:27:381246 input_api, output_api,
1247 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
[email protected]66daa702011-05-28 14:41:461248 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]55459852011-08-10 15:17:191249 results.extend(
[email protected]760deea2013-12-10 19:33:491250 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
[email protected]10689ca2011-09-02 02:31:541251 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
[email protected]72df4e782012-06-21 16:28:181252 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
[email protected]8ea5d4b2011-09-13 21:49:221253 results.extend(_CheckNoNewWStrings(input_api, output_api))
[email protected]2a8ac9c2011-10-19 17:20:441254 results.extend(_CheckNoDEPSGIT(input_api, output_api))
[email protected]127f18ec2012-06-16 05:05:591255 results.extend(_CheckNoBannedFunctions(input_api, output_api))
[email protected]6c063c62012-07-11 19:11:061256 results.extend(_CheckNoPragmaOnce(input_api, output_api))
[email protected]e7479052012-09-19 00:26:121257 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
[email protected]55f9f382012-07-31 11:02:181258 results.extend(_CheckUnwantedDependencies(input_api, output_api))
[email protected]fbcafe5a2012-08-08 15:31:221259 results.extend(_CheckFilePermissions(input_api, output_api))
[email protected]c8278b32012-10-30 20:35:491260 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
[email protected]2309b0fa02012-11-16 12:18:271261 results.extend(_CheckIncludeOrder(input_api, output_api))
[email protected]70ca77752012-11-20 03:45:031262 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
[email protected]b8079ae4a2012-12-05 19:56:491263 results.extend(_CheckPatchFiles(input_api, output_api))
[email protected]06e6d0ff2012-12-11 01:36:441264 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
[email protected]d2530012013-01-25 16:39:271265 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
[email protected]b00342e7f2013-03-26 16:21:541266 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
[email protected]e871964c2013-05-13 14:14:551267 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
[email protected]9f919cc2013-07-31 03:04:041268 results.extend(
1269 input_api.canned_checks.CheckChangeHasNoTabs(
1270 input_api,
1271 output_api,
1272 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
[email protected]85218562013-11-22 07:41:401273 results.extend(_CheckSpamLogging(input_api, output_api))
[email protected]49aa76a2013-12-04 06:59:161274 results.extend(_CheckForAnonymousVariables(input_api, output_api))
[email protected]5fe0f8742013-11-29 01:04:591275 results.extend(_CheckCygwinShell(input_api, output_api))
[email protected]999261d2014-03-03 20:08:081276 results.extend(_CheckUserActionUpdate(input_api, output_api))
[email protected]fd20b902014-05-09 02:14:531277 results.extend(_CheckNoDeprecatedCSS(input_api, output_api))
[email protected]99171a92014-06-03 08:44:471278 results.extend(_CheckParseErrors(input_api, output_api))
[email protected]2299dcf2012-11-15 19:56:241279
1280 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1281 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1282 input_api, output_api,
1283 input_api.PresubmitLocalPath(),
[email protected]6be63382013-01-21 15:42:381284 whitelist=[r'^PRESUBMIT_test\.py$']))
[email protected]22c9bd72011-03-27 16:47:391285 return results
[email protected]1f7b4172010-01-28 01:17:341286
[email protected]b337cb5b2011-01-23 21:24:051287
[email protected]66daa702011-05-28 14:41:461288def _CheckAuthorizedAuthor(input_api, output_api):
1289 """For non-googler/chromites committers, verify the author's email address is
1290 in AUTHORS.
1291 """
[email protected]9bb9cb82011-06-13 20:43:011292 # TODO(maruel): Add it to input_api?
1293 import fnmatch
1294
[email protected]66daa702011-05-28 14:41:461295 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:011296 if not author:
1297 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:461298 return []
[email protected]c99663292011-05-31 19:46:081299 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:461300 input_api.PresubmitLocalPath(), 'AUTHORS')
1301 valid_authors = (
1302 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1303 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:181304 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]d8b50be2011-06-15 14:19:441305 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]5861efb2013-01-07 18:33:231306 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
[email protected]66daa702011-05-28 14:41:461307 return [output_api.PresubmitPromptWarning(
1308 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1309 '\n'
1310 'http://www.chromium.org/developers/contributing-code and read the '
1311 '"Legal" section\n'
1312 'If you are a chromite, verify the contributor signed the CLA.') %
1313 author)]
1314 return []
1315
1316
[email protected]b8079ae4a2012-12-05 19:56:491317def _CheckPatchFiles(input_api, output_api):
1318 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1319 if f.LocalPath().endswith(('.orig', '.rej'))]
1320 if problems:
1321 return [output_api.PresubmitError(
1322 "Don't commit .rej and .orig files.", problems)]
[email protected]2fdd1f362013-01-16 03:56:031323 else:
1324 return []
[email protected]b8079ae4a2012-12-05 19:56:491325
1326
[email protected]b00342e7f2013-03-26 16:21:541327def _DidYouMeanOSMacro(bad_macro):
1328 try:
1329 return {'A': 'OS_ANDROID',
1330 'B': 'OS_BSD',
1331 'C': 'OS_CHROMEOS',
1332 'F': 'OS_FREEBSD',
1333 'L': 'OS_LINUX',
1334 'M': 'OS_MACOSX',
1335 'N': 'OS_NACL',
1336 'O': 'OS_OPENBSD',
1337 'P': 'OS_POSIX',
1338 'S': 'OS_SOLARIS',
1339 'W': 'OS_WIN'}[bad_macro[3].upper()]
1340 except KeyError:
1341 return ''
1342
1343
1344def _CheckForInvalidOSMacrosInFile(input_api, f):
1345 """Check for sensible looking, totally invalid OS macros."""
1346 preprocessor_statement = input_api.re.compile(r'^\s*#')
1347 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1348 results = []
1349 for lnum, line in f.ChangedContents():
1350 if preprocessor_statement.search(line):
1351 for match in os_macro.finditer(line):
1352 if not match.group(1) in _VALID_OS_MACROS:
1353 good = _DidYouMeanOSMacro(match.group(1))
1354 did_you_mean = ' (did you mean %s?)' % good if good else ''
1355 results.append(' %s:%d %s%s' % (f.LocalPath(),
1356 lnum,
1357 match.group(1),
1358 did_you_mean))
1359 return results
1360
1361
1362def _CheckForInvalidOSMacros(input_api, output_api):
1363 """Check all affected files for invalid OS macros."""
1364 bad_macros = []
1365 for f in input_api.AffectedFiles():
1366 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1367 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1368
1369 if not bad_macros:
1370 return []
1371
1372 return [output_api.PresubmitError(
1373 'Possibly invalid OS macro[s] found. Please fix your code\n'
1374 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1375
1376
[email protected]1f7b4172010-01-28 01:17:341377def CheckChangeOnUpload(input_api, output_api):
1378 results = []
1379 results.extend(_CommonChecks(input_api, output_api))
[email protected]ae69ae72014-02-20 13:09:361380 results.extend(_CheckJavaStyle(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541381 return results
[email protected]ca8d1982009-02-19 16:33:121382
1383
[email protected]1bfb8322014-04-23 01:02:411384def GetTryServerMasterForBot(bot):
1385 """Returns the Try Server master for the given bot.
1386
[email protected]0bb112362014-07-26 04:38:321387 It tries to guess the master from the bot name, but may still fail
1388 and return None. There is no longer a default master.
1389 """
1390 # Potentially ambiguous bot names are listed explicitly.
1391 master_map = {
[email protected]1bfb8322014-04-23 01:02:411392 'linux_gpu': 'tryserver.chromium.gpu',
[email protected]5c5f13042014-05-09 21:28:301393 'mac_gpu': 'tryserver.chromium.gpu',
[email protected]d263d5b2014-04-30 01:15:551394 'win_gpu': 'tryserver.chromium.gpu',
[email protected]0bb112362014-07-26 04:38:321395 'chromium_presubmit': 'tryserver.chromium.linux',
1396 'blink_presubmit': 'tryserver.chromium.linux',
1397 'tools_build_presubmit': 'tryserver.chromium.linux',
[email protected]1bfb8322014-04-23 01:02:411398 }
[email protected]0bb112362014-07-26 04:38:321399 master = master_map.get(bot)
1400 if not master:
1401 if 'gpu' in bot:
1402 master = 'tryserver.chromium.gpu'
1403 elif 'linux' in bot or 'android' in bot or 'presubmit' in bot:
1404 master = 'tryserver.chromium.linux'
1405 elif 'win' in bot:
1406 master = 'tryserver.chromium.win'
1407 elif 'mac' in bot or 'ios' in bot:
1408 master = 'tryserver.chromium.mac'
1409 return master
[email protected]1bfb8322014-04-23 01:02:411410
1411
[email protected]38c6a512013-12-18 23:48:011412def GetDefaultTryConfigs(bots=None):
1413 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1414
1415 To add tests to this list, they MUST be in the the corresponding master's
1416 gatekeeper config. For example, anything on master.chromium would be closed by
1417 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1418
1419 If 'bots' is specified, will only return configurations for bots in that list.
1420 """
1421
1422 standard_tests = [
1423 'base_unittests',
1424 'browser_tests',
1425 'cacheinvalidation_unittests',
1426 'check_deps',
1427 'check_deps2git',
1428 'content_browsertests',
1429 'content_unittests',
1430 'crypto_unittests',
[email protected]38c6a512013-12-18 23:48:011431 'gpu_unittests',
1432 'interactive_ui_tests',
1433 'ipc_tests',
1434 'jingle_unittests',
1435 'media_unittests',
1436 'net_unittests',
1437 'ppapi_unittests',
1438 'printing_unittests',
1439 'sql_unittests',
1440 'sync_unit_tests',
1441 'unit_tests',
1442 # Broken in release.
1443 #'url_unittests',
1444 #'webkit_unit_tests',
1445 ]
1446
[email protected]38c6a512013-12-18 23:48:011447 builders_and_tests = {
1448 # TODO(maruel): Figure out a way to run 'sizes' where people can
1449 # effectively update the perf expectation correctly. This requires a
1450 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1451 # incremental build. Reference:
1452 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1453 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1454 # of this step as a try job failure.
1455 'android_aosp': ['compile'],
[email protected]5a65d3042014-05-07 14:26:011456 'android_chromium_gn_compile_rel': ['compile'],
[email protected]38c6a512013-12-18 23:48:011457 'android_clang_dbg': ['slave_steps'],
[email protected]5bd4f0cd2014-08-22 21:59:291458 'android_dbg_tests_recipe': ['slave_steps'],
[email protected]38c6a512013-12-18 23:48:011459 'cros_x86': ['defaulttests'],
1460 'ios_dbg_simulator': [
1461 'compile',
1462 'base_unittests',
1463 'content_unittests',
1464 'crypto_unittests',
1465 'url_unittests',
1466 'net_unittests',
1467 'sql_unittests',
1468 'ui_unittests',
1469 ],
1470 'ios_rel_device': ['compile'],
[email protected]971b08ce2014-03-19 22:03:561471 'linux_asan': ['compile'],
1472 'mac_asan': ['compile'],
[email protected]38c6a512013-12-18 23:48:011473 #TODO(stip): Change the name of this builder to reflect that it's release.
[email protected]71afb4ec2014-02-07 02:45:131474 'linux_gtk': standard_tests,
[email protected]971b08ce2014-03-19 22:03:561475 'linux_chromeos_asan': ['compile'],
[email protected]d910b6082014-02-27 18:15:431476 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
[email protected]ce51953982014-08-07 15:43:241477 'linux_chromium_chromeos_rel_swarming': ['defaulttests'],
[email protected]d910b6082014-02-27 18:15:431478 'linux_chromium_compile_dbg': ['defaulttests'],
[email protected]5a65d3042014-05-07 14:26:011479 'linux_chromium_gn_rel': ['defaulttests'],
[email protected]0bb112362014-07-26 04:38:321480 'linux_chromium_rel_swarming': ['defaulttests'],
[email protected]d910b6082014-02-27 18:15:431481 'linux_chromium_clang_dbg': ['defaulttests'],
[email protected]1bfb8322014-04-23 01:02:411482 'linux_gpu': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021483 'linux_nacl_sdk_build': ['compile'],
[email protected]d910b6082014-02-27 18:15:431484 'mac_chromium_compile_dbg': ['defaulttests'],
[email protected]ce51953982014-08-07 15:43:241485 'mac_chromium_rel_swarming': ['defaulttests'],
[email protected]5c5f13042014-05-09 21:28:301486 'mac_gpu': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021487 'mac_nacl_sdk_build': ['compile'],
[email protected]0094fa12014-03-13 03:18:281488 'win_chromium_compile_dbg': ['defaulttests'],
[email protected]c17144e42014-04-15 09:32:431489 'win_chromium_dbg': ['defaulttests'],
[email protected]02a7f6362014-08-13 02:04:161490 'win_chromium_rel_swarming': ['defaulttests'],
[email protected]c0f4e82b2014-08-15 23:35:341491 'win_chromium_x64_rel_swarming': ['defaulttests'],
[email protected]d263d5b2014-04-30 01:15:551492 'win_gpu': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021493 'win_nacl_sdk_build': ['compile'],
danakjc89745a2014-09-16 01:33:031494 'win8_chromium_rel': ['defaulttests'],
[email protected]38c6a512013-12-18 23:48:011495 }
1496
[email protected]38c6a512013-12-18 23:48:011497 if bots:
[email protected]1bfb8322014-04-23 01:02:411498 filtered_builders_and_tests = dict((bot, set(builders_and_tests[bot]))
1499 for bot in bots)
[email protected]38c6a512013-12-18 23:48:011500 else:
[email protected]1bfb8322014-04-23 01:02:411501 filtered_builders_and_tests = dict(
1502 (bot, set(tests))
1503 for bot, tests in builders_and_tests.iteritems())
1504
1505 # Build up the mapping from tryserver master to bot/test.
1506 out = dict()
1507 for bot, tests in filtered_builders_and_tests.iteritems():
1508 out.setdefault(GetTryServerMasterForBot(bot), {})[bot] = tests
1509 return out
[email protected]38c6a512013-12-18 23:48:011510
1511
[email protected]ca8d1982009-02-19 16:33:121512def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:541513 results = []
[email protected]1f7b4172010-01-28 01:17:341514 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:511515 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1516 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1517 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:541518 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:271519 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:341520 input_api,
1521 output_api,
[email protected]2fdd1f362013-01-16 03:56:031522 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:271523
[email protected]3e4eb112011-01-18 03:29:541524 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1525 input_api, output_api))
[email protected]c4b47562011-12-05 23:39:411526 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1527 input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541528 return results
[email protected]ca8d1982009-02-19 16:33:121529
1530
[email protected]7468ac522014-03-12 23:35:571531def GetPreferredTryMasters(project, change):
[email protected]4ce995ea2012-06-27 02:13:101532 files = change.LocalPaths()
1533
joaodasilva718f87672014-08-30 09:25:491534 if not files or all(re.search(r'[\\\/]OWNERS$', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571535 return {}
[email protected]3019c902012-06-29 00:09:031536
joaodasilva718f87672014-08-30 09:25:491537 if all(re.search(r'\.(m|mm)$|(^|[\\\/_])mac[\\\/_.]', f) for f in files):
[email protected]d96b1f42014-02-27 19:17:521538 return GetDefaultTryConfigs([
1539 'mac_chromium_compile_dbg',
[email protected]e6890ec2014-08-07 16:59:421540 'mac_chromium_rel_swarming',
[email protected]d96b1f42014-02-27 19:17:521541 ])
[email protected]d668899a2012-09-06 18:16:591542 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
[email protected]02a7f6362014-08-13 02:04:161543 return GetDefaultTryConfigs([
1544 'win_chromium_dbg',
1545 'win_chromium_rel_swarming',
danakjc89745a2014-09-16 01:33:031546 'win8_chromium_rel',
[email protected]02a7f6362014-08-13 02:04:161547 ])
joaodasilva718f87672014-08-30 09:25:491548 if all(re.search(r'(^|[\\\/_])android[\\\/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011549 return GetDefaultTryConfigs([
1550 'android_aosp',
1551 'android_clang_dbg',
[email protected]5bd4f0cd2014-08-22 21:59:291552 'android_dbg_tests_recipe',
[email protected]38c6a512013-12-18 23:48:011553 ])
joaodasilva718f87672014-08-30 09:25:491554 if all(re.search(r'[\\\/_]ios[\\\/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011555 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
[email protected]4ce995ea2012-06-27 02:13:101556
[email protected]7468ac522014-03-12 23:35:571557 builders = [
[email protected]5a65d3042014-05-07 14:26:011558 'android_chromium_gn_compile_rel',
[email protected]3e2f0402012-11-02 16:28:011559 'android_clang_dbg',
[email protected]5bd4f0cd2014-08-22 21:59:291560 'android_dbg_tests_recipe',
[email protected]3e2f0402012-11-02 16:28:011561 'ios_dbg_simulator',
1562 'ios_rel_device',
[email protected]e6890ec2014-08-07 16:59:421563 'linux_chromium_chromeos_rel_swarming',
[email protected]d96b1f42014-02-27 19:17:521564 'linux_chromium_clang_dbg',
[email protected]5a65d3042014-05-07 14:26:011565 'linux_chromium_gn_rel',
[email protected]0bb112362014-07-26 04:38:321566 'linux_chromium_rel_swarming',
[email protected]1bfb8322014-04-23 01:02:411567 'linux_gpu',
[email protected]d96b1f42014-02-27 19:17:521568 'mac_chromium_compile_dbg',
[email protected]e6890ec2014-08-07 16:59:421569 'mac_chromium_rel_swarming',
[email protected]5c5f13042014-05-09 21:28:301570 'mac_gpu',
[email protected]0094fa12014-03-13 03:18:281571 'win_chromium_compile_dbg',
[email protected]02a7f6362014-08-13 02:04:161572 'win_chromium_rel_swarming',
[email protected]c0f4e82b2014-08-15 23:35:341573 'win_chromium_x64_rel_swarming',
[email protected]d263d5b2014-04-30 01:15:551574 'win_gpu',
danakjc89745a2014-09-16 01:33:031575 'win8_chromium_rel',
[email protected]7468ac522014-03-12 23:35:571576 ]
[email protected]911753b2012-08-02 12:11:541577
1578 # Match things like path/aura/file.cc and path/file_aura.cc.
[email protected]95c989162012-11-29 05:58:251579 # Same for chromeos.
joaodasilva718f87672014-08-30 09:25:491580 if any(re.search(r'[\\\/_](aura|chromeos)', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571581 builders.extend([
1582 'linux_chromeos_asan',
1583 'linux_chromium_chromeos_clang_dbg'
1584 ])
[email protected]4ce995ea2012-06-27 02:13:101585
[email protected]e8df48f2013-09-30 20:07:541586 # If there are gyp changes to base, build, or chromeos, run a full cros build
1587 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1588 # files have a much higher chance of breaking the cros build, which is
1589 # differnt from the linux_chromeos build that most chrome developers test
1590 # with.
1591 if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571592 builders.extend(['cros_x86'])
[email protected]e8df48f2013-09-30 20:07:541593
[email protected]d95948ef2013-07-02 10:51:001594 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1595 # unless they're .gyp(i) files as changes to those files can break the gyp
1596 # step on that bot.
1597 if (not all(re.search('^chrome', f) for f in files) or
1598 any(re.search('\.gypi?$', f) for f in files)):
[email protected]7468ac522014-03-12 23:35:571599 builders.extend(['android_aosp'])
[email protected]d95948ef2013-07-02 10:51:001600
[email protected]7468ac522014-03-12 23:35:571601 return GetDefaultTryConfigs(builders)