blob: 2e6c077e5f8598be04a358721fe0d3497e0d4dc0 [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]4306417642009-06-11 00:33:4028)
[email protected]ca8d1982009-02-19 16:33:1229
[email protected]3de922f2013-12-20 13:27:3830# TestRunner library is temporarily excluded from pan-project checks until
31# it's transitioned to chromium coding style.
32_TESTRUNNER_PATHS = (
33 r"^content[\\\/]shell[\\\/]renderer[\\\/]test_runner[\\\/].*",
34 r"^content[\\\/]shell[\\\/]common[\\\/]test_runner[\\\/].*",
35)
36
[email protected]06e6d0ff2012-12-11 01:36:4437# Fragment of a regular expression that matches C++ and Objective-C++
38# implementation files.
39_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
40
41# Regular expression that matches code only used for test binaries
42# (best effort).
43_TEST_CODE_EXCLUDED_PATHS = (
44 r'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
45 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
[email protected]6e04f8c2014-01-29 18:08:3246 r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
[email protected]e2d7e6f2013-04-23 12:57:1247 _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4448 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
49 r'.*[/\\](test|tool(s)?)[/\\].*',
[email protected]ef070cc2013-05-03 11:53:0550 # content_shell is used for running layout tests.
51 r'content[/\\]shell[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4452 # At request of folks maintaining this folder.
53 r'chrome[/\\]browser[/\\]automation[/\\].*',
[email protected]7b054982013-11-27 00:44:4754 # Non-production example code.
55 r'mojo[/\\]examples[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4456)
[email protected]ca8d1982009-02-19 16:33:1257
[email protected]eea609a2011-11-18 13:10:1258_TEST_ONLY_WARNING = (
59 'You might be calling functions intended only for testing from\n'
60 'production code. It is OK to ignore this warning if you know what\n'
61 'you are doing, as the heuristics used to detect the situation are\n'
62 'not perfect. The commit queue will not block on this warning.\n'
63 'Email [email protected] if you have questions.')
64
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]398ad132013-04-02 15:11:01171 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
[email protected]7345da02012-11-27 14:31:49172 ),
[email protected]23e6cbc2012-06-16 18:51:20173 ),
[email protected]52657f62013-05-20 05:30:31174 (
175 'SkRefPtr',
176 (
177 'The use of SkRefPtr is prohibited. ',
178 'Please use skia::RefPtr instead.'
179 ),
180 True,
181 (),
182 ),
183 (
184 'SkAutoRef',
185 (
186 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
187 'Please use skia::RefPtr instead.'
188 ),
189 True,
190 (),
191 ),
192 (
193 'SkAutoTUnref',
194 (
195 'The use of SkAutoTUnref is dangerous because it implicitly ',
196 'converts to a raw pointer. Please use skia::RefPtr instead.'
197 ),
198 True,
199 (),
200 ),
201 (
202 'SkAutoUnref',
203 (
204 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
205 'because it implicitly converts to a raw pointer. ',
206 'Please use skia::RefPtr instead.'
207 ),
208 True,
209 (),
210 ),
[email protected]d89eec82013-12-03 14:10:59211 (
212 r'/HANDLE_EINTR\(.*close',
213 (
214 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
215 'descriptor will be closed, and it is incorrect to retry the close.',
216 'Either call close directly and ignore its return value, or wrap close',
217 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
218 ),
219 True,
220 (),
221 ),
222 (
223 r'/IGNORE_EINTR\((?!.*close)',
224 (
225 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
226 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
227 ),
228 True,
229 (
230 # Files that #define IGNORE_EINTR.
231 r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
232 r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
233 ),
234 ),
[email protected]127f18ec2012-06-16 05:05:59235)
236
237
[email protected]b00342e7f2013-03-26 16:21:54238_VALID_OS_MACROS = (
239 # Please keep sorted.
240 'OS_ANDROID',
241 'OS_BSD',
242 'OS_CAT', # For testing.
243 'OS_CHROMEOS',
244 'OS_FREEBSD',
245 'OS_IOS',
246 'OS_LINUX',
247 'OS_MACOSX',
248 'OS_NACL',
249 'OS_OPENBSD',
250 'OS_POSIX',
251 'OS_SOLARIS',
[email protected]b00342e7f2013-03-26 16:21:54252 'OS_WIN',
253)
254
255
[email protected]55459852011-08-10 15:17:19256def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
257 """Attempts to prevent use of functions intended only for testing in
258 non-testing code. For now this is just a best-effort implementation
259 that ignores header files and may have some false positives. A
260 better implementation would probably need a proper C++ parser.
261 """
262 # We only scan .cc files and the like, as the declaration of
263 # for-testing functions in header files are hard to distinguish from
264 # calls to such functions without a proper C++ parser.
[email protected]06e6d0ff2012-12-11 01:36:44265 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
[email protected]55459852011-08-10 15:17:19266
267 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
268 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
[email protected]de4f7d22013-05-23 14:27:46269 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
[email protected]55459852011-08-10 15:17:19270 exclusion_pattern = input_api.re.compile(
271 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
272 base_function_pattern, base_function_pattern))
273
274 def FilterFile(affected_file):
[email protected]06e6d0ff2012-12-11 01:36:44275 black_list = (_EXCLUDED_PATHS +
276 _TEST_CODE_EXCLUDED_PATHS +
277 input_api.DEFAULT_BLACK_LIST)
[email protected]55459852011-08-10 15:17:19278 return input_api.FilterSourceFile(
279 affected_file,
280 white_list=(file_inclusion_pattern, ),
281 black_list=black_list)
282
283 problems = []
284 for f in input_api.AffectedSourceFiles(FilterFile):
285 local_path = f.LocalPath()
[email protected]825d27182014-01-02 21:24:24286 for line_number, line in f.ChangedContents():
[email protected]2fdd1f362013-01-16 03:56:03287 if (inclusion_pattern.search(line) and
[email protected]de4f7d22013-05-23 14:27:46288 not comment_pattern.search(line) and
[email protected]2fdd1f362013-01-16 03:56:03289 not exclusion_pattern.search(line)):
[email protected]55459852011-08-10 15:17:19290 problems.append(
[email protected]2fdd1f362013-01-16 03:56:03291 '%s:%d\n %s' % (local_path, line_number, line.strip()))
[email protected]55459852011-08-10 15:17:19292
293 if problems:
[email protected]f7051d52013-04-02 18:31:42294 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
[email protected]2fdd1f362013-01-16 03:56:03295 else:
296 return []
[email protected]55459852011-08-10 15:17:19297
298
[email protected]10689ca2011-09-02 02:31:54299def _CheckNoIOStreamInHeaders(input_api, output_api):
300 """Checks to make sure no .h files include <iostream>."""
301 files = []
302 pattern = input_api.re.compile(r'^#include\s*<iostream>',
303 input_api.re.MULTILINE)
304 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
305 if not f.LocalPath().endswith('.h'):
306 continue
307 contents = input_api.ReadFile(f)
308 if pattern.search(contents):
309 files.append(f)
310
311 if len(files):
312 return [ output_api.PresubmitError(
[email protected]6c063c62012-07-11 19:11:06313 'Do not #include <iostream> in header files, since it inserts static '
314 'initialization into every file including the header. Instead, '
[email protected]10689ca2011-09-02 02:31:54315 '#include <ostream>. See http://crbug.com/94794',
316 files) ]
317 return []
318
319
[email protected]72df4e782012-06-21 16:28:18320def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
321 """Checks to make sure no source files use UNIT_TEST"""
322 problems = []
323 for f in input_api.AffectedFiles():
324 if (not f.LocalPath().endswith(('.cc', '.mm'))):
325 continue
326
327 for line_num, line in f.ChangedContents():
[email protected]549f86a2013-11-19 13:00:04328 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
[email protected]72df4e782012-06-21 16:28:18329 problems.append(' %s:%d' % (f.LocalPath(), line_num))
330
331 if not problems:
332 return []
333 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
334 '\n'.join(problems))]
335
336
[email protected]8ea5d4b2011-09-13 21:49:22337def _CheckNoNewWStrings(input_api, output_api):
338 """Checks to make sure we don't introduce use of wstrings."""
[email protected]55463aa62011-10-12 00:48:27339 problems = []
[email protected]8ea5d4b2011-09-13 21:49:22340 for f in input_api.AffectedFiles():
[email protected]b5c24292011-11-28 14:38:20341 if (not f.LocalPath().endswith(('.cc', '.h')) or
[email protected]24be83c2013-08-29 23:01:23342 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
[email protected]b5c24292011-11-28 14:38:20343 continue
[email protected]8ea5d4b2011-09-13 21:49:22344
[email protected]a11dbe9b2012-08-07 01:32:58345 allowWString = False
[email protected]b5c24292011-11-28 14:38:20346 for line_num, line in f.ChangedContents():
[email protected]a11dbe9b2012-08-07 01:32:58347 if 'presubmit: allow wstring' in line:
348 allowWString = True
349 elif not allowWString and 'wstring' in line:
[email protected]55463aa62011-10-12 00:48:27350 problems.append(' %s:%d' % (f.LocalPath(), line_num))
[email protected]a11dbe9b2012-08-07 01:32:58351 allowWString = False
352 else:
353 allowWString = False
[email protected]8ea5d4b2011-09-13 21:49:22354
[email protected]55463aa62011-10-12 00:48:27355 if not problems:
356 return []
357 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
[email protected]a11dbe9b2012-08-07 01:32:58358 ' If you are calling a cross-platform API that accepts a wstring, '
359 'fix the API.\n' +
[email protected]55463aa62011-10-12 00:48:27360 '\n'.join(problems))]
[email protected]8ea5d4b2011-09-13 21:49:22361
362
[email protected]2a8ac9c2011-10-19 17:20:44363def _CheckNoDEPSGIT(input_api, output_api):
364 """Make sure .DEPS.git is never modified manually."""
365 if any(f.LocalPath().endswith('.DEPS.git') for f in
366 input_api.AffectedFiles()):
367 return [output_api.PresubmitError(
368 'Never commit changes to .DEPS.git. This file is maintained by an\n'
369 'automated system based on what\'s in DEPS and your changes will be\n'
370 'overwritten.\n'
371 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
372 'for more information')]
373 return []
374
375
[email protected]127f18ec2012-06-16 05:05:59376def _CheckNoBannedFunctions(input_api, output_api):
377 """Make sure that banned functions are not used."""
378 warnings = []
379 errors = []
380
381 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
382 for f in input_api.AffectedFiles(file_filter=file_filter):
383 for line_num, line in f.ChangedContents():
384 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
385 if func_name in line:
386 problems = warnings;
387 if error:
388 problems = errors;
389 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
390 for message_line in message:
391 problems.append(' %s' % message_line)
392
393 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
394 for f in input_api.AffectedFiles(file_filter=file_filter):
395 for line_num, line in f.ChangedContents():
[email protected]7345da02012-11-27 14:31:49396 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
397 def IsBlacklisted(affected_file, blacklist):
398 local_path = affected_file.LocalPath()
399 for item in blacklist:
400 if input_api.re.match(item, local_path):
401 return True
402 return False
403 if IsBlacklisted(f, excluded_paths):
404 continue
[email protected]d89eec82013-12-03 14:10:59405 matched = False
406 if func_name[0:1] == '/':
407 regex = func_name[1:]
408 if input_api.re.search(regex, line):
409 matched = True
410 elif func_name in line:
411 matched = True
412 if matched:
[email protected]127f18ec2012-06-16 05:05:59413 problems = warnings;
414 if error:
415 problems = errors;
416 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
417 for message_line in message:
418 problems.append(' %s' % message_line)
419
420 result = []
421 if (warnings):
422 result.append(output_api.PresubmitPromptWarning(
423 'Banned functions were used.\n' + '\n'.join(warnings)))
424 if (errors):
425 result.append(output_api.PresubmitError(
426 'Banned functions were used.\n' + '\n'.join(errors)))
427 return result
428
429
[email protected]6c063c62012-07-11 19:11:06430def _CheckNoPragmaOnce(input_api, output_api):
431 """Make sure that banned functions are not used."""
432 files = []
433 pattern = input_api.re.compile(r'^#pragma\s+once',
434 input_api.re.MULTILINE)
435 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
436 if not f.LocalPath().endswith('.h'):
437 continue
438 contents = input_api.ReadFile(f)
439 if pattern.search(contents):
440 files.append(f)
441
442 if files:
443 return [output_api.PresubmitError(
444 'Do not use #pragma once in header files.\n'
445 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
446 files)]
447 return []
448
[email protected]127f18ec2012-06-16 05:05:59449
[email protected]e7479052012-09-19 00:26:12450def _CheckNoTrinaryTrueFalse(input_api, output_api):
451 """Checks to make sure we don't introduce use of foo ? true : false."""
452 problems = []
453 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
454 for f in input_api.AffectedFiles():
455 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
456 continue
457
458 for line_num, line in f.ChangedContents():
459 if pattern.match(line):
460 problems.append(' %s:%d' % (f.LocalPath(), line_num))
461
462 if not problems:
463 return []
464 return [output_api.PresubmitPromptWarning(
465 'Please consider avoiding the "? true : false" pattern if possible.\n' +
466 '\n'.join(problems))]
467
468
[email protected]55f9f382012-07-31 11:02:18469def _CheckUnwantedDependencies(input_api, output_api):
470 """Runs checkdeps on #include statements added in this
471 change. Breaking - rules is an error, breaking ! rules is a
472 warning.
473 """
474 # We need to wait until we have an input_api object and use this
475 # roundabout construct to import checkdeps because this file is
476 # eval-ed and thus doesn't have __file__.
477 original_sys_path = sys.path
478 try:
479 sys.path = sys.path + [input_api.os_path.join(
480 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
481 import checkdeps
482 from cpp_checker import CppChecker
483 from rules import Rule
484 finally:
485 # Restore sys.path to what it was before.
486 sys.path = original_sys_path
487
488 added_includes = []
489 for f in input_api.AffectedFiles():
490 if not CppChecker.IsCppFile(f.LocalPath()):
491 continue
492
493 changed_lines = [line for line_num, line in f.ChangedContents()]
494 added_includes.append([f.LocalPath(), changed_lines])
495
[email protected]26385172013-05-09 23:11:35496 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
[email protected]55f9f382012-07-31 11:02:18497
498 error_descriptions = []
499 warning_descriptions = []
500 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
501 added_includes):
502 description_with_path = '%s\n %s' % (path, rule_description)
503 if rule_type == Rule.DISALLOW:
504 error_descriptions.append(description_with_path)
505 else:
506 warning_descriptions.append(description_with_path)
507
508 results = []
509 if error_descriptions:
510 results.append(output_api.PresubmitError(
511 'You added one or more #includes that violate checkdeps rules.',
512 error_descriptions))
513 if warning_descriptions:
[email protected]f7051d52013-04-02 18:31:42514 results.append(output_api.PresubmitPromptOrNotify(
[email protected]55f9f382012-07-31 11:02:18515 'You added one or more #includes of files that are temporarily\n'
516 'allowed but being removed. Can you avoid introducing the\n'
517 '#include? See relevant DEPS file(s) for details and contacts.',
518 warning_descriptions))
519 return results
520
521
[email protected]fbcafe5a2012-08-08 15:31:22522def _CheckFilePermissions(input_api, output_api):
523 """Check that all files have their permissions properly set."""
524 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
525 input_api.change.RepositoryRoot()]
526 for f in input_api.AffectedFiles():
527 args += ['--file', f.LocalPath()]
[email protected]f0d330f2014-01-30 01:44:34528 checkperms = input_api.subprocess.Popen(args,
529 stdout=input_api.subprocess.PIPE)
530 errors = checkperms.communicate()[0].strip()
[email protected]fbcafe5a2012-08-08 15:31:22531 if errors:
[email protected]f0d330f2014-01-30 01:44:34532 return [output_api.PresubmitError('checkperms.py failed.',
533 errors.splitlines())]
534 return []
[email protected]fbcafe5a2012-08-08 15:31:22535
536
[email protected]c8278b32012-10-30 20:35:49537def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
538 """Makes sure we don't include ui/aura/window_property.h
539 in header files.
540 """
541 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
542 errors = []
543 for f in input_api.AffectedFiles():
544 if not f.LocalPath().endswith('.h'):
545 continue
546 for line_num, line in f.ChangedContents():
547 if pattern.match(line):
548 errors.append(' %s:%d' % (f.LocalPath(), line_num))
549
550 results = []
551 if errors:
552 results.append(output_api.PresubmitError(
553 'Header files should not include ui/aura/window_property.h', errors))
554 return results
555
556
[email protected]cf9b78f2012-11-14 11:40:28557def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
558 """Checks that the lines in scope occur in the right order.
559
560 1. C system files in alphabetical order
561 2. C++ system files in alphabetical order
562 3. Project's .h files
563 """
564
565 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
566 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
567 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
568
569 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
570
571 state = C_SYSTEM_INCLUDES
572
573 previous_line = ''
[email protected]728b9bb2012-11-14 20:38:57574 previous_line_num = 0
[email protected]cf9b78f2012-11-14 11:40:28575 problem_linenums = []
576 for line_num, line in scope:
577 if c_system_include_pattern.match(line):
578 if state != C_SYSTEM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57579 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28580 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57581 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28582 elif cpp_system_include_pattern.match(line):
583 if state == C_SYSTEM_INCLUDES:
584 state = CPP_SYSTEM_INCLUDES
585 elif state == CUSTOM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57586 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28587 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57588 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28589 elif custom_include_pattern.match(line):
590 if state != CUSTOM_INCLUDES:
591 state = CUSTOM_INCLUDES
592 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57593 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28594 else:
595 problem_linenums.append(line_num)
596 previous_line = line
[email protected]728b9bb2012-11-14 20:38:57597 previous_line_num = line_num
[email protected]cf9b78f2012-11-14 11:40:28598
599 warnings = []
[email protected]728b9bb2012-11-14 20:38:57600 for (line_num, previous_line_num) in problem_linenums:
601 if line_num in changed_linenums or previous_line_num in changed_linenums:
[email protected]cf9b78f2012-11-14 11:40:28602 warnings.append(' %s:%d' % (file_path, line_num))
603 return warnings
604
605
[email protected]ac294a12012-12-06 16:38:43606def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
[email protected]cf9b78f2012-11-14 11:40:28607 """Checks the #include order for the given file f."""
608
[email protected]2299dcf2012-11-15 19:56:24609 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
[email protected]23093b62013-09-20 12:16:30610 # Exclude the following includes from the check:
611 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
612 # specific order.
613 # 2) <atlbase.h>, "build/build_config.h"
614 excluded_include_pattern = input_api.re.compile(
615 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
[email protected]2299dcf2012-11-15 19:56:24616 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
[email protected]3e83618c2013-10-09 22:32:33617 # Match the final or penultimate token if it is xxxtest so we can ignore it
618 # when considering the special first include.
619 test_file_tag_pattern = input_api.re.compile(
620 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
[email protected]0e5c1852012-12-18 20:17:11621 if_pattern = input_api.re.compile(
622 r'\s*#\s*(if|elif|else|endif|define|undef).*')
623 # Some files need specialized order of includes; exclude such files from this
624 # check.
625 uncheckable_includes_pattern = input_api.re.compile(
626 r'\s*#include '
627 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
[email protected]cf9b78f2012-11-14 11:40:28628
629 contents = f.NewContents()
630 warnings = []
631 line_num = 0
632
[email protected]ac294a12012-12-06 16:38:43633 # Handle the special first include. If the first include file is
634 # some/path/file.h, the corresponding including file can be some/path/file.cc,
635 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
636 # etc. It's also possible that no special first include exists.
[email protected]3e83618c2013-10-09 22:32:33637 # If the included file is some/path/file_platform.h the including file could
638 # also be some/path/file_xxxtest_platform.h.
639 including_file_base_name = test_file_tag_pattern.sub(
640 '', input_api.os_path.basename(f.LocalPath()))
641
[email protected]ac294a12012-12-06 16:38:43642 for line in contents:
643 line_num += 1
644 if system_include_pattern.match(line):
645 # No special first include -> process the line again along with normal
646 # includes.
647 line_num -= 1
648 break
649 match = custom_include_pattern.match(line)
650 if match:
651 match_dict = match.groupdict()
[email protected]3e83618c2013-10-09 22:32:33652 header_basename = test_file_tag_pattern.sub(
653 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
654
655 if header_basename not in including_file_base_name:
[email protected]2299dcf2012-11-15 19:56:24656 # No special first include -> process the line again along with normal
657 # includes.
658 line_num -= 1
[email protected]ac294a12012-12-06 16:38:43659 break
[email protected]cf9b78f2012-11-14 11:40:28660
661 # Split into scopes: Each region between #if and #endif is its own scope.
662 scopes = []
663 current_scope = []
664 for line in contents[line_num:]:
665 line_num += 1
[email protected]0e5c1852012-12-18 20:17:11666 if uncheckable_includes_pattern.match(line):
[email protected]4436c9e2014-01-07 23:19:54667 continue
[email protected]2309b0fa02012-11-16 12:18:27668 if if_pattern.match(line):
[email protected]cf9b78f2012-11-14 11:40:28669 scopes.append(current_scope)
670 current_scope = []
[email protected]962f117e2012-11-22 18:11:56671 elif ((system_include_pattern.match(line) or
672 custom_include_pattern.match(line)) and
673 not excluded_include_pattern.match(line)):
[email protected]cf9b78f2012-11-14 11:40:28674 current_scope.append((line_num, line))
675 scopes.append(current_scope)
676
677 for scope in scopes:
678 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
679 changed_linenums))
680 return warnings
681
682
683def _CheckIncludeOrder(input_api, output_api):
684 """Checks that the #include order is correct.
685
686 1. The corresponding header for source files.
687 2. C system files in alphabetical order
688 3. C++ system files in alphabetical order
689 4. Project's .h files in alphabetical order
690
[email protected]ac294a12012-12-06 16:38:43691 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
692 these rules separately.
[email protected]cf9b78f2012-11-14 11:40:28693 """
694
695 warnings = []
696 for f in input_api.AffectedFiles():
[email protected]ac294a12012-12-06 16:38:43697 if f.LocalPath().endswith(('.cc', '.h')):
698 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
699 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
[email protected]cf9b78f2012-11-14 11:40:28700
701 results = []
702 if warnings:
[email protected]f7051d52013-04-02 18:31:42703 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
[email protected]120cf540d2012-12-10 17:55:53704 warnings))
[email protected]cf9b78f2012-11-14 11:40:28705 return results
706
707
[email protected]70ca77752012-11-20 03:45:03708def _CheckForVersionControlConflictsInFile(input_api, f):
709 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
710 errors = []
711 for line_num, line in f.ChangedContents():
712 if pattern.match(line):
713 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
714 return errors
715
716
717def _CheckForVersionControlConflicts(input_api, output_api):
718 """Usually this is not intentional and will cause a compile failure."""
719 errors = []
720 for f in input_api.AffectedFiles():
721 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
722
723 results = []
724 if errors:
725 results.append(output_api.PresubmitError(
726 'Version control conflict markers found, please resolve.', errors))
727 return results
728
729
[email protected]06e6d0ff2012-12-11 01:36:44730def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
731 def FilterFile(affected_file):
732 """Filter function for use with input_api.AffectedSourceFiles,
733 below. This filters out everything except non-test files from
734 top-level directories that generally speaking should not hard-code
735 service URLs (e.g. src/android_webview/, src/content/ and others).
736 """
737 return input_api.FilterSourceFile(
738 affected_file,
[email protected]78bb39d62012-12-11 15:11:56739 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
[email protected]06e6d0ff2012-12-11 01:36:44740 black_list=(_EXCLUDED_PATHS +
741 _TEST_CODE_EXCLUDED_PATHS +
742 input_api.DEFAULT_BLACK_LIST))
743
[email protected]de4f7d22013-05-23 14:27:46744 base_pattern = '"[^"]*google\.com[^"]*"'
745 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
746 pattern = input_api.re.compile(base_pattern)
[email protected]06e6d0ff2012-12-11 01:36:44747 problems = [] # items are (filename, line_number, line)
748 for f in input_api.AffectedSourceFiles(FilterFile):
749 for line_num, line in f.ChangedContents():
[email protected]de4f7d22013-05-23 14:27:46750 if not comment_pattern.search(line) and pattern.search(line):
[email protected]06e6d0ff2012-12-11 01:36:44751 problems.append((f.LocalPath(), line_num, line))
752
753 if problems:
[email protected]f7051d52013-04-02 18:31:42754 return [output_api.PresubmitPromptOrNotify(
[email protected]06e6d0ff2012-12-11 01:36:44755 'Most layers below src/chrome/ should not hardcode service URLs.\n'
756 'Are you sure this is correct? (Contact: [email protected])',
757 [' %s:%d: %s' % (
758 problem[0], problem[1], problem[2]) for problem in problems])]
[email protected]2fdd1f362013-01-16 03:56:03759 else:
760 return []
[email protected]06e6d0ff2012-12-11 01:36:44761
762
[email protected]d2530012013-01-25 16:39:27763def _CheckNoAbbreviationInPngFileName(input_api, output_api):
764 """Makes sure there are no abbreviations in the name of PNG files.
765 """
[email protected]4053a48e2013-01-25 21:43:04766 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
[email protected]d2530012013-01-25 16:39:27767 errors = []
768 for f in input_api.AffectedFiles(include_deletes=False):
769 if pattern.match(f.LocalPath()):
770 errors.append(' %s' % f.LocalPath())
771
772 results = []
773 if errors:
774 results.append(output_api.PresubmitError(
775 'The name of PNG files should not have abbreviations. \n'
776 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
777 'Contact [email protected] if you have questions.', errors))
778 return results
779
780
[email protected]14a6131c2014-01-08 01:15:41781def _FilesToCheckForIncomingDeps(re, changed_lines):
[email protected]f32e2d1e2013-07-26 21:39:08782 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
[email protected]14a6131c2014-01-08 01:15:41783 a set of DEPS entries that we should look up.
784
785 For a directory (rather than a specific filename) we fake a path to
786 a specific filename by adding /DEPS. This is chosen as a file that
787 will seldom or never be subject to per-file include_rules.
788 """
[email protected]2b438d62013-11-14 17:54:14789 # We ignore deps entries on auto-generated directories.
790 AUTO_GENERATED_DIRS = ['grit', 'jni']
[email protected]f32e2d1e2013-07-26 21:39:08791
792 # This pattern grabs the path without basename in the first
793 # parentheses, and the basename (if present) in the second. It
794 # relies on the simple heuristic that if there is a basename it will
795 # be a header file ending in ".h".
796 pattern = re.compile(
797 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
[email protected]2b438d62013-11-14 17:54:14798 results = set()
[email protected]f32e2d1e2013-07-26 21:39:08799 for changed_line in changed_lines:
800 m = pattern.match(changed_line)
801 if m:
802 path = m.group(1)
[email protected]2b438d62013-11-14 17:54:14803 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
[email protected]14a6131c2014-01-08 01:15:41804 if m.group(2):
805 results.add('%s%s' % (path, m.group(2)))
806 else:
807 results.add('%s/DEPS' % path)
[email protected]f32e2d1e2013-07-26 21:39:08808 return results
809
810
[email protected]e871964c2013-05-13 14:14:55811def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
812 """When a dependency prefixed with + is added to a DEPS file, we
813 want to make sure that the change is reviewed by an OWNER of the
814 target file or directory, to avoid layering violations from being
815 introduced. This check verifies that this happens.
816 """
817 changed_lines = set()
818 for f in input_api.AffectedFiles():
819 filename = input_api.os_path.basename(f.LocalPath())
820 if filename == 'DEPS':
821 changed_lines |= set(line.strip()
822 for line_num, line
823 in f.ChangedContents())
824 if not changed_lines:
825 return []
826
[email protected]14a6131c2014-01-08 01:15:41827 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
828 changed_lines)
[email protected]e871964c2013-05-13 14:14:55829 if not virtual_depended_on_files:
830 return []
831
832 if input_api.is_committing:
833 if input_api.tbr:
834 return [output_api.PresubmitNotifyResult(
835 '--tbr was specified, skipping OWNERS check for DEPS additions')]
836 if not input_api.change.issue:
837 return [output_api.PresubmitError(
838 "DEPS approval by OWNERS check failed: this change has "
839 "no Rietveld issue number, so we can't check it for approvals.")]
840 output = output_api.PresubmitError
841 else:
842 output = output_api.PresubmitNotifyResult
843
844 owners_db = input_api.owners_db
845 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
846 input_api,
847 owners_db.email_regexp,
848 approval_needed=input_api.is_committing)
849
850 owner_email = owner_email or input_api.change.author_email
851
[email protected]de4f7d22013-05-23 14:27:46852 reviewers_plus_owner = set(reviewers)
[email protected]e71c6082013-05-22 02:28:51853 if owner_email:
[email protected]de4f7d22013-05-23 14:27:46854 reviewers_plus_owner.add(owner_email)
[email protected]e871964c2013-05-13 14:14:55855 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
856 reviewers_plus_owner)
[email protected]14a6131c2014-01-08 01:15:41857
858 # We strip the /DEPS part that was added by
859 # _FilesToCheckForIncomingDeps to fake a path to a file in a
860 # directory.
861 def StripDeps(path):
862 start_deps = path.rfind('/DEPS')
863 if start_deps != -1:
864 return path[:start_deps]
865 else:
866 return path
867 unapproved_dependencies = ["'+%s'," % StripDeps(path)
[email protected]e871964c2013-05-13 14:14:55868 for path in missing_files]
869
870 if unapproved_dependencies:
871 output_list = [
[email protected]14a6131c2014-01-08 01:15:41872 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
[email protected]e871964c2013-05-13 14:14:55873 '\n '.join(sorted(unapproved_dependencies)))]
874 if not input_api.is_committing:
875 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
876 output_list.append(output(
877 'Suggested missing target path OWNERS:\n %s' %
878 '\n '.join(suggested_owners or [])))
879 return output_list
880
881 return []
882
883
[email protected]85218562013-11-22 07:41:40884def _CheckSpamLogging(input_api, output_api):
885 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
886 black_list = (_EXCLUDED_PATHS +
887 _TEST_CODE_EXCLUDED_PATHS +
888 input_api.DEFAULT_BLACK_LIST +
[email protected]6f742dd02013-11-26 23:19:50889 (r"^base[\\\/]logging\.h$",
[email protected]80f360a2014-01-23 01:36:19890 r"^base[\\\/]logging\.cc$",
[email protected]8dc338c2013-12-09 16:28:48891 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
[email protected]6e268db2013-12-04 01:41:46892 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
[email protected]4de75262013-12-18 23:16:12893 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
894 r"startup_browser_creator\.cc$",
[email protected]fe0e6e12013-12-04 05:52:58895 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
[email protected]95c6b3012013-12-02 14:30:31896 r"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
[email protected]6e268db2013-12-04 01:41:46897 r"logging_native_handler\.cc$",
[email protected]9056e732014-01-08 06:25:25898 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
899 r"gl_helper_benchmark\.cc$",
[email protected]cdbdced2013-11-27 21:35:50900 r"^remoting[\\\/]base[\\\/]logging\.h$",
[email protected]67c96ab2013-12-17 02:05:36901 r"^remoting[\\\/]host[\\\/].*",
[email protected]8232f8fd2013-12-14 00:52:31902 r"^sandbox[\\\/]linux[\\\/].*",
[email protected]90f69902014-01-22 17:49:55903 r"^tools[\\\/]telemetry[\\\/]telemetry[\\\/]core[\\\/]"
904 r"bitmaptools.cc$",
[email protected]8232f8fd2013-12-14 00:52:31905 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
[email protected]85218562013-11-22 07:41:40906 source_file_filter = lambda x: input_api.FilterSourceFile(
907 x, white_list=(file_inclusion_pattern,), black_list=black_list)
908
909 log_info = []
910 printf = []
911
912 for f in input_api.AffectedSourceFiles(source_file_filter):
913 contents = input_api.ReadFile(f, 'rb')
914 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
915 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37916 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
[email protected]85210652013-11-28 05:50:13917 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37918
919 if re.search(r"\bprintf\(", contents):
920 printf.append(f.LocalPath())
921 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
[email protected]85218562013-11-22 07:41:40922 printf.append(f.LocalPath())
923
924 if log_info:
925 return [output_api.PresubmitError(
926 'These files spam the console log with LOG(INFO):',
927 items=log_info)]
928 if printf:
929 return [output_api.PresubmitError(
930 'These files spam the console log with printf/fprintf:',
931 items=printf)]
932 return []
933
934
[email protected]49aa76a2013-12-04 06:59:16935def _CheckForAnonymousVariables(input_api, output_api):
936 """These types are all expected to hold locks while in scope and
937 so should never be anonymous (which causes them to be immediately
938 destroyed)."""
939 they_who_must_be_named = [
940 'base::AutoLock',
941 'base::AutoReset',
942 'base::AutoUnlock',
943 'SkAutoAlphaRestore',
944 'SkAutoBitmapShaderInstall',
945 'SkAutoBlitterChoose',
946 'SkAutoBounderCommit',
947 'SkAutoCallProc',
948 'SkAutoCanvasRestore',
949 'SkAutoCommentBlock',
950 'SkAutoDescriptor',
951 'SkAutoDisableDirectionCheck',
952 'SkAutoDisableOvalCheck',
953 'SkAutoFree',
954 'SkAutoGlyphCache',
955 'SkAutoHDC',
956 'SkAutoLockColors',
957 'SkAutoLockPixels',
958 'SkAutoMalloc',
959 'SkAutoMaskFreeImage',
960 'SkAutoMutexAcquire',
961 'SkAutoPathBoundsUpdate',
962 'SkAutoPDFRelease',
963 'SkAutoRasterClipValidate',
964 'SkAutoRef',
965 'SkAutoTime',
966 'SkAutoTrace',
967 'SkAutoUnref',
968 ]
969 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
970 # bad: base::AutoLock(lock.get());
971 # not bad: base::AutoLock lock(lock.get());
972 bad_pattern = input_api.re.compile(anonymous)
973 # good: new base::AutoLock(lock.get())
974 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
975 errors = []
976
977 for f in input_api.AffectedFiles():
978 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
979 continue
980 for linenum, line in f.ChangedContents():
981 if bad_pattern.search(line) and not good_pattern.search(line):
982 errors.append('%s:%d' % (f.LocalPath(), linenum))
983
984 if errors:
985 return [output_api.PresubmitError(
986 'These lines create anonymous variables that need to be named:',
987 items=errors)]
988 return []
989
990
[email protected]5fe0f8742013-11-29 01:04:59991def _CheckCygwinShell(input_api, output_api):
992 source_file_filter = lambda x: input_api.FilterSourceFile(
993 x, white_list=(r'.+\.(gyp|gypi)$',))
994 cygwin_shell = []
995
996 for f in input_api.AffectedSourceFiles(source_file_filter):
997 for linenum, line in f.ChangedContents():
998 if 'msvs_cygwin_shell' in line:
999 cygwin_shell.append(f.LocalPath())
1000 break
1001
1002 if cygwin_shell:
1003 return [output_api.PresubmitError(
1004 'These files should not use msvs_cygwin_shell (the default is 0):',
1005 items=cygwin_shell)]
1006 return []
1007
[email protected]85218562013-11-22 07:41:401008
[email protected]760deea2013-12-10 19:33:491009def _CheckJavaStyle(input_api, output_api):
1010 """Runs checkstyle on changed java files and returns errors if any exist."""
1011 original_sys_path = sys.path
1012 try:
1013 sys.path = sys.path + [input_api.os_path.join(
1014 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1015 import checkstyle
1016 finally:
1017 # Restore sys.path to what it was before.
1018 sys.path = original_sys_path
1019
1020 return checkstyle.RunCheckstyle(
1021 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1022
1023
[email protected]22c9bd72011-03-27 16:47:391024def _CommonChecks(input_api, output_api):
1025 """Checks common to both upload and commit."""
1026 results = []
1027 results.extend(input_api.canned_checks.PanProjectChecks(
[email protected]3de922f2013-12-20 13:27:381028 input_api, output_api,
1029 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
[email protected]66daa702011-05-28 14:41:461030 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]55459852011-08-10 15:17:191031 results.extend(
[email protected]760deea2013-12-10 19:33:491032 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
[email protected]10689ca2011-09-02 02:31:541033 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
[email protected]72df4e782012-06-21 16:28:181034 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
[email protected]8ea5d4b2011-09-13 21:49:221035 results.extend(_CheckNoNewWStrings(input_api, output_api))
[email protected]2a8ac9c2011-10-19 17:20:441036 results.extend(_CheckNoDEPSGIT(input_api, output_api))
[email protected]127f18ec2012-06-16 05:05:591037 results.extend(_CheckNoBannedFunctions(input_api, output_api))
[email protected]6c063c62012-07-11 19:11:061038 results.extend(_CheckNoPragmaOnce(input_api, output_api))
[email protected]e7479052012-09-19 00:26:121039 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
[email protected]55f9f382012-07-31 11:02:181040 results.extend(_CheckUnwantedDependencies(input_api, output_api))
[email protected]fbcafe5a2012-08-08 15:31:221041 results.extend(_CheckFilePermissions(input_api, output_api))
[email protected]c8278b32012-10-30 20:35:491042 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
[email protected]2309b0fa02012-11-16 12:18:271043 results.extend(_CheckIncludeOrder(input_api, output_api))
[email protected]70ca77752012-11-20 03:45:031044 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
[email protected]b8079ae4a2012-12-05 19:56:491045 results.extend(_CheckPatchFiles(input_api, output_api))
[email protected]06e6d0ff2012-12-11 01:36:441046 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
[email protected]d2530012013-01-25 16:39:271047 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
[email protected]b00342e7f2013-03-26 16:21:541048 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
[email protected]e871964c2013-05-13 14:14:551049 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
[email protected]9f919cc2013-07-31 03:04:041050 results.extend(
1051 input_api.canned_checks.CheckChangeHasNoTabs(
1052 input_api,
1053 output_api,
1054 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
[email protected]85218562013-11-22 07:41:401055 results.extend(_CheckSpamLogging(input_api, output_api))
[email protected]49aa76a2013-12-04 06:59:161056 results.extend(_CheckForAnonymousVariables(input_api, output_api))
[email protected]5fe0f8742013-11-29 01:04:591057 results.extend(_CheckCygwinShell(input_api, output_api))
[email protected]760deea2013-12-10 19:33:491058 results.extend(_CheckJavaStyle(input_api, output_api))
[email protected]2299dcf2012-11-15 19:56:241059
1060 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1061 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1062 input_api, output_api,
1063 input_api.PresubmitLocalPath(),
[email protected]6be63382013-01-21 15:42:381064 whitelist=[r'^PRESUBMIT_test\.py$']))
[email protected]22c9bd72011-03-27 16:47:391065 return results
[email protected]1f7b4172010-01-28 01:17:341066
[email protected]b337cb5b2011-01-23 21:24:051067
1068def _CheckSubversionConfig(input_api, output_api):
1069 """Verifies the subversion config file is correctly setup.
1070
1071 Checks that autoprops are enabled, returns an error otherwise.
1072 """
1073 join = input_api.os_path.join
1074 if input_api.platform == 'win32':
1075 appdata = input_api.environ.get('APPDATA', '')
1076 if not appdata:
1077 return [output_api.PresubmitError('%APPDATA% is not configured.')]
1078 path = join(appdata, 'Subversion', 'config')
1079 else:
1080 home = input_api.environ.get('HOME', '')
1081 if not home:
1082 return [output_api.PresubmitError('$HOME is not configured.')]
1083 path = join(home, '.subversion', 'config')
1084
1085 error_msg = (
1086 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1087 'configure your subversion configuration file. This enables automatic\n'
[email protected]c6a3c10b2011-01-24 16:14:201088 'properties to simplify the project maintenance.\n'
1089 'Pro-tip: just download and install\n'
1090 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
[email protected]b337cb5b2011-01-23 21:24:051091
1092 try:
1093 lines = open(path, 'r').read().splitlines()
1094 # Make sure auto-props is enabled and check for 2 Chromium standard
1095 # auto-prop.
1096 if (not '*.cc = svn:eol-style=LF' in lines or
1097 not '*.pdf = svn:mime-type=application/pdf' in lines or
1098 not 'enable-auto-props = yes' in lines):
1099 return [
[email protected]79ed7e62011-02-21 21:08:531100 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:051101 'It looks like you have not configured your subversion config '
[email protected]b5359c02011-02-01 20:29:561102 'file or it is not up-to-date.\n' + error_msg)
[email protected]b337cb5b2011-01-23 21:24:051103 ]
1104 except (OSError, IOError):
1105 return [
[email protected]79ed7e62011-02-21 21:08:531106 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:051107 'Can\'t find your subversion config file.\n' + error_msg)
1108 ]
1109 return []
1110
1111
[email protected]66daa702011-05-28 14:41:461112def _CheckAuthorizedAuthor(input_api, output_api):
1113 """For non-googler/chromites committers, verify the author's email address is
1114 in AUTHORS.
1115 """
[email protected]9bb9cb82011-06-13 20:43:011116 # TODO(maruel): Add it to input_api?
1117 import fnmatch
1118
[email protected]66daa702011-05-28 14:41:461119 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:011120 if not author:
1121 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:461122 return []
[email protected]c99663292011-05-31 19:46:081123 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:461124 input_api.PresubmitLocalPath(), 'AUTHORS')
1125 valid_authors = (
1126 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1127 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:181128 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]d8b50be2011-06-15 14:19:441129 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]5861efb2013-01-07 18:33:231130 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
[email protected]66daa702011-05-28 14:41:461131 return [output_api.PresubmitPromptWarning(
1132 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1133 '\n'
1134 'http://www.chromium.org/developers/contributing-code and read the '
1135 '"Legal" section\n'
1136 'If you are a chromite, verify the contributor signed the CLA.') %
1137 author)]
1138 return []
1139
1140
[email protected]b8079ae4a2012-12-05 19:56:491141def _CheckPatchFiles(input_api, output_api):
1142 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1143 if f.LocalPath().endswith(('.orig', '.rej'))]
1144 if problems:
1145 return [output_api.PresubmitError(
1146 "Don't commit .rej and .orig files.", problems)]
[email protected]2fdd1f362013-01-16 03:56:031147 else:
1148 return []
[email protected]b8079ae4a2012-12-05 19:56:491149
1150
[email protected]b00342e7f2013-03-26 16:21:541151def _DidYouMeanOSMacro(bad_macro):
1152 try:
1153 return {'A': 'OS_ANDROID',
1154 'B': 'OS_BSD',
1155 'C': 'OS_CHROMEOS',
1156 'F': 'OS_FREEBSD',
1157 'L': 'OS_LINUX',
1158 'M': 'OS_MACOSX',
1159 'N': 'OS_NACL',
1160 'O': 'OS_OPENBSD',
1161 'P': 'OS_POSIX',
1162 'S': 'OS_SOLARIS',
1163 'W': 'OS_WIN'}[bad_macro[3].upper()]
1164 except KeyError:
1165 return ''
1166
1167
1168def _CheckForInvalidOSMacrosInFile(input_api, f):
1169 """Check for sensible looking, totally invalid OS macros."""
1170 preprocessor_statement = input_api.re.compile(r'^\s*#')
1171 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1172 results = []
1173 for lnum, line in f.ChangedContents():
1174 if preprocessor_statement.search(line):
1175 for match in os_macro.finditer(line):
1176 if not match.group(1) in _VALID_OS_MACROS:
1177 good = _DidYouMeanOSMacro(match.group(1))
1178 did_you_mean = ' (did you mean %s?)' % good if good else ''
1179 results.append(' %s:%d %s%s' % (f.LocalPath(),
1180 lnum,
1181 match.group(1),
1182 did_you_mean))
1183 return results
1184
1185
1186def _CheckForInvalidOSMacros(input_api, output_api):
1187 """Check all affected files for invalid OS macros."""
1188 bad_macros = []
1189 for f in input_api.AffectedFiles():
1190 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1191 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1192
1193 if not bad_macros:
1194 return []
1195
1196 return [output_api.PresubmitError(
1197 'Possibly invalid OS macro[s] found. Please fix your code\n'
1198 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1199
1200
[email protected]1f7b4172010-01-28 01:17:341201def CheckChangeOnUpload(input_api, output_api):
1202 results = []
1203 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541204 return results
[email protected]ca8d1982009-02-19 16:33:121205
1206
[email protected]38c6a512013-12-18 23:48:011207def GetDefaultTryConfigs(bots=None):
1208 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1209
1210 To add tests to this list, they MUST be in the the corresponding master's
1211 gatekeeper config. For example, anything on master.chromium would be closed by
1212 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1213
1214 If 'bots' is specified, will only return configurations for bots in that list.
1215 """
1216
1217 standard_tests = [
1218 'base_unittests',
1219 'browser_tests',
1220 'cacheinvalidation_unittests',
1221 'check_deps',
1222 'check_deps2git',
1223 'content_browsertests',
1224 'content_unittests',
1225 'crypto_unittests',
1226 #'gfx_unittests',
1227 'gpu_unittests',
1228 'interactive_ui_tests',
1229 'ipc_tests',
1230 'jingle_unittests',
1231 'media_unittests',
1232 'net_unittests',
1233 'ppapi_unittests',
1234 'printing_unittests',
1235 'sql_unittests',
1236 'sync_unit_tests',
1237 'unit_tests',
1238 # Broken in release.
1239 #'url_unittests',
1240 #'webkit_unit_tests',
1241 ]
1242
1243 linux_aura_tests = [
1244 'app_list_unittests',
1245 'aura_unittests',
1246 'browser_tests',
1247 'compositor_unittests',
1248 'content_browsertests',
1249 'content_unittests',
1250 'events_unittests',
1251 'interactive_ui_tests',
1252 'unit_tests',
1253 ]
1254 builders_and_tests = {
1255 # TODO(maruel): Figure out a way to run 'sizes' where people can
1256 # effectively update the perf expectation correctly. This requires a
1257 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1258 # incremental build. Reference:
1259 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1260 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1261 # of this step as a try job failure.
1262 'android_aosp': ['compile'],
1263 'android_clang_dbg': ['slave_steps'],
1264 'android_dbg': ['slave_steps'],
1265 'cros_x86': ['defaulttests'],
1266 'ios_dbg_simulator': [
1267 'compile',
1268 'base_unittests',
1269 'content_unittests',
1270 'crypto_unittests',
1271 'url_unittests',
1272 'net_unittests',
1273 'sql_unittests',
1274 'ui_unittests',
1275 ],
1276 'ios_rel_device': ['compile'],
1277 'linux_asan': ['defaulttests'],
1278 #TODO(stip): Change the name of this builder to reflect that it's release.
1279 'linux_aura': linux_aura_tests,
1280 'linux_chromeos_asan': ['defaulttests'],
1281 'linux_chromeos_clang': ['compile'],
1282 # Note: It is a Release builder even if its name convey otherwise.
1283 'linux_chromeos': standard_tests + [
1284 'app_list_unittests',
1285 'aura_unittests',
1286 'ash_unittests',
1287 'chromeos_unittests',
1288 'components_unittests',
1289 'dbus_unittests',
1290 'device_unittests',
1291 'events_unittests',
1292 'google_apis_unittests',
1293 'sandbox_linux_unittests',
1294 ],
[email protected]23c81d552014-01-07 13:45:461295 'linux_chromium_dbg': ['defaulttests'],
1296 'linux_chromium_rel': ['defaulttests'],
[email protected]38c6a512013-12-18 23:48:011297 'linux_clang': ['compile'],
[email protected]9780bac2014-01-11 00:12:021298 'linux_nacl_sdk_build': ['compile'],
[email protected]38c6a512013-12-18 23:48:011299 'linux_rel': standard_tests + [
1300 'cc_unittests',
[email protected]5d0413fc2014-01-03 18:24:301301 'chromedriver_unittests',
[email protected]38c6a512013-12-18 23:48:011302 'components_unittests',
1303 'google_apis_unittests',
1304 'nacl_integration',
1305 'remoting_unittests',
1306 'sandbox_linux_unittests',
1307 'sync_integration_tests',
[email protected]9021a5f72014-01-24 19:02:381308 'telemetry_perf_unittests',
1309 'telemetry_unittests',
[email protected]38c6a512013-12-18 23:48:011310 ],
1311 'mac': ['compile'],
[email protected]23c81d552014-01-07 13:45:461312 'mac_chromium_dbg': ['defaulttests'],
1313 'mac_chromium_rel': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021314 'mac_nacl_sdk_build': ['compile'],
[email protected]38c6a512013-12-18 23:48:011315 'mac_rel': standard_tests + [
1316 'app_list_unittests',
1317 'cc_unittests',
[email protected]5d0413fc2014-01-03 18:24:301318 'chromedriver_unittests',
[email protected]38c6a512013-12-18 23:48:011319 'components_unittests',
1320 'google_apis_unittests',
1321 'message_center_unittests',
1322 'nacl_integration',
1323 'remoting_unittests',
1324 'sync_integration_tests',
[email protected]9021a5f72014-01-24 19:02:381325 'telemetry_perf_unittests',
[email protected]38c6a512013-12-18 23:48:011326 'telemetry_unittests',
1327 ],
1328 'win': ['compile'],
[email protected]9780bac2014-01-11 00:12:021329 'win_nacl_sdk_build': ['compile'],
[email protected]38c6a512013-12-18 23:48:011330 'win_rel': standard_tests + [
1331 'app_list_unittests',
1332 'ash_unittests',
1333 'aura_unittests',
1334 'cc_unittests',
1335 'chrome_elf_unittests',
[email protected]5d0413fc2014-01-03 18:24:301336 'chromedriver_unittests',
[email protected]38c6a512013-12-18 23:48:011337 'components_unittests',
1338 'compositor_unittests',
1339 'events_unittests',
1340 'google_apis_unittests',
1341 'installer_util_unittests',
1342 'mini_installer_test',
1343 'nacl_integration',
1344 'remoting_unittests',
1345 'sync_integration_tests',
[email protected]9021a5f72014-01-24 19:02:381346 'telemetry_perf_unittests',
[email protected]38c6a512013-12-18 23:48:011347 'telemetry_unittests',
1348 'views_unittests',
1349 ],
1350 'win_x64_rel': [
1351 'base_unittests',
1352 ],
1353 }
1354
1355 swarm_enabled_builders = (
1356 'linux_rel',
1357 'mac_rel',
1358 'win_rel',
1359 )
1360
1361 swarm_enabled_tests = (
1362 'base_unittests',
1363 'browser_tests',
1364 'interactive_ui_tests',
1365 'net_unittests',
1366 'unit_tests',
1367 )
1368
1369 for bot in builders_and_tests:
1370 if bot in swarm_enabled_builders:
1371 builders_and_tests[bot] = [x + '_swarm' if x in swarm_enabled_tests else x
1372 for x in builders_and_tests[bot]]
1373
1374 if bots:
1375 return [(bot, set(builders_and_tests[bot])) for bot in bots]
1376 else:
1377 return [(bot, set(tests)) for bot, tests in builders_and_tests.iteritems()]
1378
1379
[email protected]ca8d1982009-02-19 16:33:121380def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:541381 results = []
[email protected]1f7b4172010-01-28 01:17:341382 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:511383 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1384 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1385 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:541386 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:271387 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:341388 input_api,
1389 output_api,
[email protected]2fdd1f362013-01-16 03:56:031390 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:271391 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
[email protected]2fdd1f362013-01-16 03:56:031392 output_api, 'http://codereview.chromium.org',
[email protected]c1ba4c52012-03-09 14:23:281393 ('win_rel', 'linux_rel', 'mac_rel, win:compile'),
1394 '[email protected]'))
[email protected]806e98e2010-03-19 17:49:271395
[email protected]3e4eb112011-01-18 03:29:541396 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1397 input_api, output_api))
[email protected]c4b47562011-12-05 23:39:411398 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1399 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:051400 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541401 return results
[email protected]ca8d1982009-02-19 16:33:121402
1403
[email protected]5efb2a822011-09-27 23:06:131404def GetPreferredTrySlaves(project, change):
[email protected]4ce995ea2012-06-27 02:13:101405 files = change.LocalPaths()
1406
[email protected]751b05f2013-01-10 23:12:171407 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
[email protected]3019c902012-06-29 00:09:031408 return []
1409
[email protected]d668899a2012-09-06 18:16:591410 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011411 return GetDefaultTryConfigs(['mac', 'mac_rel'])
[email protected]d668899a2012-09-06 18:16:591412 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
[email protected]3630be892013-12-19 05:34:281413 return GetDefaultTryConfigs(['win', 'win_rel'])
[email protected]d668899a2012-09-06 18:16:591414 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011415 return GetDefaultTryConfigs([
1416 'android_aosp',
1417 'android_clang_dbg',
1418 'android_dbg',
1419 ])
[email protected]de142152012-10-03 23:02:451420 if all(re.search('[/_]ios[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011421 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
[email protected]4ce995ea2012-06-27 02:13:101422
[email protected]38c6a512013-12-18 23:48:011423 trybots = GetDefaultTryConfigs([
[email protected]3e2f0402012-11-02 16:28:011424 'android_clang_dbg',
1425 'android_dbg',
1426 'ios_dbg_simulator',
1427 'ios_rel_device',
[email protected]95c989162012-11-29 05:58:251428 'linux_aura',
[email protected]38c6a512013-12-18 23:48:011429 'linux_asan',
[email protected]3e2f0402012-11-02 16:28:011430 'linux_chromeos',
[email protected]38c6a512013-12-18 23:48:011431 'linux_clang',
[email protected]3056a392014-01-23 20:17:191432 'linux_nacl_sdk_build',
[email protected]3e2f0402012-11-02 16:28:011433 'linux_rel',
[email protected]38c6a512013-12-18 23:48:011434 'mac',
[email protected]9780bac2014-01-11 00:12:021435 'mac_nacl_sdk_build',
[email protected]3e2f0402012-11-02 16:28:011436 'mac_rel',
[email protected]38c6a512013-12-18 23:48:011437 'win',
[email protected]9780bac2014-01-11 00:12:021438 'win_nacl_sdk_build',
[email protected]3e2f0402012-11-02 16:28:011439 'win_rel',
[email protected]38c6a512013-12-18 23:48:011440 'win_x64_rel',
1441 ])
[email protected]911753b2012-08-02 12:11:541442
1443 # Match things like path/aura/file.cc and path/file_aura.cc.
[email protected]95c989162012-11-29 05:58:251444 # Same for chromeos.
1445 if any(re.search('[/_](aura|chromeos)', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011446 trybots.extend(GetDefaultTryConfigs([
1447 'linux_chromeos_asan', 'linux_chromeos_clang']))
[email protected]4ce995ea2012-06-27 02:13:101448
[email protected]e8df48f2013-09-30 20:07:541449 # If there are gyp changes to base, build, or chromeos, run a full cros build
1450 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1451 # files have a much higher chance of breaking the cros build, which is
1452 # differnt from the linux_chromeos build that most chrome developers test
1453 # with.
1454 if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011455 trybots.extend(GetDefaultTryConfigs(['cros_x86']))
[email protected]e8df48f2013-09-30 20:07:541456
[email protected]d95948ef2013-07-02 10:51:001457 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1458 # unless they're .gyp(i) files as changes to those files can break the gyp
1459 # step on that bot.
1460 if (not all(re.search('^chrome', f) for f in files) or
1461 any(re.search('\.gypi?$', f) for f in files)):
[email protected]38c6a512013-12-18 23:48:011462 trybots.extend(GetDefaultTryConfigs(['android_aosp']))
[email protected]d95948ef2013-07-02 10:51:001463
[email protected]4ce995ea2012-06-27 02:13:101464 return trybots