blob: f808fed61655eb9ce2eb4db9af5fd1a3870d5230 [file] [log] [blame]
[email protected]a18130a2012-01-03 17:52:081# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ca8d19842009-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]ca8d19842009-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]ca8d19842009-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 = (
45 r'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
46 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,
50 r'.*[/\\](test|tool(s)?)[/\\].*',
[email protected]ef070cc2013-05-03 11:53:0551 # content_shell is used for running layout tests.
52 r'content[/\\]shell[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4453 # At request of folks maintaining this folder.
54 r'chrome[/\\]browser[/\\]automation[/\\].*',
[email protected]7b054982013-11-27 00:44:4755 # Non-production example code.
56 r'mojo[/\\]examples[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4457)
[email protected]ca8d19842009-02-19 16:33:1258
[email protected]eea609a2011-11-18 13:10:1259_TEST_ONLY_WARNING = (
60 'You might be calling functions intended only for testing from\n'
61 'production code. It is OK to ignore this warning if you know what\n'
62 'you are doing, as the heuristics used to detect the situation are\n'
[email protected]b0149772014-03-27 16:47:5863 'not perfect. The commit queue will not block on this warning.')
[email protected]eea609a2011-11-18 13:10:1264
65
[email protected]cf9b78f2012-11-14 11:40:2866_INCLUDE_ORDER_WARNING = (
67 'Your #include order seems to be broken. Send mail to\n'
68 '[email protected] if this is not the case.')
69
70
[email protected]127f18ec2012-06-16 05:05:5971_BANNED_OBJC_FUNCTIONS = (
72 (
73 'addTrackingRect:',
[email protected]23e6cbc2012-06-16 18:51:2074 (
75 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
[email protected]127f18ec2012-06-16 05:05:5976 'prohibited. Please use CrTrackingArea instead.',
77 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
78 ),
79 False,
80 ),
81 (
82 'NSTrackingArea',
[email protected]23e6cbc2012-06-16 18:51:2083 (
84 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
[email protected]127f18ec2012-06-16 05:05:5985 'instead.',
86 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
87 ),
88 False,
89 ),
90 (
91 'convertPointFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2092 (
93 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5994 'Please use |convertPoint:(point) fromView:nil| instead.',
95 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
96 ),
97 True,
98 ),
99 (
100 'convertPointToBase:',
[email protected]23e6cbc2012-06-16 18:51:20101 (
102 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59103 'Please use |convertPoint:(point) toView:nil| instead.',
104 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
105 ),
106 True,
107 ),
108 (
109 'convertRectFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20110 (
111 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59112 'Please use |convertRect:(point) fromView:nil| instead.',
113 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
114 ),
115 True,
116 ),
117 (
118 'convertRectToBase:',
[email protected]23e6cbc2012-06-16 18:51:20119 (
120 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59121 'Please use |convertRect:(point) toView:nil| instead.',
122 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
123 ),
124 True,
125 ),
126 (
127 'convertSizeFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20128 (
129 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59130 'Please use |convertSize:(point) fromView:nil| instead.',
131 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
132 ),
133 True,
134 ),
135 (
136 'convertSizeToBase:',
[email protected]23e6cbc2012-06-16 18:51:20137 (
138 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59139 'Please use |convertSize:(point) toView:nil| instead.',
140 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
141 ),
142 True,
143 ),
144)
145
146
147_BANNED_CPP_FUNCTIONS = (
[email protected]23e6cbc2012-06-16 18:51:20148 # Make sure that gtest's FRIEND_TEST() macro is not used; the
149 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
[email protected]e00ccc92012-11-01 17:32:30150 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
[email protected]23e6cbc2012-06-16 18:51:20151 (
152 'FRIEND_TEST(',
153 (
[email protected]e3c945502012-06-26 20:01:49154 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
[email protected]23e6cbc2012-06-16 18:51:20155 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
156 ),
157 False,
[email protected]7345da02012-11-27 14:31:49158 (),
[email protected]23e6cbc2012-06-16 18:51:20159 ),
160 (
161 'ScopedAllowIO',
162 (
[email protected]e3c945502012-06-26 20:01:49163 'New code should not use ScopedAllowIO. Post a task to the blocking',
164 'pool or the FILE thread instead.',
[email protected]23e6cbc2012-06-16 18:51:20165 ),
[email protected]e3c945502012-06-26 20:01:49166 True,
[email protected]7345da02012-11-27 14:31:49167 (
[email protected]0b818f72013-10-22 00:11:03168 r"^components[\\\/]breakpad[\\\/]app[\\\/]breakpad_mac\.mm$",
[email protected]de7d61ff2013-08-20 11:30:41169 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
170 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
[email protected]ac1df702014-03-21 20:45:27171 r"^mojo[\\\/]system[\\\/]raw_shared_buffer_posix\.cc$",
[email protected]398ad132013-04-02 15:11:01172 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
[email protected]7345da02012-11-27 14:31:49173 ),
[email protected]23e6cbc2012-06-16 18:51:20174 ),
[email protected]52657f62013-05-20 05:30:31175 (
176 'SkRefPtr',
177 (
178 'The use of SkRefPtr is prohibited. ',
179 'Please use skia::RefPtr instead.'
180 ),
181 True,
182 (),
183 ),
184 (
185 'SkAutoRef',
186 (
187 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
188 'Please use skia::RefPtr instead.'
189 ),
190 True,
191 (),
192 ),
193 (
194 'SkAutoTUnref',
195 (
196 'The use of SkAutoTUnref is dangerous because it implicitly ',
197 'converts to a raw pointer. Please use skia::RefPtr instead.'
198 ),
199 True,
200 (),
201 ),
202 (
203 'SkAutoUnref',
204 (
205 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
206 'because it implicitly converts to a raw pointer. ',
207 'Please use skia::RefPtr instead.'
208 ),
209 True,
210 (),
211 ),
[email protected]d89eec82013-12-03 14:10:59212 (
213 r'/HANDLE_EINTR\(.*close',
214 (
215 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
216 'descriptor will be closed, and it is incorrect to retry the close.',
217 'Either call close directly and ignore its return value, or wrap close',
218 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
219 ),
220 True,
221 (),
222 ),
223 (
224 r'/IGNORE_EINTR\((?!.*close)',
225 (
226 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
227 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
228 ),
229 True,
230 (
231 # Files that #define IGNORE_EINTR.
232 r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
233 r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
234 ),
235 ),
[email protected]ec5b3f02014-04-04 18:43:43236 (
237 r'/v8::Extension\(',
238 (
239 'Do not introduce new v8::Extensions into the code base, use',
240 'gin::Wrappable instead. See http://crbug.com/334679',
241 ),
242 True,
243 (),
244 ),
[email protected]127f18ec2012-06-16 05:05:59245)
246
247
[email protected]b00342e7f2013-03-26 16:21:54248_VALID_OS_MACROS = (
249 # Please keep sorted.
250 'OS_ANDROID',
[email protected]f4440b42014-03-19 05:47:01251 'OS_ANDROID_HOST',
[email protected]b00342e7f2013-03-26 16:21:54252 'OS_BSD',
253 'OS_CAT', # For testing.
254 'OS_CHROMEOS',
255 'OS_FREEBSD',
256 'OS_IOS',
257 'OS_LINUX',
258 'OS_MACOSX',
259 'OS_NACL',
260 'OS_OPENBSD',
261 'OS_POSIX',
[email protected]eda7afa12014-02-06 12:27:37262 'OS_QNX',
[email protected]b00342e7f2013-03-26 16:21:54263 'OS_SOLARIS',
[email protected]b00342e7f2013-03-26 16:21:54264 'OS_WIN',
265)
266
267
[email protected]55459852011-08-10 15:17:19268def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
269 """Attempts to prevent use of functions intended only for testing in
270 non-testing code. For now this is just a best-effort implementation
271 that ignores header files and may have some false positives. A
272 better implementation would probably need a proper C++ parser.
273 """
274 # We only scan .cc files and the like, as the declaration of
275 # for-testing functions in header files are hard to distinguish from
276 # calls to such functions without a proper C++ parser.
[email protected]06e6d0ff2012-12-11 01:36:44277 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
[email protected]55459852011-08-10 15:17:19278
279 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
280 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
[email protected]de4f7d22013-05-23 14:27:46281 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
[email protected]55459852011-08-10 15:17:19282 exclusion_pattern = input_api.re.compile(
283 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
284 base_function_pattern, base_function_pattern))
285
286 def FilterFile(affected_file):
[email protected]06e6d0ff2012-12-11 01:36:44287 black_list = (_EXCLUDED_PATHS +
288 _TEST_CODE_EXCLUDED_PATHS +
289 input_api.DEFAULT_BLACK_LIST)
[email protected]55459852011-08-10 15:17:19290 return input_api.FilterSourceFile(
291 affected_file,
292 white_list=(file_inclusion_pattern, ),
293 black_list=black_list)
294
295 problems = []
296 for f in input_api.AffectedSourceFiles(FilterFile):
297 local_path = f.LocalPath()
[email protected]825d27182014-01-02 21:24:24298 for line_number, line in f.ChangedContents():
[email protected]2fdd1f362013-01-16 03:56:03299 if (inclusion_pattern.search(line) and
[email protected]de4f7d22013-05-23 14:27:46300 not comment_pattern.search(line) and
[email protected]2fdd1f362013-01-16 03:56:03301 not exclusion_pattern.search(line)):
[email protected]55459852011-08-10 15:17:19302 problems.append(
[email protected]2fdd1f362013-01-16 03:56:03303 '%s:%d\n %s' % (local_path, line_number, line.strip()))
[email protected]55459852011-08-10 15:17:19304
305 if problems:
[email protected]f7051d52013-04-02 18:31:42306 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
[email protected]2fdd1f362013-01-16 03:56:03307 else:
308 return []
[email protected]55459852011-08-10 15:17:19309
310
[email protected]10689ca2011-09-02 02:31:54311def _CheckNoIOStreamInHeaders(input_api, output_api):
312 """Checks to make sure no .h files include <iostream>."""
313 files = []
314 pattern = input_api.re.compile(r'^#include\s*<iostream>',
315 input_api.re.MULTILINE)
316 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
317 if not f.LocalPath().endswith('.h'):
318 continue
319 contents = input_api.ReadFile(f)
320 if pattern.search(contents):
321 files.append(f)
322
323 if len(files):
324 return [ output_api.PresubmitError(
[email protected]6c063c62012-07-11 19:11:06325 'Do not #include <iostream> in header files, since it inserts static '
326 'initialization into every file including the header. Instead, '
[email protected]10689ca2011-09-02 02:31:54327 '#include <ostream>. See http://crbug.com/94794',
328 files) ]
329 return []
330
331
[email protected]72df4e782012-06-21 16:28:18332def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
333 """Checks to make sure no source files use UNIT_TEST"""
334 problems = []
335 for f in input_api.AffectedFiles():
336 if (not f.LocalPath().endswith(('.cc', '.mm'))):
337 continue
338
339 for line_num, line in f.ChangedContents():
[email protected]549f86a2013-11-19 13:00:04340 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
[email protected]72df4e782012-06-21 16:28:18341 problems.append(' %s:%d' % (f.LocalPath(), line_num))
342
343 if not problems:
344 return []
345 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
346 '\n'.join(problems))]
347
348
[email protected]8ea5d4b2011-09-13 21:49:22349def _CheckNoNewWStrings(input_api, output_api):
350 """Checks to make sure we don't introduce use of wstrings."""
[email protected]55463aa62011-10-12 00:48:27351 problems = []
[email protected]8ea5d4b2011-09-13 21:49:22352 for f in input_api.AffectedFiles():
[email protected]b5c24292011-11-28 14:38:20353 if (not f.LocalPath().endswith(('.cc', '.h')) or
[email protected]24be83c2013-08-29 23:01:23354 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
[email protected]b5c24292011-11-28 14:38:20355 continue
[email protected]8ea5d4b2011-09-13 21:49:22356
[email protected]a11dbe9b2012-08-07 01:32:58357 allowWString = False
[email protected]b5c24292011-11-28 14:38:20358 for line_num, line in f.ChangedContents():
[email protected]a11dbe9b2012-08-07 01:32:58359 if 'presubmit: allow wstring' in line:
360 allowWString = True
361 elif not allowWString and 'wstring' in line:
[email protected]55463aa62011-10-12 00:48:27362 problems.append(' %s:%d' % (f.LocalPath(), line_num))
[email protected]a11dbe9b2012-08-07 01:32:58363 allowWString = False
364 else:
365 allowWString = False
[email protected]8ea5d4b2011-09-13 21:49:22366
[email protected]55463aa62011-10-12 00:48:27367 if not problems:
368 return []
369 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
[email protected]a11dbe9b2012-08-07 01:32:58370 ' If you are calling a cross-platform API that accepts a wstring, '
371 'fix the API.\n' +
[email protected]55463aa62011-10-12 00:48:27372 '\n'.join(problems))]
[email protected]8ea5d4b2011-09-13 21:49:22373
374
[email protected]2a8ac9c2011-10-19 17:20:44375def _CheckNoDEPSGIT(input_api, output_api):
376 """Make sure .DEPS.git is never modified manually."""
377 if any(f.LocalPath().endswith('.DEPS.git') for f in
378 input_api.AffectedFiles()):
379 return [output_api.PresubmitError(
380 'Never commit changes to .DEPS.git. This file is maintained by an\n'
381 'automated system based on what\'s in DEPS and your changes will be\n'
382 'overwritten.\n'
383 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
384 'for more information')]
385 return []
386
387
[email protected]127f18ec2012-06-16 05:05:59388def _CheckNoBannedFunctions(input_api, output_api):
389 """Make sure that banned functions are not used."""
390 warnings = []
391 errors = []
392
393 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
394 for f in input_api.AffectedFiles(file_filter=file_filter):
395 for line_num, line in f.ChangedContents():
396 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
397 if func_name in line:
398 problems = warnings;
399 if error:
400 problems = errors;
401 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
402 for message_line in message:
403 problems.append(' %s' % message_line)
404
405 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
406 for f in input_api.AffectedFiles(file_filter=file_filter):
407 for line_num, line in f.ChangedContents():
[email protected]7345da02012-11-27 14:31:49408 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
409 def IsBlacklisted(affected_file, blacklist):
410 local_path = affected_file.LocalPath()
411 for item in blacklist:
412 if input_api.re.match(item, local_path):
413 return True
414 return False
415 if IsBlacklisted(f, excluded_paths):
416 continue
[email protected]d89eec82013-12-03 14:10:59417 matched = False
418 if func_name[0:1] == '/':
419 regex = func_name[1:]
420 if input_api.re.search(regex, line):
421 matched = True
422 elif func_name in line:
423 matched = True
424 if matched:
[email protected]127f18ec2012-06-16 05:05:59425 problems = warnings;
426 if error:
427 problems = errors;
428 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
429 for message_line in message:
430 problems.append(' %s' % message_line)
431
432 result = []
433 if (warnings):
434 result.append(output_api.PresubmitPromptWarning(
435 'Banned functions were used.\n' + '\n'.join(warnings)))
436 if (errors):
437 result.append(output_api.PresubmitError(
438 'Banned functions were used.\n' + '\n'.join(errors)))
439 return result
440
441
[email protected]6c063c62012-07-11 19:11:06442def _CheckNoPragmaOnce(input_api, output_api):
443 """Make sure that banned functions are not used."""
444 files = []
445 pattern = input_api.re.compile(r'^#pragma\s+once',
446 input_api.re.MULTILINE)
447 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
448 if not f.LocalPath().endswith('.h'):
449 continue
450 contents = input_api.ReadFile(f)
451 if pattern.search(contents):
452 files.append(f)
453
454 if files:
455 return [output_api.PresubmitError(
456 'Do not use #pragma once in header files.\n'
457 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
458 files)]
459 return []
460
[email protected]127f18ec2012-06-16 05:05:59461
[email protected]e7479052012-09-19 00:26:12462def _CheckNoTrinaryTrueFalse(input_api, output_api):
463 """Checks to make sure we don't introduce use of foo ? true : false."""
464 problems = []
465 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
466 for f in input_api.AffectedFiles():
467 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
468 continue
469
470 for line_num, line in f.ChangedContents():
471 if pattern.match(line):
472 problems.append(' %s:%d' % (f.LocalPath(), line_num))
473
474 if not problems:
475 return []
476 return [output_api.PresubmitPromptWarning(
477 'Please consider avoiding the "? true : false" pattern if possible.\n' +
478 '\n'.join(problems))]
479
480
[email protected]55f9f382012-07-31 11:02:18481def _CheckUnwantedDependencies(input_api, output_api):
482 """Runs checkdeps on #include statements added in this
483 change. Breaking - rules is an error, breaking ! rules is a
484 warning.
485 """
486 # We need to wait until we have an input_api object and use this
487 # roundabout construct to import checkdeps because this file is
488 # eval-ed and thus doesn't have __file__.
489 original_sys_path = sys.path
490 try:
491 sys.path = sys.path + [input_api.os_path.join(
492 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
493 import checkdeps
494 from cpp_checker import CppChecker
495 from rules import Rule
496 finally:
497 # Restore sys.path to what it was before.
498 sys.path = original_sys_path
499
500 added_includes = []
501 for f in input_api.AffectedFiles():
502 if not CppChecker.IsCppFile(f.LocalPath()):
503 continue
504
505 changed_lines = [line for line_num, line in f.ChangedContents()]
506 added_includes.append([f.LocalPath(), changed_lines])
507
[email protected]26385172013-05-09 23:11:35508 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
[email protected]55f9f382012-07-31 11:02:18509
510 error_descriptions = []
511 warning_descriptions = []
512 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
513 added_includes):
514 description_with_path = '%s\n %s' % (path, rule_description)
515 if rule_type == Rule.DISALLOW:
516 error_descriptions.append(description_with_path)
517 else:
518 warning_descriptions.append(description_with_path)
519
520 results = []
521 if error_descriptions:
522 results.append(output_api.PresubmitError(
523 'You added one or more #includes that violate checkdeps rules.',
524 error_descriptions))
525 if warning_descriptions:
[email protected]f7051d52013-04-02 18:31:42526 results.append(output_api.PresubmitPromptOrNotify(
[email protected]55f9f382012-07-31 11:02:18527 'You added one or more #includes of files that are temporarily\n'
528 'allowed but being removed. Can you avoid introducing the\n'
529 '#include? See relevant DEPS file(s) for details and contacts.',
530 warning_descriptions))
531 return results
532
533
[email protected]fbcafe5a2012-08-08 15:31:22534def _CheckFilePermissions(input_api, output_api):
535 """Check that all files have their permissions properly set."""
[email protected]791507202014-02-03 23:19:15536 if input_api.platform == 'win32':
537 return []
[email protected]fbcafe5a2012-08-08 15:31:22538 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
539 input_api.change.RepositoryRoot()]
540 for f in input_api.AffectedFiles():
541 args += ['--file', f.LocalPath()]
[email protected]f0d330f2014-01-30 01:44:34542 checkperms = input_api.subprocess.Popen(args,
543 stdout=input_api.subprocess.PIPE)
544 errors = checkperms.communicate()[0].strip()
[email protected]fbcafe5a2012-08-08 15:31:22545 if errors:
[email protected]f0d330f2014-01-30 01:44:34546 return [output_api.PresubmitError('checkperms.py failed.',
547 errors.splitlines())]
548 return []
[email protected]fbcafe5a2012-08-08 15:31:22549
550
[email protected]c8278b32012-10-30 20:35:49551def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
552 """Makes sure we don't include ui/aura/window_property.h
553 in header files.
554 """
555 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
556 errors = []
557 for f in input_api.AffectedFiles():
558 if not f.LocalPath().endswith('.h'):
559 continue
560 for line_num, line in f.ChangedContents():
561 if pattern.match(line):
562 errors.append(' %s:%d' % (f.LocalPath(), line_num))
563
564 results = []
565 if errors:
566 results.append(output_api.PresubmitError(
567 'Header files should not include ui/aura/window_property.h', errors))
568 return results
569
570
[email protected]cf9b78f2012-11-14 11:40:28571def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
572 """Checks that the lines in scope occur in the right order.
573
574 1. C system files in alphabetical order
575 2. C++ system files in alphabetical order
576 3. Project's .h files
577 """
578
579 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
580 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
581 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
582
583 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
584
585 state = C_SYSTEM_INCLUDES
586
587 previous_line = ''
[email protected]728b9bb2012-11-14 20:38:57588 previous_line_num = 0
[email protected]cf9b78f2012-11-14 11:40:28589 problem_linenums = []
590 for line_num, line in scope:
591 if c_system_include_pattern.match(line):
592 if state != C_SYSTEM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57593 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28594 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57595 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28596 elif cpp_system_include_pattern.match(line):
597 if state == C_SYSTEM_INCLUDES:
598 state = CPP_SYSTEM_INCLUDES
599 elif state == CUSTOM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57600 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28601 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57602 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28603 elif custom_include_pattern.match(line):
604 if state != CUSTOM_INCLUDES:
605 state = CUSTOM_INCLUDES
606 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57607 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28608 else:
609 problem_linenums.append(line_num)
610 previous_line = line
[email protected]728b9bb2012-11-14 20:38:57611 previous_line_num = line_num
[email protected]cf9b78f2012-11-14 11:40:28612
613 warnings = []
[email protected]728b9bb2012-11-14 20:38:57614 for (line_num, previous_line_num) in problem_linenums:
615 if line_num in changed_linenums or previous_line_num in changed_linenums:
[email protected]cf9b78f2012-11-14 11:40:28616 warnings.append(' %s:%d' % (file_path, line_num))
617 return warnings
618
619
[email protected]ac294a12012-12-06 16:38:43620def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
[email protected]cf9b78f2012-11-14 11:40:28621 """Checks the #include order for the given file f."""
622
[email protected]2299dcf2012-11-15 19:56:24623 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
[email protected]23093b62013-09-20 12:16:30624 # Exclude the following includes from the check:
625 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
626 # specific order.
627 # 2) <atlbase.h>, "build/build_config.h"
628 excluded_include_pattern = input_api.re.compile(
629 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
[email protected]2299dcf2012-11-15 19:56:24630 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
[email protected]3e83618c2013-10-09 22:32:33631 # Match the final or penultimate token if it is xxxtest so we can ignore it
632 # when considering the special first include.
633 test_file_tag_pattern = input_api.re.compile(
634 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
[email protected]0e5c1852012-12-18 20:17:11635 if_pattern = input_api.re.compile(
636 r'\s*#\s*(if|elif|else|endif|define|undef).*')
637 # Some files need specialized order of includes; exclude such files from this
638 # check.
639 uncheckable_includes_pattern = input_api.re.compile(
640 r'\s*#include '
641 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
[email protected]cf9b78f2012-11-14 11:40:28642
643 contents = f.NewContents()
644 warnings = []
645 line_num = 0
646
[email protected]ac294a12012-12-06 16:38:43647 # Handle the special first include. If the first include file is
648 # some/path/file.h, the corresponding including file can be some/path/file.cc,
649 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
650 # etc. It's also possible that no special first include exists.
[email protected]3e83618c2013-10-09 22:32:33651 # If the included file is some/path/file_platform.h the including file could
652 # also be some/path/file_xxxtest_platform.h.
653 including_file_base_name = test_file_tag_pattern.sub(
654 '', input_api.os_path.basename(f.LocalPath()))
655
[email protected]ac294a12012-12-06 16:38:43656 for line in contents:
657 line_num += 1
658 if system_include_pattern.match(line):
659 # No special first include -> process the line again along with normal
660 # includes.
661 line_num -= 1
662 break
663 match = custom_include_pattern.match(line)
664 if match:
665 match_dict = match.groupdict()
[email protected]3e83618c2013-10-09 22:32:33666 header_basename = test_file_tag_pattern.sub(
667 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
668
669 if header_basename not in including_file_base_name:
[email protected]2299dcf2012-11-15 19:56:24670 # No special first include -> process the line again along with normal
671 # includes.
672 line_num -= 1
[email protected]ac294a12012-12-06 16:38:43673 break
[email protected]cf9b78f2012-11-14 11:40:28674
675 # Split into scopes: Each region between #if and #endif is its own scope.
676 scopes = []
677 current_scope = []
678 for line in contents[line_num:]:
679 line_num += 1
[email protected]0e5c1852012-12-18 20:17:11680 if uncheckable_includes_pattern.match(line):
[email protected]4436c9e2014-01-07 23:19:54681 continue
[email protected]2309b0fa02012-11-16 12:18:27682 if if_pattern.match(line):
[email protected]cf9b78f2012-11-14 11:40:28683 scopes.append(current_scope)
684 current_scope = []
[email protected]962f117e2012-11-22 18:11:56685 elif ((system_include_pattern.match(line) or
686 custom_include_pattern.match(line)) and
687 not excluded_include_pattern.match(line)):
[email protected]cf9b78f2012-11-14 11:40:28688 current_scope.append((line_num, line))
689 scopes.append(current_scope)
690
691 for scope in scopes:
692 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
693 changed_linenums))
694 return warnings
695
696
697def _CheckIncludeOrder(input_api, output_api):
698 """Checks that the #include order is correct.
699
700 1. The corresponding header for source files.
701 2. C system files in alphabetical order
702 3. C++ system files in alphabetical order
703 4. Project's .h files in alphabetical order
704
[email protected]ac294a12012-12-06 16:38:43705 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
706 these rules separately.
[email protected]cf9b78f2012-11-14 11:40:28707 """
708
709 warnings = []
710 for f in input_api.AffectedFiles():
[email protected]ac294a12012-12-06 16:38:43711 if f.LocalPath().endswith(('.cc', '.h')):
712 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
713 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
[email protected]cf9b78f2012-11-14 11:40:28714
715 results = []
716 if warnings:
[email protected]f7051d52013-04-02 18:31:42717 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
[email protected]120cf540d2012-12-10 17:55:53718 warnings))
[email protected]cf9b78f2012-11-14 11:40:28719 return results
720
721
[email protected]70ca77752012-11-20 03:45:03722def _CheckForVersionControlConflictsInFile(input_api, f):
723 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
724 errors = []
725 for line_num, line in f.ChangedContents():
726 if pattern.match(line):
727 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
728 return errors
729
730
731def _CheckForVersionControlConflicts(input_api, output_api):
732 """Usually this is not intentional and will cause a compile failure."""
733 errors = []
734 for f in input_api.AffectedFiles():
735 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
736
737 results = []
738 if errors:
739 results.append(output_api.PresubmitError(
740 'Version control conflict markers found, please resolve.', errors))
741 return results
742
743
[email protected]06e6d0ff2012-12-11 01:36:44744def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
745 def FilterFile(affected_file):
746 """Filter function for use with input_api.AffectedSourceFiles,
747 below. This filters out everything except non-test files from
748 top-level directories that generally speaking should not hard-code
749 service URLs (e.g. src/android_webview/, src/content/ and others).
750 """
751 return input_api.FilterSourceFile(
752 affected_file,
[email protected]78bb39d62012-12-11 15:11:56753 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
[email protected]06e6d0ff2012-12-11 01:36:44754 black_list=(_EXCLUDED_PATHS +
755 _TEST_CODE_EXCLUDED_PATHS +
756 input_api.DEFAULT_BLACK_LIST))
757
[email protected]de4f7d22013-05-23 14:27:46758 base_pattern = '"[^"]*google\.com[^"]*"'
759 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
760 pattern = input_api.re.compile(base_pattern)
[email protected]06e6d0ff2012-12-11 01:36:44761 problems = [] # items are (filename, line_number, line)
762 for f in input_api.AffectedSourceFiles(FilterFile):
763 for line_num, line in f.ChangedContents():
[email protected]de4f7d22013-05-23 14:27:46764 if not comment_pattern.search(line) and pattern.search(line):
[email protected]06e6d0ff2012-12-11 01:36:44765 problems.append((f.LocalPath(), line_num, line))
766
767 if problems:
[email protected]f7051d52013-04-02 18:31:42768 return [output_api.PresubmitPromptOrNotify(
[email protected]06e6d0ff2012-12-11 01:36:44769 'Most layers below src/chrome/ should not hardcode service URLs.\n'
[email protected]b0149772014-03-27 16:47:58770 'Are you sure this is correct?',
[email protected]06e6d0ff2012-12-11 01:36:44771 [' %s:%d: %s' % (
772 problem[0], problem[1], problem[2]) for problem in problems])]
[email protected]2fdd1f362013-01-16 03:56:03773 else:
774 return []
[email protected]06e6d0ff2012-12-11 01:36:44775
776
[email protected]d2530012013-01-25 16:39:27777def _CheckNoAbbreviationInPngFileName(input_api, output_api):
778 """Makes sure there are no abbreviations in the name of PNG files.
779 """
[email protected]4053a48e2013-01-25 21:43:04780 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
[email protected]d2530012013-01-25 16:39:27781 errors = []
782 for f in input_api.AffectedFiles(include_deletes=False):
783 if pattern.match(f.LocalPath()):
784 errors.append(' %s' % f.LocalPath())
785
786 results = []
787 if errors:
788 results.append(output_api.PresubmitError(
789 'The name of PNG files should not have abbreviations. \n'
790 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
791 'Contact [email protected] if you have questions.', errors))
792 return results
793
794
[email protected]14a6131c2014-01-08 01:15:41795def _FilesToCheckForIncomingDeps(re, changed_lines):
[email protected]f32e2d1e2013-07-26 21:39:08796 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
[email protected]14a6131c2014-01-08 01:15:41797 a set of DEPS entries that we should look up.
798
799 For a directory (rather than a specific filename) we fake a path to
800 a specific filename by adding /DEPS. This is chosen as a file that
801 will seldom or never be subject to per-file include_rules.
802 """
[email protected]2b438d62013-11-14 17:54:14803 # We ignore deps entries on auto-generated directories.
804 AUTO_GENERATED_DIRS = ['grit', 'jni']
[email protected]f32e2d1e2013-07-26 21:39:08805
806 # This pattern grabs the path without basename in the first
807 # parentheses, and the basename (if present) in the second. It
808 # relies on the simple heuristic that if there is a basename it will
809 # be a header file ending in ".h".
810 pattern = re.compile(
811 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
[email protected]2b438d62013-11-14 17:54:14812 results = set()
[email protected]f32e2d1e2013-07-26 21:39:08813 for changed_line in changed_lines:
814 m = pattern.match(changed_line)
815 if m:
816 path = m.group(1)
[email protected]2b438d62013-11-14 17:54:14817 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
[email protected]14a6131c2014-01-08 01:15:41818 if m.group(2):
819 results.add('%s%s' % (path, m.group(2)))
820 else:
821 results.add('%s/DEPS' % path)
[email protected]f32e2d1e2013-07-26 21:39:08822 return results
823
824
[email protected]e871964c2013-05-13 14:14:55825def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
826 """When a dependency prefixed with + is added to a DEPS file, we
827 want to make sure that the change is reviewed by an OWNER of the
828 target file or directory, to avoid layering violations from being
829 introduced. This check verifies that this happens.
830 """
831 changed_lines = set()
832 for f in input_api.AffectedFiles():
833 filename = input_api.os_path.basename(f.LocalPath())
834 if filename == 'DEPS':
835 changed_lines |= set(line.strip()
836 for line_num, line
837 in f.ChangedContents())
838 if not changed_lines:
839 return []
840
[email protected]14a6131c2014-01-08 01:15:41841 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
842 changed_lines)
[email protected]e871964c2013-05-13 14:14:55843 if not virtual_depended_on_files:
844 return []
845
846 if input_api.is_committing:
847 if input_api.tbr:
848 return [output_api.PresubmitNotifyResult(
849 '--tbr was specified, skipping OWNERS check for DEPS additions')]
850 if not input_api.change.issue:
851 return [output_api.PresubmitError(
852 "DEPS approval by OWNERS check failed: this change has "
853 "no Rietveld issue number, so we can't check it for approvals.")]
854 output = output_api.PresubmitError
855 else:
856 output = output_api.PresubmitNotifyResult
857
858 owners_db = input_api.owners_db
859 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
860 input_api,
861 owners_db.email_regexp,
862 approval_needed=input_api.is_committing)
863
864 owner_email = owner_email or input_api.change.author_email
865
[email protected]de4f7d22013-05-23 14:27:46866 reviewers_plus_owner = set(reviewers)
[email protected]e71c6082013-05-22 02:28:51867 if owner_email:
[email protected]de4f7d22013-05-23 14:27:46868 reviewers_plus_owner.add(owner_email)
[email protected]e871964c2013-05-13 14:14:55869 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
870 reviewers_plus_owner)
[email protected]14a6131c2014-01-08 01:15:41871
872 # We strip the /DEPS part that was added by
873 # _FilesToCheckForIncomingDeps to fake a path to a file in a
874 # directory.
875 def StripDeps(path):
876 start_deps = path.rfind('/DEPS')
877 if start_deps != -1:
878 return path[:start_deps]
879 else:
880 return path
881 unapproved_dependencies = ["'+%s'," % StripDeps(path)
[email protected]e871964c2013-05-13 14:14:55882 for path in missing_files]
883
884 if unapproved_dependencies:
885 output_list = [
[email protected]14a6131c2014-01-08 01:15:41886 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
[email protected]e871964c2013-05-13 14:14:55887 '\n '.join(sorted(unapproved_dependencies)))]
888 if not input_api.is_committing:
889 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
890 output_list.append(output(
891 'Suggested missing target path OWNERS:\n %s' %
892 '\n '.join(suggested_owners or [])))
893 return output_list
894
895 return []
896
897
[email protected]85218562013-11-22 07:41:40898def _CheckSpamLogging(input_api, output_api):
899 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
900 black_list = (_EXCLUDED_PATHS +
901 _TEST_CODE_EXCLUDED_PATHS +
902 input_api.DEFAULT_BLACK_LIST +
[email protected]6f742dd02013-11-26 23:19:50903 (r"^base[\\\/]logging\.h$",
[email protected]80f360a2014-01-23 01:36:19904 r"^base[\\\/]logging\.cc$",
[email protected]b3643872014-02-11 23:29:39905 r"^cloud_print[\\\/]",
[email protected]c80b35022014-03-03 17:01:41906 r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
[email protected]8dc338c2013-12-09 16:28:48907 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
[email protected]6e268db2013-12-04 01:41:46908 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
[email protected]4de75262013-12-18 23:16:12909 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
910 r"startup_browser_creator\.cc$",
[email protected]fe0e6e12013-12-04 05:52:58911 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
[email protected]95c6b3012013-12-02 14:30:31912 r"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
[email protected]6e268db2013-12-04 01:41:46913 r"logging_native_handler\.cc$",
[email protected]9056e732014-01-08 06:25:25914 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
915 r"gl_helper_benchmark\.cc$",
[email protected]9c36d922014-03-24 16:47:52916 r"^native_client_sdk[\\\/]",
[email protected]cdbdced2013-11-27 21:35:50917 r"^remoting[\\\/]base[\\\/]logging\.h$",
[email protected]67c96ab2013-12-17 02:05:36918 r"^remoting[\\\/]host[\\\/].*",
[email protected]8232f8fd2013-12-14 00:52:31919 r"^sandbox[\\\/]linux[\\\/].*",
[email protected]0b7a21e2014-02-11 18:38:13920 r"^tools[\\\/]",
[email protected]8232f8fd2013-12-14 00:52:31921 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
[email protected]85218562013-11-22 07:41:40922 source_file_filter = lambda x: input_api.FilterSourceFile(
923 x, white_list=(file_inclusion_pattern,), black_list=black_list)
924
925 log_info = []
926 printf = []
927
928 for f in input_api.AffectedSourceFiles(source_file_filter):
929 contents = input_api.ReadFile(f, 'rb')
930 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
931 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37932 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
[email protected]85210652013-11-28 05:50:13933 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37934
935 if re.search(r"\bprintf\(", contents):
936 printf.append(f.LocalPath())
937 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
[email protected]85218562013-11-22 07:41:40938 printf.append(f.LocalPath())
939
940 if log_info:
941 return [output_api.PresubmitError(
942 'These files spam the console log with LOG(INFO):',
943 items=log_info)]
944 if printf:
945 return [output_api.PresubmitError(
946 'These files spam the console log with printf/fprintf:',
947 items=printf)]
948 return []
949
950
[email protected]49aa76a2013-12-04 06:59:16951def _CheckForAnonymousVariables(input_api, output_api):
952 """These types are all expected to hold locks while in scope and
953 so should never be anonymous (which causes them to be immediately
954 destroyed)."""
955 they_who_must_be_named = [
956 'base::AutoLock',
957 'base::AutoReset',
958 'base::AutoUnlock',
959 'SkAutoAlphaRestore',
960 'SkAutoBitmapShaderInstall',
961 'SkAutoBlitterChoose',
962 'SkAutoBounderCommit',
963 'SkAutoCallProc',
964 'SkAutoCanvasRestore',
965 'SkAutoCommentBlock',
966 'SkAutoDescriptor',
967 'SkAutoDisableDirectionCheck',
968 'SkAutoDisableOvalCheck',
969 'SkAutoFree',
970 'SkAutoGlyphCache',
971 'SkAutoHDC',
972 'SkAutoLockColors',
973 'SkAutoLockPixels',
974 'SkAutoMalloc',
975 'SkAutoMaskFreeImage',
976 'SkAutoMutexAcquire',
977 'SkAutoPathBoundsUpdate',
978 'SkAutoPDFRelease',
979 'SkAutoRasterClipValidate',
980 'SkAutoRef',
981 'SkAutoTime',
982 'SkAutoTrace',
983 'SkAutoUnref',
984 ]
985 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
986 # bad: base::AutoLock(lock.get());
987 # not bad: base::AutoLock lock(lock.get());
988 bad_pattern = input_api.re.compile(anonymous)
989 # good: new base::AutoLock(lock.get())
990 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
991 errors = []
992
993 for f in input_api.AffectedFiles():
994 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
995 continue
996 for linenum, line in f.ChangedContents():
997 if bad_pattern.search(line) and not good_pattern.search(line):
998 errors.append('%s:%d' % (f.LocalPath(), linenum))
999
1000 if errors:
1001 return [output_api.PresubmitError(
1002 'These lines create anonymous variables that need to be named:',
1003 items=errors)]
1004 return []
1005
1006
[email protected]5fe0f8742013-11-29 01:04:591007def _CheckCygwinShell(input_api, output_api):
1008 source_file_filter = lambda x: input_api.FilterSourceFile(
1009 x, white_list=(r'.+\.(gyp|gypi)$',))
1010 cygwin_shell = []
1011
1012 for f in input_api.AffectedSourceFiles(source_file_filter):
1013 for linenum, line in f.ChangedContents():
1014 if 'msvs_cygwin_shell' in line:
1015 cygwin_shell.append(f.LocalPath())
1016 break
1017
1018 if cygwin_shell:
1019 return [output_api.PresubmitError(
1020 'These files should not use msvs_cygwin_shell (the default is 0):',
1021 items=cygwin_shell)]
1022 return []
1023
[email protected]85218562013-11-22 07:41:401024
[email protected]999261d2014-03-03 20:08:081025def _CheckUserActionUpdate(input_api, output_api):
1026 """Checks if any new user action has been added."""
[email protected]2f92dec2014-03-07 19:21:521027 if any('actions.xml' == input_api.os_path.basename(f) for f in
[email protected]999261d2014-03-03 20:08:081028 input_api.LocalPaths()):
[email protected]2f92dec2014-03-07 19:21:521029 # If actions.xml is already included in the changelist, the PRESUBMIT
1030 # for actions.xml will do a more complete presubmit check.
[email protected]999261d2014-03-03 20:08:081031 return []
1032
[email protected]999261d2014-03-03 20:08:081033 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm'))
1034 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)'
[email protected]2f92dec2014-03-07 19:21:521035 current_actions = None
[email protected]999261d2014-03-03 20:08:081036 for f in input_api.AffectedFiles(file_filter=file_filter):
1037 for line_num, line in f.ChangedContents():
1038 match = input_api.re.search(action_re, line)
1039 if match:
[email protected]2f92dec2014-03-07 19:21:521040 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1041 # loaded only once.
1042 if not current_actions:
1043 with open('tools/metrics/actions/actions.xml') as actions_f:
1044 current_actions = actions_f.read()
1045 # Search for the matched user action name in |current_actions|.
[email protected]999261d2014-03-03 20:08:081046 for action_name in match.groups():
[email protected]2f92dec2014-03-07 19:21:521047 action = 'name="{0}"'.format(action_name)
1048 if action not in current_actions:
[email protected]999261d2014-03-03 20:08:081049 return [output_api.PresubmitPromptWarning(
1050 'File %s line %d: %s is missing in '
[email protected]2f92dec2014-03-07 19:21:521051 'tools/metrics/actions/actions.xml. Please run '
1052 'tools/metrics/actions/extract_actions.py to update.'
[email protected]999261d2014-03-03 20:08:081053 % (f.LocalPath(), line_num, action_name))]
1054 return []
1055
1056
[email protected]760deea2013-12-10 19:33:491057def _CheckJavaStyle(input_api, output_api):
1058 """Runs checkstyle on changed java files and returns errors if any exist."""
1059 original_sys_path = sys.path
1060 try:
1061 sys.path = sys.path + [input_api.os_path.join(
1062 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1063 import checkstyle
1064 finally:
1065 # Restore sys.path to what it was before.
1066 sys.path = original_sys_path
1067
1068 return checkstyle.RunCheckstyle(
1069 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1070
1071
[email protected]22c9bd72011-03-27 16:47:391072def _CommonChecks(input_api, output_api):
1073 """Checks common to both upload and commit."""
1074 results = []
1075 results.extend(input_api.canned_checks.PanProjectChecks(
[email protected]3de922f2013-12-20 13:27:381076 input_api, output_api,
1077 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
[email protected]66daa702011-05-28 14:41:461078 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]55459852011-08-10 15:17:191079 results.extend(
[email protected]760deea2013-12-10 19:33:491080 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
[email protected]10689ca2011-09-02 02:31:541081 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
[email protected]72df4e782012-06-21 16:28:181082 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
[email protected]8ea5d4b2011-09-13 21:49:221083 results.extend(_CheckNoNewWStrings(input_api, output_api))
[email protected]2a8ac9c2011-10-19 17:20:441084 results.extend(_CheckNoDEPSGIT(input_api, output_api))
[email protected]127f18ec2012-06-16 05:05:591085 results.extend(_CheckNoBannedFunctions(input_api, output_api))
[email protected]6c063c62012-07-11 19:11:061086 results.extend(_CheckNoPragmaOnce(input_api, output_api))
[email protected]e7479052012-09-19 00:26:121087 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
[email protected]55f9f382012-07-31 11:02:181088 results.extend(_CheckUnwantedDependencies(input_api, output_api))
[email protected]fbcafe5a2012-08-08 15:31:221089 results.extend(_CheckFilePermissions(input_api, output_api))
[email protected]c8278b32012-10-30 20:35:491090 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
[email protected]2309b0fa02012-11-16 12:18:271091 results.extend(_CheckIncludeOrder(input_api, output_api))
[email protected]70ca77752012-11-20 03:45:031092 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
[email protected]b8079ae4a2012-12-05 19:56:491093 results.extend(_CheckPatchFiles(input_api, output_api))
[email protected]06e6d0ff2012-12-11 01:36:441094 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
[email protected]d2530012013-01-25 16:39:271095 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
[email protected]b00342e7f2013-03-26 16:21:541096 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
[email protected]e871964c2013-05-13 14:14:551097 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
[email protected]9f919cc2013-07-31 03:04:041098 results.extend(
1099 input_api.canned_checks.CheckChangeHasNoTabs(
1100 input_api,
1101 output_api,
1102 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
[email protected]85218562013-11-22 07:41:401103 results.extend(_CheckSpamLogging(input_api, output_api))
[email protected]49aa76a2013-12-04 06:59:161104 results.extend(_CheckForAnonymousVariables(input_api, output_api))
[email protected]5fe0f8742013-11-29 01:04:591105 results.extend(_CheckCygwinShell(input_api, output_api))
[email protected]999261d2014-03-03 20:08:081106 results.extend(_CheckUserActionUpdate(input_api, output_api))
[email protected]2299dcf2012-11-15 19:56:241107
1108 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1109 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1110 input_api, output_api,
1111 input_api.PresubmitLocalPath(),
[email protected]6be63382013-01-21 15:42:381112 whitelist=[r'^PRESUBMIT_test\.py$']))
[email protected]22c9bd72011-03-27 16:47:391113 return results
[email protected]1f7b4172010-01-28 01:17:341114
[email protected]b337cb5b2011-01-23 21:24:051115
1116def _CheckSubversionConfig(input_api, output_api):
1117 """Verifies the subversion config file is correctly setup.
1118
1119 Checks that autoprops are enabled, returns an error otherwise.
1120 """
1121 join = input_api.os_path.join
1122 if input_api.platform == 'win32':
1123 appdata = input_api.environ.get('APPDATA', '')
1124 if not appdata:
1125 return [output_api.PresubmitError('%APPDATA% is not configured.')]
1126 path = join(appdata, 'Subversion', 'config')
1127 else:
1128 home = input_api.environ.get('HOME', '')
1129 if not home:
1130 return [output_api.PresubmitError('$HOME is not configured.')]
1131 path = join(home, '.subversion', 'config')
1132
1133 error_msg = (
1134 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1135 'configure your subversion configuration file. This enables automatic\n'
[email protected]c6a3c10b2011-01-24 16:14:201136 'properties to simplify the project maintenance.\n'
1137 'Pro-tip: just download and install\n'
1138 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
[email protected]b337cb5b2011-01-23 21:24:051139
1140 try:
1141 lines = open(path, 'r').read().splitlines()
1142 # Make sure auto-props is enabled and check for 2 Chromium standard
1143 # auto-prop.
1144 if (not '*.cc = svn:eol-style=LF' in lines or
1145 not '*.pdf = svn:mime-type=application/pdf' in lines or
1146 not 'enable-auto-props = yes' in lines):
1147 return [
[email protected]79ed7e62011-02-21 21:08:531148 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:051149 'It looks like you have not configured your subversion config '
[email protected]b5359c02011-02-01 20:29:561150 'file or it is not up-to-date.\n' + error_msg)
[email protected]b337cb5b2011-01-23 21:24:051151 ]
1152 except (OSError, IOError):
1153 return [
[email protected]79ed7e62011-02-21 21:08:531154 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:051155 'Can\'t find your subversion config file.\n' + error_msg)
1156 ]
1157 return []
1158
1159
[email protected]66daa702011-05-28 14:41:461160def _CheckAuthorizedAuthor(input_api, output_api):
1161 """For non-googler/chromites committers, verify the author's email address is
1162 in AUTHORS.
1163 """
[email protected]9bb9cb82011-06-13 20:43:011164 # TODO(maruel): Add it to input_api?
1165 import fnmatch
1166
[email protected]66daa702011-05-28 14:41:461167 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:011168 if not author:
1169 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:461170 return []
[email protected]c99663292011-05-31 19:46:081171 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:461172 input_api.PresubmitLocalPath(), 'AUTHORS')
1173 valid_authors = (
1174 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1175 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:181176 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]d8b50be2011-06-15 14:19:441177 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]5861efb2013-01-07 18:33:231178 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
[email protected]66daa702011-05-28 14:41:461179 return [output_api.PresubmitPromptWarning(
1180 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1181 '\n'
1182 'http://www.chromium.org/developers/contributing-code and read the '
1183 '"Legal" section\n'
1184 'If you are a chromite, verify the contributor signed the CLA.') %
1185 author)]
1186 return []
1187
1188
[email protected]b8079ae4a2012-12-05 19:56:491189def _CheckPatchFiles(input_api, output_api):
1190 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1191 if f.LocalPath().endswith(('.orig', '.rej'))]
1192 if problems:
1193 return [output_api.PresubmitError(
1194 "Don't commit .rej and .orig files.", problems)]
[email protected]2fdd1f362013-01-16 03:56:031195 else:
1196 return []
[email protected]b8079ae4a2012-12-05 19:56:491197
1198
[email protected]b00342e7f2013-03-26 16:21:541199def _DidYouMeanOSMacro(bad_macro):
1200 try:
1201 return {'A': 'OS_ANDROID',
1202 'B': 'OS_BSD',
1203 'C': 'OS_CHROMEOS',
1204 'F': 'OS_FREEBSD',
1205 'L': 'OS_LINUX',
1206 'M': 'OS_MACOSX',
1207 'N': 'OS_NACL',
1208 'O': 'OS_OPENBSD',
1209 'P': 'OS_POSIX',
1210 'S': 'OS_SOLARIS',
1211 'W': 'OS_WIN'}[bad_macro[3].upper()]
1212 except KeyError:
1213 return ''
1214
1215
1216def _CheckForInvalidOSMacrosInFile(input_api, f):
1217 """Check for sensible looking, totally invalid OS macros."""
1218 preprocessor_statement = input_api.re.compile(r'^\s*#')
1219 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1220 results = []
1221 for lnum, line in f.ChangedContents():
1222 if preprocessor_statement.search(line):
1223 for match in os_macro.finditer(line):
1224 if not match.group(1) in _VALID_OS_MACROS:
1225 good = _DidYouMeanOSMacro(match.group(1))
1226 did_you_mean = ' (did you mean %s?)' % good if good else ''
1227 results.append(' %s:%d %s%s' % (f.LocalPath(),
1228 lnum,
1229 match.group(1),
1230 did_you_mean))
1231 return results
1232
1233
1234def _CheckForInvalidOSMacros(input_api, output_api):
1235 """Check all affected files for invalid OS macros."""
1236 bad_macros = []
1237 for f in input_api.AffectedFiles():
1238 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1239 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1240
1241 if not bad_macros:
1242 return []
1243
1244 return [output_api.PresubmitError(
1245 'Possibly invalid OS macro[s] found. Please fix your code\n'
1246 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1247
1248
[email protected]1f7b4172010-01-28 01:17:341249def CheckChangeOnUpload(input_api, output_api):
1250 results = []
1251 results.extend(_CommonChecks(input_api, output_api))
[email protected]ae69ae72014-02-20 13:09:361252 results.extend(_CheckJavaStyle(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541253 return results
[email protected]ca8d19842009-02-19 16:33:121254
1255
[email protected]38c6a512013-12-18 23:48:011256def GetDefaultTryConfigs(bots=None):
1257 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1258
1259 To add tests to this list, they MUST be in the the corresponding master's
1260 gatekeeper config. For example, anything on master.chromium would be closed by
1261 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1262
1263 If 'bots' is specified, will only return configurations for bots in that list.
1264 """
1265
1266 standard_tests = [
1267 'base_unittests',
1268 'browser_tests',
1269 'cacheinvalidation_unittests',
1270 'check_deps',
1271 'check_deps2git',
1272 'content_browsertests',
1273 'content_unittests',
1274 'crypto_unittests',
[email protected]38c6a512013-12-18 23:48:011275 'gpu_unittests',
1276 'interactive_ui_tests',
1277 'ipc_tests',
1278 'jingle_unittests',
1279 'media_unittests',
1280 'net_unittests',
1281 'ppapi_unittests',
1282 'printing_unittests',
1283 'sql_unittests',
1284 'sync_unit_tests',
1285 'unit_tests',
1286 # Broken in release.
1287 #'url_unittests',
1288 #'webkit_unit_tests',
1289 ]
1290
[email protected]38c6a512013-12-18 23:48:011291 builders_and_tests = {
1292 # TODO(maruel): Figure out a way to run 'sizes' where people can
1293 # effectively update the perf expectation correctly. This requires a
1294 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1295 # incremental build. Reference:
1296 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1297 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1298 # of this step as a try job failure.
1299 'android_aosp': ['compile'],
1300 'android_clang_dbg': ['slave_steps'],
1301 'android_dbg': ['slave_steps'],
1302 'cros_x86': ['defaulttests'],
1303 'ios_dbg_simulator': [
1304 'compile',
1305 'base_unittests',
1306 'content_unittests',
1307 'crypto_unittests',
1308 'url_unittests',
1309 'net_unittests',
1310 'sql_unittests',
1311 'ui_unittests',
1312 ],
1313 'ios_rel_device': ['compile'],
[email protected]971b08ce2014-03-19 22:03:561314 'linux_asan': ['compile'],
1315 'mac_asan': ['compile'],
[email protected]38c6a512013-12-18 23:48:011316 #TODO(stip): Change the name of this builder to reflect that it's release.
[email protected]71afb4ec2014-02-07 02:45:131317 'linux_gtk': standard_tests,
[email protected]971b08ce2014-03-19 22:03:561318 'linux_chromeos_asan': ['compile'],
[email protected]d910b6082014-02-27 18:15:431319 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
1320 'linux_chromium_chromeos_rel': ['defaulttests'],
1321 'linux_chromium_compile_dbg': ['defaulttests'],
[email protected]23c81d552014-01-07 13:45:461322 'linux_chromium_rel': ['defaulttests'],
[email protected]d910b6082014-02-27 18:15:431323 'linux_chromium_clang_dbg': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021324 'linux_nacl_sdk_build': ['compile'],
[email protected]d910b6082014-02-27 18:15:431325 'linux_rel': [
[email protected]9021a5f72014-01-24 19:02:381326 'telemetry_perf_unittests',
1327 'telemetry_unittests',
[email protected]38c6a512013-12-18 23:48:011328 ],
[email protected]d910b6082014-02-27 18:15:431329 'mac_chromium_compile_dbg': ['defaulttests'],
[email protected]23c81d552014-01-07 13:45:461330 'mac_chromium_rel': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021331 'mac_nacl_sdk_build': ['compile'],
[email protected]d910b6082014-02-27 18:15:431332 'mac_rel': [
[email protected]9021a5f72014-01-24 19:02:381333 'telemetry_perf_unittests',
[email protected]38c6a512013-12-18 23:48:011334 'telemetry_unittests',
1335 ],
1336 'win': ['compile'],
[email protected]0094fa12014-03-13 03:18:281337 'win_chromium_compile_dbg': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021338 'win_nacl_sdk_build': ['compile'],
[email protected]38c6a512013-12-18 23:48:011339 'win_rel': standard_tests + [
1340 'app_list_unittests',
1341 'ash_unittests',
1342 'aura_unittests',
1343 'cc_unittests',
1344 'chrome_elf_unittests',
[email protected]5d0413fc2014-01-03 18:24:301345 'chromedriver_unittests',
[email protected]38c6a512013-12-18 23:48:011346 'components_unittests',
1347 'compositor_unittests',
1348 'events_unittests',
[email protected]0df555e2014-02-27 14:53:111349 'gfx_unittests',
[email protected]38c6a512013-12-18 23:48:011350 'google_apis_unittests',
1351 'installer_util_unittests',
1352 'mini_installer_test',
1353 'nacl_integration',
1354 'remoting_unittests',
1355 'sync_integration_tests',
[email protected]9021a5f72014-01-24 19:02:381356 'telemetry_perf_unittests',
[email protected]38c6a512013-12-18 23:48:011357 'telemetry_unittests',
1358 'views_unittests',
1359 ],
1360 'win_x64_rel': [
1361 'base_unittests',
1362 ],
1363 }
1364
1365 swarm_enabled_builders = (
[email protected]9714f3b2014-03-20 19:50:111366 # http://crbug.com/354263
1367 # 'linux_rel',
1368 # 'mac_rel',
1369 # 'win_rel',
[email protected]38c6a512013-12-18 23:48:011370 )
1371
1372 swarm_enabled_tests = (
1373 'base_unittests',
1374 'browser_tests',
1375 'interactive_ui_tests',
1376 'net_unittests',
1377 'unit_tests',
1378 )
1379
1380 for bot in builders_and_tests:
1381 if bot in swarm_enabled_builders:
1382 builders_and_tests[bot] = [x + '_swarm' if x in swarm_enabled_tests else x
1383 for x in builders_and_tests[bot]]
1384
1385 if bots:
[email protected]7468ac522014-03-12 23:35:571386 return {
1387 'tryserver.chromium': dict((bot, set(builders_and_tests[bot]))
1388 for bot in bots)
1389 }
[email protected]38c6a512013-12-18 23:48:011390 else:
[email protected]7468ac522014-03-12 23:35:571391 return {
1392 'tryserver.chromium': dict(
1393 (bot, set(tests))
1394 for bot, tests in builders_and_tests.iteritems())
1395 }
[email protected]38c6a512013-12-18 23:48:011396
1397
[email protected]ca8d19842009-02-19 16:33:121398def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:541399 results = []
[email protected]1f7b4172010-01-28 01:17:341400 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:511401 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1402 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1403 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:541404 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:271405 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:341406 input_api,
1407 output_api,
[email protected]2fdd1f362013-01-16 03:56:031408 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:271409
[email protected]3e4eb112011-01-18 03:29:541410 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1411 input_api, output_api))
[email protected]c4b47562011-12-05 23:39:411412 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1413 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:051414 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541415 return results
[email protected]ca8d19842009-02-19 16:33:121416
1417
[email protected]7468ac522014-03-12 23:35:571418def GetPreferredTryMasters(project, change):
[email protected]4ce995ea2012-06-27 02:13:101419 files = change.LocalPaths()
1420
[email protected]751b05f2013-01-10 23:12:171421 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571422 return {}
[email protected]3019c902012-06-29 00:09:031423
[email protected]d668899a2012-09-06 18:16:591424 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
[email protected]d96b1f42014-02-27 19:17:521425 return GetDefaultTryConfigs([
1426 'mac_chromium_compile_dbg',
1427 'mac_chromium_rel',
[email protected]d96b1f42014-02-27 19:17:521428 ])
[email protected]d668899a2012-09-06 18:16:591429 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
[email protected]3630be892013-12-19 05:34:281430 return GetDefaultTryConfigs(['win', 'win_rel'])
[email protected]d668899a2012-09-06 18:16:591431 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011432 return GetDefaultTryConfigs([
1433 'android_aosp',
1434 'android_clang_dbg',
1435 'android_dbg',
1436 ])
[email protected]de142152012-10-03 23:02:451437 if all(re.search('[/_]ios[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011438 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
[email protected]4ce995ea2012-06-27 02:13:101439
[email protected]7468ac522014-03-12 23:35:571440 builders = [
[email protected]3e2f0402012-11-02 16:28:011441 'android_clang_dbg',
1442 'android_dbg',
1443 'ios_dbg_simulator',
1444 'ios_rel_device',
[email protected]d96b1f42014-02-27 19:17:521445 'linux_chromium_chromeos_rel',
1446 'linux_chromium_clang_dbg',
[email protected]d96b1f42014-02-27 19:17:521447 'linux_chromium_rel',
[email protected]d96b1f42014-02-27 19:17:521448 'mac_chromium_compile_dbg',
[email protected]d96b1f42014-02-27 19:17:521449 'mac_chromium_rel',
[email protected]0094fa12014-03-13 03:18:281450 'win_chromium_compile_dbg',
[email protected]3e2f0402012-11-02 16:28:011451 'win_rel',
[email protected]38c6a512013-12-18 23:48:011452 'win_x64_rel',
[email protected]7468ac522014-03-12 23:35:571453 ]
[email protected]911753b2012-08-02 12:11:541454
1455 # Match things like path/aura/file.cc and path/file_aura.cc.
[email protected]95c989162012-11-29 05:58:251456 # Same for chromeos.
1457 if any(re.search('[/_](aura|chromeos)', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571458 builders.extend([
1459 'linux_chromeos_asan',
1460 'linux_chromium_chromeos_clang_dbg'
1461 ])
[email protected]4ce995ea2012-06-27 02:13:101462
[email protected]e8df48f2013-09-30 20:07:541463 # If there are gyp changes to base, build, or chromeos, run a full cros build
1464 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1465 # files have a much higher chance of breaking the cros build, which is
1466 # differnt from the linux_chromeos build that most chrome developers test
1467 # with.
1468 if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571469 builders.extend(['cros_x86'])
[email protected]e8df48f2013-09-30 20:07:541470
[email protected]d95948ef2013-07-02 10:51:001471 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1472 # unless they're .gyp(i) files as changes to those files can break the gyp
1473 # step on that bot.
1474 if (not all(re.search('^chrome', f) for f in files) or
1475 any(re.search('\.gypi?$', f) for f in files)):
[email protected]7468ac522014-03-12 23:35:571476 builders.extend(['android_aosp'])
[email protected]d95948ef2013-07-02 10:51:001477
[email protected]7468ac522014-03-12 23:35:571478 return GetDefaultTryConfigs(builders)