blob: c847096e7f82e919228ec8a2e4a3231fb9270763 [file] [log] [blame]
[email protected]a18130a2012-01-03 17:52:081# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ca8d1982009-02-19 16:33:122# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Top-level presubmit script for Chromium.
6
[email protected]f1293792009-07-31 18:09:567See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
[email protected]50d7d721e2009-11-15 17:56:188for more details about the presubmit API built into gcl.
[email protected]ca8d1982009-02-19 16:33:129"""
10
[email protected]eea609a2011-11-18 13:10:1211
[email protected]9d16ad12011-12-14 20:49:4712import re
[email protected]55f9f382012-07-31 11:02:1813import sys
[email protected]9d16ad12011-12-14 20:49:4714
15
[email protected]379e7dd2010-01-28 17:39:2116_EXCLUDED_PATHS = (
[email protected]3e4eb112011-01-18 03:29:5417 r"^breakpad[\\\/].*",
[email protected]40d1dbb2012-10-26 07:18:0018 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
19 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
[email protected]8886ffcb2013-02-12 04:56:2820 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
[email protected]a18130a2012-01-03 17:52:0821 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
[email protected]3e4eb112011-01-18 03:29:5422 r"^skia[\\\/].*",
23 r"^v8[\\\/].*",
24 r".*MakeFile$",
[email protected]1084ccc2012-03-14 03:22:5325 r".+_autogen\.h$",
[email protected]ce145c02012-09-06 09:49:3426 r".+[\\\/]pnacl_shim\.c$",
[email protected]e07b6ac72013-08-20 00:30:4227 r"^gpu[\\\/]config[\\\/].*_list_json\.cc$",
[email protected]d2600602014-02-19 00:09:1928 r"^chrome[\\\/]browser[\\\/]resources[\\\/]pdf[\\\/]index.js"
[email protected]4306417642009-06-11 00:33:4029)
[email protected]ca8d1982009-02-19 16:33:1230
[email protected]de28fed2e2014-02-01 14:36:3231# TestRunner and NetscapePlugIn library is temporarily excluded from pan-project
32# checks until it's transitioned to chromium coding style.
[email protected]3de922f2013-12-20 13:27:3833_TESTRUNNER_PATHS = (
34 r"^content[\\\/]shell[\\\/]renderer[\\\/]test_runner[\\\/].*",
35 r"^content[\\\/]shell[\\\/]common[\\\/]test_runner[\\\/].*",
[email protected]de28fed2e2014-02-01 14:36:3236 r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*",
[email protected]3de922f2013-12-20 13:27:3837)
38
[email protected]06e6d0ff2012-12-11 01:36:4439# Fragment of a regular expression that matches C++ and Objective-C++
40# implementation files.
41_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
42
43# Regular expression that matches code only used for test binaries
44# (best effort).
45_TEST_CODE_EXCLUDED_PATHS = (
46 r'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
47 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
[email protected]6e04f8c2014-01-29 18:08:3248 r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
[email protected]e2d7e6f2013-04-23 12:57:1249 _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4450 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
51 r'.*[/\\](test|tool(s)?)[/\\].*',
[email protected]ef070cc2013-05-03 11:53:0552 # content_shell is used for running layout tests.
53 r'content[/\\]shell[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4454 # At request of folks maintaining this folder.
55 r'chrome[/\\]browser[/\\]automation[/\\].*',
[email protected]7b054982013-11-27 00:44:4756 # Non-production example code.
57 r'mojo[/\\]examples[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4458)
[email protected]ca8d1982009-02-19 16:33:1259
[email protected]eea609a2011-11-18 13:10:1260_TEST_ONLY_WARNING = (
61 'You might be calling functions intended only for testing from\n'
62 'production code. It is OK to ignore this warning if you know what\n'
63 'you are doing, as the heuristics used to detect the situation are\n'
64 'not perfect. The commit queue will not block on this warning.\n'
65 'Email [email protected] if you have questions.')
66
67
[email protected]cf9b78f2012-11-14 11:40:2868_INCLUDE_ORDER_WARNING = (
69 'Your #include order seems to be broken. Send mail to\n'
70 '[email protected] if this is not the case.')
71
72
[email protected]127f18ec2012-06-16 05:05:5973_BANNED_OBJC_FUNCTIONS = (
74 (
75 'addTrackingRect:',
[email protected]23e6cbc2012-06-16 18:51:2076 (
77 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
[email protected]127f18ec2012-06-16 05:05:5978 'prohibited. Please use CrTrackingArea instead.',
79 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
80 ),
81 False,
82 ),
83 (
84 'NSTrackingArea',
[email protected]23e6cbc2012-06-16 18:51:2085 (
86 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
[email protected]127f18ec2012-06-16 05:05:5987 'instead.',
88 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
89 ),
90 False,
91 ),
92 (
93 'convertPointFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2094 (
95 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5996 'Please use |convertPoint:(point) fromView:nil| instead.',
97 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
98 ),
99 True,
100 ),
101 (
102 'convertPointToBase:',
[email protected]23e6cbc2012-06-16 18:51:20103 (
104 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59105 'Please use |convertPoint:(point) toView:nil| instead.',
106 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
107 ),
108 True,
109 ),
110 (
111 'convertRectFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20112 (
113 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59114 'Please use |convertRect:(point) fromView:nil| instead.',
115 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
116 ),
117 True,
118 ),
119 (
120 'convertRectToBase:',
[email protected]23e6cbc2012-06-16 18:51:20121 (
122 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59123 'Please use |convertRect:(point) toView:nil| instead.',
124 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
125 ),
126 True,
127 ),
128 (
129 'convertSizeFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20130 (
131 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59132 'Please use |convertSize:(point) fromView:nil| instead.',
133 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
134 ),
135 True,
136 ),
137 (
138 'convertSizeToBase:',
[email protected]23e6cbc2012-06-16 18:51:20139 (
140 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59141 'Please use |convertSize:(point) toView:nil| instead.',
142 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
143 ),
144 True,
145 ),
146)
147
148
149_BANNED_CPP_FUNCTIONS = (
[email protected]23e6cbc2012-06-16 18:51:20150 # Make sure that gtest's FRIEND_TEST() macro is not used; the
151 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
[email protected]e00ccc92012-11-01 17:32:30152 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
[email protected]23e6cbc2012-06-16 18:51:20153 (
154 'FRIEND_TEST(',
155 (
[email protected]e3c945502012-06-26 20:01:49156 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
[email protected]23e6cbc2012-06-16 18:51:20157 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
158 ),
159 False,
[email protected]7345da02012-11-27 14:31:49160 (),
[email protected]23e6cbc2012-06-16 18:51:20161 ),
162 (
163 'ScopedAllowIO',
164 (
[email protected]e3c945502012-06-26 20:01:49165 'New code should not use ScopedAllowIO. Post a task to the blocking',
166 'pool or the FILE thread instead.',
[email protected]23e6cbc2012-06-16 18:51:20167 ),
[email protected]e3c945502012-06-26 20:01:49168 True,
[email protected]7345da02012-11-27 14:31:49169 (
[email protected]0b818f72013-10-22 00:11:03170 r"^components[\\\/]breakpad[\\\/]app[\\\/]breakpad_mac\.mm$",
[email protected]de7d61ff2013-08-20 11:30:41171 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
172 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
[email protected]398ad132013-04-02 15:11:01173 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
[email protected]7345da02012-11-27 14:31:49174 ),
[email protected]23e6cbc2012-06-16 18:51:20175 ),
[email protected]52657f62013-05-20 05:30:31176 (
177 'SkRefPtr',
178 (
179 'The use of SkRefPtr is prohibited. ',
180 'Please use skia::RefPtr instead.'
181 ),
182 True,
183 (),
184 ),
185 (
186 'SkAutoRef',
187 (
188 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
189 'Please use skia::RefPtr instead.'
190 ),
191 True,
192 (),
193 ),
194 (
195 'SkAutoTUnref',
196 (
197 'The use of SkAutoTUnref is dangerous because it implicitly ',
198 'converts to a raw pointer. Please use skia::RefPtr instead.'
199 ),
200 True,
201 (),
202 ),
203 (
204 'SkAutoUnref',
205 (
206 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
207 'because it implicitly converts to a raw pointer. ',
208 'Please use skia::RefPtr instead.'
209 ),
210 True,
211 (),
212 ),
[email protected]d89eec82013-12-03 14:10:59213 (
214 r'/HANDLE_EINTR\(.*close',
215 (
216 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
217 'descriptor will be closed, and it is incorrect to retry the close.',
218 'Either call close directly and ignore its return value, or wrap close',
219 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
220 ),
221 True,
222 (),
223 ),
224 (
225 r'/IGNORE_EINTR\((?!.*close)',
226 (
227 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
228 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
229 ),
230 True,
231 (
232 # Files that #define IGNORE_EINTR.
233 r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
234 r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
235 ),
236 ),
[email protected]127f18ec2012-06-16 05:05:59237)
238
239
[email protected]b00342e7f2013-03-26 16:21:54240_VALID_OS_MACROS = (
241 # Please keep sorted.
242 'OS_ANDROID',
[email protected]f4440b42014-03-19 05:47:01243 'OS_ANDROID_HOST',
[email protected]b00342e7f2013-03-26 16:21:54244 'OS_BSD',
245 'OS_CAT', # For testing.
246 'OS_CHROMEOS',
247 'OS_FREEBSD',
248 'OS_IOS',
249 'OS_LINUX',
250 'OS_MACOSX',
251 'OS_NACL',
252 'OS_OPENBSD',
253 'OS_POSIX',
[email protected]eda7afa12014-02-06 12:27:37254 'OS_QNX',
[email protected]b00342e7f2013-03-26 16:21:54255 'OS_SOLARIS',
[email protected]b00342e7f2013-03-26 16:21:54256 'OS_WIN',
257)
258
259
[email protected]55459852011-08-10 15:17:19260def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
261 """Attempts to prevent use of functions intended only for testing in
262 non-testing code. For now this is just a best-effort implementation
263 that ignores header files and may have some false positives. A
264 better implementation would probably need a proper C++ parser.
265 """
266 # We only scan .cc files and the like, as the declaration of
267 # for-testing functions in header files are hard to distinguish from
268 # calls to such functions without a proper C++ parser.
[email protected]06e6d0ff2012-12-11 01:36:44269 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
[email protected]55459852011-08-10 15:17:19270
271 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
272 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
[email protected]de4f7d22013-05-23 14:27:46273 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
[email protected]55459852011-08-10 15:17:19274 exclusion_pattern = input_api.re.compile(
275 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
276 base_function_pattern, base_function_pattern))
277
278 def FilterFile(affected_file):
[email protected]06e6d0ff2012-12-11 01:36:44279 black_list = (_EXCLUDED_PATHS +
280 _TEST_CODE_EXCLUDED_PATHS +
281 input_api.DEFAULT_BLACK_LIST)
[email protected]55459852011-08-10 15:17:19282 return input_api.FilterSourceFile(
283 affected_file,
284 white_list=(file_inclusion_pattern, ),
285 black_list=black_list)
286
287 problems = []
288 for f in input_api.AffectedSourceFiles(FilterFile):
289 local_path = f.LocalPath()
[email protected]825d27182014-01-02 21:24:24290 for line_number, line in f.ChangedContents():
[email protected]2fdd1f362013-01-16 03:56:03291 if (inclusion_pattern.search(line) and
[email protected]de4f7d22013-05-23 14:27:46292 not comment_pattern.search(line) and
[email protected]2fdd1f362013-01-16 03:56:03293 not exclusion_pattern.search(line)):
[email protected]55459852011-08-10 15:17:19294 problems.append(
[email protected]2fdd1f362013-01-16 03:56:03295 '%s:%d\n %s' % (local_path, line_number, line.strip()))
[email protected]55459852011-08-10 15:17:19296
297 if problems:
[email protected]f7051d52013-04-02 18:31:42298 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
[email protected]2fdd1f362013-01-16 03:56:03299 else:
300 return []
[email protected]55459852011-08-10 15:17:19301
302
[email protected]10689ca2011-09-02 02:31:54303def _CheckNoIOStreamInHeaders(input_api, output_api):
304 """Checks to make sure no .h files include <iostream>."""
305 files = []
306 pattern = input_api.re.compile(r'^#include\s*<iostream>',
307 input_api.re.MULTILINE)
308 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
309 if not f.LocalPath().endswith('.h'):
310 continue
311 contents = input_api.ReadFile(f)
312 if pattern.search(contents):
313 files.append(f)
314
315 if len(files):
316 return [ output_api.PresubmitError(
[email protected]6c063c62012-07-11 19:11:06317 'Do not #include <iostream> in header files, since it inserts static '
318 'initialization into every file including the header. Instead, '
[email protected]10689ca2011-09-02 02:31:54319 '#include <ostream>. See http://crbug.com/94794',
320 files) ]
321 return []
322
323
[email protected]72df4e782012-06-21 16:28:18324def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
325 """Checks to make sure no source files use UNIT_TEST"""
326 problems = []
327 for f in input_api.AffectedFiles():
328 if (not f.LocalPath().endswith(('.cc', '.mm'))):
329 continue
330
331 for line_num, line in f.ChangedContents():
[email protected]549f86a2013-11-19 13:00:04332 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
[email protected]72df4e782012-06-21 16:28:18333 problems.append(' %s:%d' % (f.LocalPath(), line_num))
334
335 if not problems:
336 return []
337 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
338 '\n'.join(problems))]
339
340
[email protected]8ea5d4b2011-09-13 21:49:22341def _CheckNoNewWStrings(input_api, output_api):
342 """Checks to make sure we don't introduce use of wstrings."""
[email protected]55463aa62011-10-12 00:48:27343 problems = []
[email protected]8ea5d4b2011-09-13 21:49:22344 for f in input_api.AffectedFiles():
[email protected]b5c24292011-11-28 14:38:20345 if (not f.LocalPath().endswith(('.cc', '.h')) or
[email protected]24be83c2013-08-29 23:01:23346 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
[email protected]b5c24292011-11-28 14:38:20347 continue
[email protected]8ea5d4b2011-09-13 21:49:22348
[email protected]a11dbe9b2012-08-07 01:32:58349 allowWString = False
[email protected]b5c24292011-11-28 14:38:20350 for line_num, line in f.ChangedContents():
[email protected]a11dbe9b2012-08-07 01:32:58351 if 'presubmit: allow wstring' in line:
352 allowWString = True
353 elif not allowWString and 'wstring' in line:
[email protected]55463aa62011-10-12 00:48:27354 problems.append(' %s:%d' % (f.LocalPath(), line_num))
[email protected]a11dbe9b2012-08-07 01:32:58355 allowWString = False
356 else:
357 allowWString = False
[email protected]8ea5d4b2011-09-13 21:49:22358
[email protected]55463aa62011-10-12 00:48:27359 if not problems:
360 return []
361 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
[email protected]a11dbe9b2012-08-07 01:32:58362 ' If you are calling a cross-platform API that accepts a wstring, '
363 'fix the API.\n' +
[email protected]55463aa62011-10-12 00:48:27364 '\n'.join(problems))]
[email protected]8ea5d4b2011-09-13 21:49:22365
366
[email protected]2a8ac9c2011-10-19 17:20:44367def _CheckNoDEPSGIT(input_api, output_api):
368 """Make sure .DEPS.git is never modified manually."""
369 if any(f.LocalPath().endswith('.DEPS.git') for f in
370 input_api.AffectedFiles()):
371 return [output_api.PresubmitError(
372 'Never commit changes to .DEPS.git. This file is maintained by an\n'
373 'automated system based on what\'s in DEPS and your changes will be\n'
374 'overwritten.\n'
375 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
376 'for more information')]
377 return []
378
379
[email protected]127f18ec2012-06-16 05:05:59380def _CheckNoBannedFunctions(input_api, output_api):
381 """Make sure that banned functions are not used."""
382 warnings = []
383 errors = []
384
385 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
386 for f in input_api.AffectedFiles(file_filter=file_filter):
387 for line_num, line in f.ChangedContents():
388 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
389 if func_name in line:
390 problems = warnings;
391 if error:
392 problems = errors;
393 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
394 for message_line in message:
395 problems.append(' %s' % message_line)
396
397 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
398 for f in input_api.AffectedFiles(file_filter=file_filter):
399 for line_num, line in f.ChangedContents():
[email protected]7345da02012-11-27 14:31:49400 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
401 def IsBlacklisted(affected_file, blacklist):
402 local_path = affected_file.LocalPath()
403 for item in blacklist:
404 if input_api.re.match(item, local_path):
405 return True
406 return False
407 if IsBlacklisted(f, excluded_paths):
408 continue
[email protected]d89eec82013-12-03 14:10:59409 matched = False
410 if func_name[0:1] == '/':
411 regex = func_name[1:]
412 if input_api.re.search(regex, line):
413 matched = True
414 elif func_name in line:
415 matched = True
416 if matched:
[email protected]127f18ec2012-06-16 05:05:59417 problems = warnings;
418 if error:
419 problems = errors;
420 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
421 for message_line in message:
422 problems.append(' %s' % message_line)
423
424 result = []
425 if (warnings):
426 result.append(output_api.PresubmitPromptWarning(
427 'Banned functions were used.\n' + '\n'.join(warnings)))
428 if (errors):
429 result.append(output_api.PresubmitError(
430 'Banned functions were used.\n' + '\n'.join(errors)))
431 return result
432
433
[email protected]6c063c62012-07-11 19:11:06434def _CheckNoPragmaOnce(input_api, output_api):
435 """Make sure that banned functions are not used."""
436 files = []
437 pattern = input_api.re.compile(r'^#pragma\s+once',
438 input_api.re.MULTILINE)
439 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
440 if not f.LocalPath().endswith('.h'):
441 continue
442 contents = input_api.ReadFile(f)
443 if pattern.search(contents):
444 files.append(f)
445
446 if files:
447 return [output_api.PresubmitError(
448 'Do not use #pragma once in header files.\n'
449 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
450 files)]
451 return []
452
[email protected]127f18ec2012-06-16 05:05:59453
[email protected]e7479052012-09-19 00:26:12454def _CheckNoTrinaryTrueFalse(input_api, output_api):
455 """Checks to make sure we don't introduce use of foo ? true : false."""
456 problems = []
457 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
458 for f in input_api.AffectedFiles():
459 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
460 continue
461
462 for line_num, line in f.ChangedContents():
463 if pattern.match(line):
464 problems.append(' %s:%d' % (f.LocalPath(), line_num))
465
466 if not problems:
467 return []
468 return [output_api.PresubmitPromptWarning(
469 'Please consider avoiding the "? true : false" pattern if possible.\n' +
470 '\n'.join(problems))]
471
472
[email protected]55f9f382012-07-31 11:02:18473def _CheckUnwantedDependencies(input_api, output_api):
474 """Runs checkdeps on #include statements added in this
475 change. Breaking - rules is an error, breaking ! rules is a
476 warning.
477 """
478 # We need to wait until we have an input_api object and use this
479 # roundabout construct to import checkdeps because this file is
480 # eval-ed and thus doesn't have __file__.
481 original_sys_path = sys.path
482 try:
483 sys.path = sys.path + [input_api.os_path.join(
484 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
485 import checkdeps
486 from cpp_checker import CppChecker
487 from rules import Rule
488 finally:
489 # Restore sys.path to what it was before.
490 sys.path = original_sys_path
491
492 added_includes = []
493 for f in input_api.AffectedFiles():
494 if not CppChecker.IsCppFile(f.LocalPath()):
495 continue
496
497 changed_lines = [line for line_num, line in f.ChangedContents()]
498 added_includes.append([f.LocalPath(), changed_lines])
499
[email protected]26385172013-05-09 23:11:35500 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
[email protected]55f9f382012-07-31 11:02:18501
502 error_descriptions = []
503 warning_descriptions = []
504 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
505 added_includes):
506 description_with_path = '%s\n %s' % (path, rule_description)
507 if rule_type == Rule.DISALLOW:
508 error_descriptions.append(description_with_path)
509 else:
510 warning_descriptions.append(description_with_path)
511
512 results = []
513 if error_descriptions:
514 results.append(output_api.PresubmitError(
515 'You added one or more #includes that violate checkdeps rules.',
516 error_descriptions))
517 if warning_descriptions:
[email protected]f7051d52013-04-02 18:31:42518 results.append(output_api.PresubmitPromptOrNotify(
[email protected]55f9f382012-07-31 11:02:18519 'You added one or more #includes of files that are temporarily\n'
520 'allowed but being removed. Can you avoid introducing the\n'
521 '#include? See relevant DEPS file(s) for details and contacts.',
522 warning_descriptions))
523 return results
524
525
[email protected]fbcafe5a2012-08-08 15:31:22526def _CheckFilePermissions(input_api, output_api):
527 """Check that all files have their permissions properly set."""
[email protected]791507202014-02-03 23:19:15528 if input_api.platform == 'win32':
529 return []
[email protected]fbcafe5a2012-08-08 15:31:22530 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
531 input_api.change.RepositoryRoot()]
532 for f in input_api.AffectedFiles():
533 args += ['--file', f.LocalPath()]
[email protected]f0d330f2014-01-30 01:44:34534 checkperms = input_api.subprocess.Popen(args,
535 stdout=input_api.subprocess.PIPE)
536 errors = checkperms.communicate()[0].strip()
[email protected]fbcafe5a2012-08-08 15:31:22537 if errors:
[email protected]f0d330f2014-01-30 01:44:34538 return [output_api.PresubmitError('checkperms.py failed.',
539 errors.splitlines())]
540 return []
[email protected]fbcafe5a2012-08-08 15:31:22541
542
[email protected]c8278b32012-10-30 20:35:49543def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
544 """Makes sure we don't include ui/aura/window_property.h
545 in header files.
546 """
547 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
548 errors = []
549 for f in input_api.AffectedFiles():
550 if not f.LocalPath().endswith('.h'):
551 continue
552 for line_num, line in f.ChangedContents():
553 if pattern.match(line):
554 errors.append(' %s:%d' % (f.LocalPath(), line_num))
555
556 results = []
557 if errors:
558 results.append(output_api.PresubmitError(
559 'Header files should not include ui/aura/window_property.h', errors))
560 return results
561
562
[email protected]cf9b78f2012-11-14 11:40:28563def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
564 """Checks that the lines in scope occur in the right order.
565
566 1. C system files in alphabetical order
567 2. C++ system files in alphabetical order
568 3. Project's .h files
569 """
570
571 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
572 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
573 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
574
575 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
576
577 state = C_SYSTEM_INCLUDES
578
579 previous_line = ''
[email protected]728b9bb2012-11-14 20:38:57580 previous_line_num = 0
[email protected]cf9b78f2012-11-14 11:40:28581 problem_linenums = []
582 for line_num, line in scope:
583 if c_system_include_pattern.match(line):
584 if state != C_SYSTEM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57585 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28586 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57587 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28588 elif cpp_system_include_pattern.match(line):
589 if state == C_SYSTEM_INCLUDES:
590 state = CPP_SYSTEM_INCLUDES
591 elif state == CUSTOM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57592 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28593 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57594 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28595 elif custom_include_pattern.match(line):
596 if state != CUSTOM_INCLUDES:
597 state = CUSTOM_INCLUDES
598 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57599 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28600 else:
601 problem_linenums.append(line_num)
602 previous_line = line
[email protected]728b9bb2012-11-14 20:38:57603 previous_line_num = line_num
[email protected]cf9b78f2012-11-14 11:40:28604
605 warnings = []
[email protected]728b9bb2012-11-14 20:38:57606 for (line_num, previous_line_num) in problem_linenums:
607 if line_num in changed_linenums or previous_line_num in changed_linenums:
[email protected]cf9b78f2012-11-14 11:40:28608 warnings.append(' %s:%d' % (file_path, line_num))
609 return warnings
610
611
[email protected]ac294a12012-12-06 16:38:43612def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
[email protected]cf9b78f2012-11-14 11:40:28613 """Checks the #include order for the given file f."""
614
[email protected]2299dcf2012-11-15 19:56:24615 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
[email protected]23093b62013-09-20 12:16:30616 # Exclude the following includes from the check:
617 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
618 # specific order.
619 # 2) <atlbase.h>, "build/build_config.h"
620 excluded_include_pattern = input_api.re.compile(
621 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
[email protected]2299dcf2012-11-15 19:56:24622 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
[email protected]3e83618c2013-10-09 22:32:33623 # Match the final or penultimate token if it is xxxtest so we can ignore it
624 # when considering the special first include.
625 test_file_tag_pattern = input_api.re.compile(
626 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
[email protected]0e5c1852012-12-18 20:17:11627 if_pattern = input_api.re.compile(
628 r'\s*#\s*(if|elif|else|endif|define|undef).*')
629 # Some files need specialized order of includes; exclude such files from this
630 # check.
631 uncheckable_includes_pattern = input_api.re.compile(
632 r'\s*#include '
633 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
[email protected]cf9b78f2012-11-14 11:40:28634
635 contents = f.NewContents()
636 warnings = []
637 line_num = 0
638
[email protected]ac294a12012-12-06 16:38:43639 # Handle the special first include. If the first include file is
640 # some/path/file.h, the corresponding including file can be some/path/file.cc,
641 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
642 # etc. It's also possible that no special first include exists.
[email protected]3e83618c2013-10-09 22:32:33643 # If the included file is some/path/file_platform.h the including file could
644 # also be some/path/file_xxxtest_platform.h.
645 including_file_base_name = test_file_tag_pattern.sub(
646 '', input_api.os_path.basename(f.LocalPath()))
647
[email protected]ac294a12012-12-06 16:38:43648 for line in contents:
649 line_num += 1
650 if system_include_pattern.match(line):
651 # No special first include -> process the line again along with normal
652 # includes.
653 line_num -= 1
654 break
655 match = custom_include_pattern.match(line)
656 if match:
657 match_dict = match.groupdict()
[email protected]3e83618c2013-10-09 22:32:33658 header_basename = test_file_tag_pattern.sub(
659 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
660
661 if header_basename not in including_file_base_name:
[email protected]2299dcf2012-11-15 19:56:24662 # No special first include -> process the line again along with normal
663 # includes.
664 line_num -= 1
[email protected]ac294a12012-12-06 16:38:43665 break
[email protected]cf9b78f2012-11-14 11:40:28666
667 # Split into scopes: Each region between #if and #endif is its own scope.
668 scopes = []
669 current_scope = []
670 for line in contents[line_num:]:
671 line_num += 1
[email protected]0e5c1852012-12-18 20:17:11672 if uncheckable_includes_pattern.match(line):
[email protected]4436c9e2014-01-07 23:19:54673 continue
[email protected]2309b0fa02012-11-16 12:18:27674 if if_pattern.match(line):
[email protected]cf9b78f2012-11-14 11:40:28675 scopes.append(current_scope)
676 current_scope = []
[email protected]962f117e2012-11-22 18:11:56677 elif ((system_include_pattern.match(line) or
678 custom_include_pattern.match(line)) and
679 not excluded_include_pattern.match(line)):
[email protected]cf9b78f2012-11-14 11:40:28680 current_scope.append((line_num, line))
681 scopes.append(current_scope)
682
683 for scope in scopes:
684 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
685 changed_linenums))
686 return warnings
687
688
689def _CheckIncludeOrder(input_api, output_api):
690 """Checks that the #include order is correct.
691
692 1. The corresponding header for source files.
693 2. C system files in alphabetical order
694 3. C++ system files in alphabetical order
695 4. Project's .h files in alphabetical order
696
[email protected]ac294a12012-12-06 16:38:43697 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
698 these rules separately.
[email protected]cf9b78f2012-11-14 11:40:28699 """
700
701 warnings = []
702 for f in input_api.AffectedFiles():
[email protected]ac294a12012-12-06 16:38:43703 if f.LocalPath().endswith(('.cc', '.h')):
704 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
705 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
[email protected]cf9b78f2012-11-14 11:40:28706
707 results = []
708 if warnings:
[email protected]f7051d52013-04-02 18:31:42709 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
[email protected]120cf540d2012-12-10 17:55:53710 warnings))
[email protected]cf9b78f2012-11-14 11:40:28711 return results
712
713
[email protected]70ca77752012-11-20 03:45:03714def _CheckForVersionControlConflictsInFile(input_api, f):
715 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
716 errors = []
717 for line_num, line in f.ChangedContents():
718 if pattern.match(line):
719 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
720 return errors
721
722
723def _CheckForVersionControlConflicts(input_api, output_api):
724 """Usually this is not intentional and will cause a compile failure."""
725 errors = []
726 for f in input_api.AffectedFiles():
727 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
728
729 results = []
730 if errors:
731 results.append(output_api.PresubmitError(
732 'Version control conflict markers found, please resolve.', errors))
733 return results
734
735
[email protected]06e6d0ff2012-12-11 01:36:44736def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
737 def FilterFile(affected_file):
738 """Filter function for use with input_api.AffectedSourceFiles,
739 below. This filters out everything except non-test files from
740 top-level directories that generally speaking should not hard-code
741 service URLs (e.g. src/android_webview/, src/content/ and others).
742 """
743 return input_api.FilterSourceFile(
744 affected_file,
[email protected]78bb39d62012-12-11 15:11:56745 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
[email protected]06e6d0ff2012-12-11 01:36:44746 black_list=(_EXCLUDED_PATHS +
747 _TEST_CODE_EXCLUDED_PATHS +
748 input_api.DEFAULT_BLACK_LIST))
749
[email protected]de4f7d22013-05-23 14:27:46750 base_pattern = '"[^"]*google\.com[^"]*"'
751 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
752 pattern = input_api.re.compile(base_pattern)
[email protected]06e6d0ff2012-12-11 01:36:44753 problems = [] # items are (filename, line_number, line)
754 for f in input_api.AffectedSourceFiles(FilterFile):
755 for line_num, line in f.ChangedContents():
[email protected]de4f7d22013-05-23 14:27:46756 if not comment_pattern.search(line) and pattern.search(line):
[email protected]06e6d0ff2012-12-11 01:36:44757 problems.append((f.LocalPath(), line_num, line))
758
759 if problems:
[email protected]f7051d52013-04-02 18:31:42760 return [output_api.PresubmitPromptOrNotify(
[email protected]06e6d0ff2012-12-11 01:36:44761 'Most layers below src/chrome/ should not hardcode service URLs.\n'
762 'Are you sure this is correct? (Contact: [email protected])',
763 [' %s:%d: %s' % (
764 problem[0], problem[1], problem[2]) for problem in problems])]
[email protected]2fdd1f362013-01-16 03:56:03765 else:
766 return []
[email protected]06e6d0ff2012-12-11 01:36:44767
768
[email protected]d2530012013-01-25 16:39:27769def _CheckNoAbbreviationInPngFileName(input_api, output_api):
770 """Makes sure there are no abbreviations in the name of PNG files.
771 """
[email protected]4053a48e2013-01-25 21:43:04772 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
[email protected]d2530012013-01-25 16:39:27773 errors = []
774 for f in input_api.AffectedFiles(include_deletes=False):
775 if pattern.match(f.LocalPath()):
776 errors.append(' %s' % f.LocalPath())
777
778 results = []
779 if errors:
780 results.append(output_api.PresubmitError(
781 'The name of PNG files should not have abbreviations. \n'
782 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
783 'Contact [email protected] if you have questions.', errors))
784 return results
785
786
[email protected]14a6131c2014-01-08 01:15:41787def _FilesToCheckForIncomingDeps(re, changed_lines):
[email protected]f32e2d1e2013-07-26 21:39:08788 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
[email protected]14a6131c2014-01-08 01:15:41789 a set of DEPS entries that we should look up.
790
791 For a directory (rather than a specific filename) we fake a path to
792 a specific filename by adding /DEPS. This is chosen as a file that
793 will seldom or never be subject to per-file include_rules.
794 """
[email protected]2b438d62013-11-14 17:54:14795 # We ignore deps entries on auto-generated directories.
796 AUTO_GENERATED_DIRS = ['grit', 'jni']
[email protected]f32e2d1e2013-07-26 21:39:08797
798 # This pattern grabs the path without basename in the first
799 # parentheses, and the basename (if present) in the second. It
800 # relies on the simple heuristic that if there is a basename it will
801 # be a header file ending in ".h".
802 pattern = re.compile(
803 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
[email protected]2b438d62013-11-14 17:54:14804 results = set()
[email protected]f32e2d1e2013-07-26 21:39:08805 for changed_line in changed_lines:
806 m = pattern.match(changed_line)
807 if m:
808 path = m.group(1)
[email protected]2b438d62013-11-14 17:54:14809 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
[email protected]14a6131c2014-01-08 01:15:41810 if m.group(2):
811 results.add('%s%s' % (path, m.group(2)))
812 else:
813 results.add('%s/DEPS' % path)
[email protected]f32e2d1e2013-07-26 21:39:08814 return results
815
816
[email protected]e871964c2013-05-13 14:14:55817def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
818 """When a dependency prefixed with + is added to a DEPS file, we
819 want to make sure that the change is reviewed by an OWNER of the
820 target file or directory, to avoid layering violations from being
821 introduced. This check verifies that this happens.
822 """
823 changed_lines = set()
824 for f in input_api.AffectedFiles():
825 filename = input_api.os_path.basename(f.LocalPath())
826 if filename == 'DEPS':
827 changed_lines |= set(line.strip()
828 for line_num, line
829 in f.ChangedContents())
830 if not changed_lines:
831 return []
832
[email protected]14a6131c2014-01-08 01:15:41833 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
834 changed_lines)
[email protected]e871964c2013-05-13 14:14:55835 if not virtual_depended_on_files:
836 return []
837
838 if input_api.is_committing:
839 if input_api.tbr:
840 return [output_api.PresubmitNotifyResult(
841 '--tbr was specified, skipping OWNERS check for DEPS additions')]
842 if not input_api.change.issue:
843 return [output_api.PresubmitError(
844 "DEPS approval by OWNERS check failed: this change has "
845 "no Rietveld issue number, so we can't check it for approvals.")]
846 output = output_api.PresubmitError
847 else:
848 output = output_api.PresubmitNotifyResult
849
850 owners_db = input_api.owners_db
851 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
852 input_api,
853 owners_db.email_regexp,
854 approval_needed=input_api.is_committing)
855
856 owner_email = owner_email or input_api.change.author_email
857
[email protected]de4f7d22013-05-23 14:27:46858 reviewers_plus_owner = set(reviewers)
[email protected]e71c6082013-05-22 02:28:51859 if owner_email:
[email protected]de4f7d22013-05-23 14:27:46860 reviewers_plus_owner.add(owner_email)
[email protected]e871964c2013-05-13 14:14:55861 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
862 reviewers_plus_owner)
[email protected]14a6131c2014-01-08 01:15:41863
864 # We strip the /DEPS part that was added by
865 # _FilesToCheckForIncomingDeps to fake a path to a file in a
866 # directory.
867 def StripDeps(path):
868 start_deps = path.rfind('/DEPS')
869 if start_deps != -1:
870 return path[:start_deps]
871 else:
872 return path
873 unapproved_dependencies = ["'+%s'," % StripDeps(path)
[email protected]e871964c2013-05-13 14:14:55874 for path in missing_files]
875
876 if unapproved_dependencies:
877 output_list = [
[email protected]14a6131c2014-01-08 01:15:41878 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
[email protected]e871964c2013-05-13 14:14:55879 '\n '.join(sorted(unapproved_dependencies)))]
880 if not input_api.is_committing:
881 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
882 output_list.append(output(
883 'Suggested missing target path OWNERS:\n %s' %
884 '\n '.join(suggested_owners or [])))
885 return output_list
886
887 return []
888
889
[email protected]85218562013-11-22 07:41:40890def _CheckSpamLogging(input_api, output_api):
891 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
892 black_list = (_EXCLUDED_PATHS +
893 _TEST_CODE_EXCLUDED_PATHS +
894 input_api.DEFAULT_BLACK_LIST +
[email protected]6f742dd02013-11-26 23:19:50895 (r"^base[\\\/]logging\.h$",
[email protected]80f360a2014-01-23 01:36:19896 r"^base[\\\/]logging\.cc$",
[email protected]b3643872014-02-11 23:29:39897 r"^cloud_print[\\\/]",
[email protected]c80b35022014-03-03 17:01:41898 r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
[email protected]8dc338c2013-12-09 16:28:48899 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
[email protected]6e268db2013-12-04 01:41:46900 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
[email protected]4de75262013-12-18 23:16:12901 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
902 r"startup_browser_creator\.cc$",
[email protected]fe0e6e12013-12-04 05:52:58903 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
[email protected]95c6b3012013-12-02 14:30:31904 r"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
[email protected]6e268db2013-12-04 01:41:46905 r"logging_native_handler\.cc$",
[email protected]9056e732014-01-08 06:25:25906 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
907 r"gl_helper_benchmark\.cc$",
[email protected]cdbdced2013-11-27 21:35:50908 r"^remoting[\\\/]base[\\\/]logging\.h$",
[email protected]67c96ab2013-12-17 02:05:36909 r"^remoting[\\\/]host[\\\/].*",
[email protected]8232f8fd2013-12-14 00:52:31910 r"^sandbox[\\\/]linux[\\\/].*",
[email protected]0b7a21e2014-02-11 18:38:13911 r"^tools[\\\/]",
[email protected]8232f8fd2013-12-14 00:52:31912 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
[email protected]85218562013-11-22 07:41:40913 source_file_filter = lambda x: input_api.FilterSourceFile(
914 x, white_list=(file_inclusion_pattern,), black_list=black_list)
915
916 log_info = []
917 printf = []
918
919 for f in input_api.AffectedSourceFiles(source_file_filter):
920 contents = input_api.ReadFile(f, 'rb')
921 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
922 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37923 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
[email protected]85210652013-11-28 05:50:13924 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37925
926 if re.search(r"\bprintf\(", contents):
927 printf.append(f.LocalPath())
928 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
[email protected]85218562013-11-22 07:41:40929 printf.append(f.LocalPath())
930
931 if log_info:
932 return [output_api.PresubmitError(
933 'These files spam the console log with LOG(INFO):',
934 items=log_info)]
935 if printf:
936 return [output_api.PresubmitError(
937 'These files spam the console log with printf/fprintf:',
938 items=printf)]
939 return []
940
941
[email protected]49aa76a2013-12-04 06:59:16942def _CheckForAnonymousVariables(input_api, output_api):
943 """These types are all expected to hold locks while in scope and
944 so should never be anonymous (which causes them to be immediately
945 destroyed)."""
946 they_who_must_be_named = [
947 'base::AutoLock',
948 'base::AutoReset',
949 'base::AutoUnlock',
950 'SkAutoAlphaRestore',
951 'SkAutoBitmapShaderInstall',
952 'SkAutoBlitterChoose',
953 'SkAutoBounderCommit',
954 'SkAutoCallProc',
955 'SkAutoCanvasRestore',
956 'SkAutoCommentBlock',
957 'SkAutoDescriptor',
958 'SkAutoDisableDirectionCheck',
959 'SkAutoDisableOvalCheck',
960 'SkAutoFree',
961 'SkAutoGlyphCache',
962 'SkAutoHDC',
963 'SkAutoLockColors',
964 'SkAutoLockPixels',
965 'SkAutoMalloc',
966 'SkAutoMaskFreeImage',
967 'SkAutoMutexAcquire',
968 'SkAutoPathBoundsUpdate',
969 'SkAutoPDFRelease',
970 'SkAutoRasterClipValidate',
971 'SkAutoRef',
972 'SkAutoTime',
973 'SkAutoTrace',
974 'SkAutoUnref',
975 ]
976 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
977 # bad: base::AutoLock(lock.get());
978 # not bad: base::AutoLock lock(lock.get());
979 bad_pattern = input_api.re.compile(anonymous)
980 # good: new base::AutoLock(lock.get())
981 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
982 errors = []
983
984 for f in input_api.AffectedFiles():
985 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
986 continue
987 for linenum, line in f.ChangedContents():
988 if bad_pattern.search(line) and not good_pattern.search(line):
989 errors.append('%s:%d' % (f.LocalPath(), linenum))
990
991 if errors:
992 return [output_api.PresubmitError(
993 'These lines create anonymous variables that need to be named:',
994 items=errors)]
995 return []
996
997
[email protected]5fe0f8742013-11-29 01:04:59998def _CheckCygwinShell(input_api, output_api):
999 source_file_filter = lambda x: input_api.FilterSourceFile(
1000 x, white_list=(r'.+\.(gyp|gypi)$',))
1001 cygwin_shell = []
1002
1003 for f in input_api.AffectedSourceFiles(source_file_filter):
1004 for linenum, line in f.ChangedContents():
1005 if 'msvs_cygwin_shell' in line:
1006 cygwin_shell.append(f.LocalPath())
1007 break
1008
1009 if cygwin_shell:
1010 return [output_api.PresubmitError(
1011 'These files should not use msvs_cygwin_shell (the default is 0):',
1012 items=cygwin_shell)]
1013 return []
1014
[email protected]85218562013-11-22 07:41:401015
[email protected]999261d2014-03-03 20:08:081016def _CheckUserActionUpdate(input_api, output_api):
1017 """Checks if any new user action has been added."""
[email protected]2f92dec2014-03-07 19:21:521018 if any('actions.xml' == input_api.os_path.basename(f) for f in
[email protected]999261d2014-03-03 20:08:081019 input_api.LocalPaths()):
[email protected]2f92dec2014-03-07 19:21:521020 # If actions.xml is already included in the changelist, the PRESUBMIT
1021 # for actions.xml will do a more complete presubmit check.
[email protected]999261d2014-03-03 20:08:081022 return []
1023
[email protected]999261d2014-03-03 20:08:081024 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm'))
1025 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)'
[email protected]2f92dec2014-03-07 19:21:521026 current_actions = None
[email protected]999261d2014-03-03 20:08:081027 for f in input_api.AffectedFiles(file_filter=file_filter):
1028 for line_num, line in f.ChangedContents():
1029 match = input_api.re.search(action_re, line)
1030 if match:
[email protected]2f92dec2014-03-07 19:21:521031 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1032 # loaded only once.
1033 if not current_actions:
1034 with open('tools/metrics/actions/actions.xml') as actions_f:
1035 current_actions = actions_f.read()
1036 # Search for the matched user action name in |current_actions|.
[email protected]999261d2014-03-03 20:08:081037 for action_name in match.groups():
[email protected]2f92dec2014-03-07 19:21:521038 action = 'name="{0}"'.format(action_name)
1039 if action not in current_actions:
[email protected]999261d2014-03-03 20:08:081040 return [output_api.PresubmitPromptWarning(
1041 'File %s line %d: %s is missing in '
[email protected]2f92dec2014-03-07 19:21:521042 'tools/metrics/actions/actions.xml. Please run '
1043 'tools/metrics/actions/extract_actions.py to update.'
[email protected]999261d2014-03-03 20:08:081044 % (f.LocalPath(), line_num, action_name))]
1045 return []
1046
1047
[email protected]760deea2013-12-10 19:33:491048def _CheckJavaStyle(input_api, output_api):
1049 """Runs checkstyle on changed java files and returns errors if any exist."""
1050 original_sys_path = sys.path
1051 try:
1052 sys.path = sys.path + [input_api.os_path.join(
1053 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1054 import checkstyle
1055 finally:
1056 # Restore sys.path to what it was before.
1057 sys.path = original_sys_path
1058
1059 return checkstyle.RunCheckstyle(
1060 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1061
1062
[email protected]22c9bd72011-03-27 16:47:391063def _CommonChecks(input_api, output_api):
1064 """Checks common to both upload and commit."""
1065 results = []
1066 results.extend(input_api.canned_checks.PanProjectChecks(
[email protected]3de922f2013-12-20 13:27:381067 input_api, output_api,
1068 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
[email protected]66daa702011-05-28 14:41:461069 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]55459852011-08-10 15:17:191070 results.extend(
[email protected]760deea2013-12-10 19:33:491071 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
[email protected]10689ca2011-09-02 02:31:541072 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
[email protected]72df4e782012-06-21 16:28:181073 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
[email protected]8ea5d4b2011-09-13 21:49:221074 results.extend(_CheckNoNewWStrings(input_api, output_api))
[email protected]2a8ac9c2011-10-19 17:20:441075 results.extend(_CheckNoDEPSGIT(input_api, output_api))
[email protected]127f18ec2012-06-16 05:05:591076 results.extend(_CheckNoBannedFunctions(input_api, output_api))
[email protected]6c063c62012-07-11 19:11:061077 results.extend(_CheckNoPragmaOnce(input_api, output_api))
[email protected]e7479052012-09-19 00:26:121078 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
[email protected]55f9f382012-07-31 11:02:181079 results.extend(_CheckUnwantedDependencies(input_api, output_api))
[email protected]fbcafe5a2012-08-08 15:31:221080 results.extend(_CheckFilePermissions(input_api, output_api))
[email protected]c8278b32012-10-30 20:35:491081 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
[email protected]2309b0fa02012-11-16 12:18:271082 results.extend(_CheckIncludeOrder(input_api, output_api))
[email protected]70ca77752012-11-20 03:45:031083 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
[email protected]b8079ae4a2012-12-05 19:56:491084 results.extend(_CheckPatchFiles(input_api, output_api))
[email protected]06e6d0ff2012-12-11 01:36:441085 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
[email protected]d2530012013-01-25 16:39:271086 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
[email protected]b00342e7f2013-03-26 16:21:541087 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
[email protected]e871964c2013-05-13 14:14:551088 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
[email protected]9f919cc2013-07-31 03:04:041089 results.extend(
1090 input_api.canned_checks.CheckChangeHasNoTabs(
1091 input_api,
1092 output_api,
1093 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
[email protected]85218562013-11-22 07:41:401094 results.extend(_CheckSpamLogging(input_api, output_api))
[email protected]49aa76a2013-12-04 06:59:161095 results.extend(_CheckForAnonymousVariables(input_api, output_api))
[email protected]5fe0f8742013-11-29 01:04:591096 results.extend(_CheckCygwinShell(input_api, output_api))
[email protected]999261d2014-03-03 20:08:081097 results.extend(_CheckUserActionUpdate(input_api, output_api))
[email protected]2299dcf2012-11-15 19:56:241098
1099 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1100 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1101 input_api, output_api,
1102 input_api.PresubmitLocalPath(),
[email protected]6be63382013-01-21 15:42:381103 whitelist=[r'^PRESUBMIT_test\.py$']))
[email protected]22c9bd72011-03-27 16:47:391104 return results
[email protected]1f7b4172010-01-28 01:17:341105
[email protected]b337cb5b2011-01-23 21:24:051106
1107def _CheckSubversionConfig(input_api, output_api):
1108 """Verifies the subversion config file is correctly setup.
1109
1110 Checks that autoprops are enabled, returns an error otherwise.
1111 """
1112 join = input_api.os_path.join
1113 if input_api.platform == 'win32':
1114 appdata = input_api.environ.get('APPDATA', '')
1115 if not appdata:
1116 return [output_api.PresubmitError('%APPDATA% is not configured.')]
1117 path = join(appdata, 'Subversion', 'config')
1118 else:
1119 home = input_api.environ.get('HOME', '')
1120 if not home:
1121 return [output_api.PresubmitError('$HOME is not configured.')]
1122 path = join(home, '.subversion', 'config')
1123
1124 error_msg = (
1125 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1126 'configure your subversion configuration file. This enables automatic\n'
[email protected]c6a3c10b2011-01-24 16:14:201127 'properties to simplify the project maintenance.\n'
1128 'Pro-tip: just download and install\n'
1129 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
[email protected]b337cb5b2011-01-23 21:24:051130
1131 try:
1132 lines = open(path, 'r').read().splitlines()
1133 # Make sure auto-props is enabled and check for 2 Chromium standard
1134 # auto-prop.
1135 if (not '*.cc = svn:eol-style=LF' in lines or
1136 not '*.pdf = svn:mime-type=application/pdf' in lines or
1137 not 'enable-auto-props = yes' in lines):
1138 return [
[email protected]79ed7e62011-02-21 21:08:531139 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:051140 'It looks like you have not configured your subversion config '
[email protected]b5359c02011-02-01 20:29:561141 'file or it is not up-to-date.\n' + error_msg)
[email protected]b337cb5b2011-01-23 21:24:051142 ]
1143 except (OSError, IOError):
1144 return [
[email protected]79ed7e62011-02-21 21:08:531145 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:051146 'Can\'t find your subversion config file.\n' + error_msg)
1147 ]
1148 return []
1149
1150
[email protected]66daa702011-05-28 14:41:461151def _CheckAuthorizedAuthor(input_api, output_api):
1152 """For non-googler/chromites committers, verify the author's email address is
1153 in AUTHORS.
1154 """
[email protected]9bb9cb82011-06-13 20:43:011155 # TODO(maruel): Add it to input_api?
1156 import fnmatch
1157
[email protected]66daa702011-05-28 14:41:461158 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:011159 if not author:
1160 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:461161 return []
[email protected]c99663292011-05-31 19:46:081162 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:461163 input_api.PresubmitLocalPath(), 'AUTHORS')
1164 valid_authors = (
1165 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1166 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:181167 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]d8b50be2011-06-15 14:19:441168 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]5861efb2013-01-07 18:33:231169 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
[email protected]66daa702011-05-28 14:41:461170 return [output_api.PresubmitPromptWarning(
1171 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1172 '\n'
1173 'http://www.chromium.org/developers/contributing-code and read the '
1174 '"Legal" section\n'
1175 'If you are a chromite, verify the contributor signed the CLA.') %
1176 author)]
1177 return []
1178
1179
[email protected]b8079ae4a2012-12-05 19:56:491180def _CheckPatchFiles(input_api, output_api):
1181 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1182 if f.LocalPath().endswith(('.orig', '.rej'))]
1183 if problems:
1184 return [output_api.PresubmitError(
1185 "Don't commit .rej and .orig files.", problems)]
[email protected]2fdd1f362013-01-16 03:56:031186 else:
1187 return []
[email protected]b8079ae4a2012-12-05 19:56:491188
1189
[email protected]b00342e7f2013-03-26 16:21:541190def _DidYouMeanOSMacro(bad_macro):
1191 try:
1192 return {'A': 'OS_ANDROID',
1193 'B': 'OS_BSD',
1194 'C': 'OS_CHROMEOS',
1195 'F': 'OS_FREEBSD',
1196 'L': 'OS_LINUX',
1197 'M': 'OS_MACOSX',
1198 'N': 'OS_NACL',
1199 'O': 'OS_OPENBSD',
1200 'P': 'OS_POSIX',
1201 'S': 'OS_SOLARIS',
1202 'W': 'OS_WIN'}[bad_macro[3].upper()]
1203 except KeyError:
1204 return ''
1205
1206
1207def _CheckForInvalidOSMacrosInFile(input_api, f):
1208 """Check for sensible looking, totally invalid OS macros."""
1209 preprocessor_statement = input_api.re.compile(r'^\s*#')
1210 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1211 results = []
1212 for lnum, line in f.ChangedContents():
1213 if preprocessor_statement.search(line):
1214 for match in os_macro.finditer(line):
1215 if not match.group(1) in _VALID_OS_MACROS:
1216 good = _DidYouMeanOSMacro(match.group(1))
1217 did_you_mean = ' (did you mean %s?)' % good if good else ''
1218 results.append(' %s:%d %s%s' % (f.LocalPath(),
1219 lnum,
1220 match.group(1),
1221 did_you_mean))
1222 return results
1223
1224
1225def _CheckForInvalidOSMacros(input_api, output_api):
1226 """Check all affected files for invalid OS macros."""
1227 bad_macros = []
1228 for f in input_api.AffectedFiles():
1229 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1230 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1231
1232 if not bad_macros:
1233 return []
1234
1235 return [output_api.PresubmitError(
1236 'Possibly invalid OS macro[s] found. Please fix your code\n'
1237 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1238
1239
[email protected]1f7b4172010-01-28 01:17:341240def CheckChangeOnUpload(input_api, output_api):
1241 results = []
1242 results.extend(_CommonChecks(input_api, output_api))
[email protected]ae69ae72014-02-20 13:09:361243 results.extend(_CheckJavaStyle(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541244 return results
[email protected]ca8d1982009-02-19 16:33:121245
1246
[email protected]38c6a512013-12-18 23:48:011247def GetDefaultTryConfigs(bots=None):
1248 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1249
1250 To add tests to this list, they MUST be in the the corresponding master's
1251 gatekeeper config. For example, anything on master.chromium would be closed by
1252 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1253
1254 If 'bots' is specified, will only return configurations for bots in that list.
1255 """
1256
1257 standard_tests = [
1258 'base_unittests',
1259 'browser_tests',
1260 'cacheinvalidation_unittests',
1261 'check_deps',
1262 'check_deps2git',
1263 'content_browsertests',
1264 'content_unittests',
1265 'crypto_unittests',
[email protected]38c6a512013-12-18 23:48:011266 'gpu_unittests',
1267 'interactive_ui_tests',
1268 'ipc_tests',
1269 'jingle_unittests',
1270 'media_unittests',
1271 'net_unittests',
1272 'ppapi_unittests',
1273 'printing_unittests',
1274 'sql_unittests',
1275 'sync_unit_tests',
1276 'unit_tests',
1277 # Broken in release.
1278 #'url_unittests',
1279 #'webkit_unit_tests',
1280 ]
1281
[email protected]38c6a512013-12-18 23:48:011282 builders_and_tests = {
1283 # TODO(maruel): Figure out a way to run 'sizes' where people can
1284 # effectively update the perf expectation correctly. This requires a
1285 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1286 # incremental build. Reference:
1287 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1288 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1289 # of this step as a try job failure.
1290 'android_aosp': ['compile'],
1291 'android_clang_dbg': ['slave_steps'],
1292 'android_dbg': ['slave_steps'],
1293 'cros_x86': ['defaulttests'],
1294 'ios_dbg_simulator': [
1295 'compile',
1296 'base_unittests',
1297 'content_unittests',
1298 'crypto_unittests',
1299 'url_unittests',
1300 'net_unittests',
1301 'sql_unittests',
1302 'ui_unittests',
1303 ],
1304 'ios_rel_device': ['compile'],
[email protected]971b08ce2014-03-19 22:03:561305 'linux_asan': ['compile'],
1306 'mac_asan': ['compile'],
[email protected]38c6a512013-12-18 23:48:011307 #TODO(stip): Change the name of this builder to reflect that it's release.
[email protected]71afb4ec2014-02-07 02:45:131308 'linux_gtk': standard_tests,
[email protected]971b08ce2014-03-19 22:03:561309 'linux_chromeos_asan': ['compile'],
[email protected]d910b6082014-02-27 18:15:431310 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
1311 'linux_chromium_chromeos_rel': ['defaulttests'],
1312 'linux_chromium_compile_dbg': ['defaulttests'],
[email protected]23c81d552014-01-07 13:45:461313 'linux_chromium_rel': ['defaulttests'],
[email protected]d910b6082014-02-27 18:15:431314 'linux_chromium_clang_dbg': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021315 'linux_nacl_sdk_build': ['compile'],
[email protected]d910b6082014-02-27 18:15:431316 'linux_rel': [
[email protected]9021a5f72014-01-24 19:02:381317 'telemetry_perf_unittests',
1318 'telemetry_unittests',
[email protected]38c6a512013-12-18 23:48:011319 ],
[email protected]d910b6082014-02-27 18:15:431320 'mac_chromium_compile_dbg': ['defaulttests'],
[email protected]23c81d552014-01-07 13:45:461321 'mac_chromium_rel': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021322 'mac_nacl_sdk_build': ['compile'],
[email protected]d910b6082014-02-27 18:15:431323 'mac_rel': [
[email protected]9021a5f72014-01-24 19:02:381324 'telemetry_perf_unittests',
[email protected]38c6a512013-12-18 23:48:011325 'telemetry_unittests',
1326 ],
1327 'win': ['compile'],
[email protected]0094fa12014-03-13 03:18:281328 'win_chromium_compile_dbg': ['defaulttests'],
[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',
[email protected]0df555e2014-02-27 14:53:111340 'gfx_unittests',
[email protected]38c6a512013-12-18 23:48:011341 'google_apis_unittests',
1342 'installer_util_unittests',
1343 'mini_installer_test',
1344 'nacl_integration',
1345 'remoting_unittests',
1346 'sync_integration_tests',
[email protected]9021a5f72014-01-24 19:02:381347 'telemetry_perf_unittests',
[email protected]38c6a512013-12-18 23:48:011348 'telemetry_unittests',
1349 'views_unittests',
1350 ],
1351 'win_x64_rel': [
1352 'base_unittests',
1353 ],
1354 }
1355
1356 swarm_enabled_builders = (
1357 'linux_rel',
1358 'mac_rel',
1359 'win_rel',
1360 )
1361
1362 swarm_enabled_tests = (
1363 'base_unittests',
1364 'browser_tests',
1365 'interactive_ui_tests',
1366 'net_unittests',
1367 'unit_tests',
1368 )
1369
1370 for bot in builders_and_tests:
1371 if bot in swarm_enabled_builders:
1372 builders_and_tests[bot] = [x + '_swarm' if x in swarm_enabled_tests else x
1373 for x in builders_and_tests[bot]]
1374
1375 if bots:
[email protected]7468ac522014-03-12 23:35:571376 return {
1377 'tryserver.chromium': dict((bot, set(builders_and_tests[bot]))
1378 for bot in bots)
1379 }
[email protected]38c6a512013-12-18 23:48:011380 else:
[email protected]7468ac522014-03-12 23:35:571381 return {
1382 'tryserver.chromium': dict(
1383 (bot, set(tests))
1384 for bot, tests in builders_and_tests.iteritems())
1385 }
[email protected]38c6a512013-12-18 23:48:011386
1387
[email protected]ca8d1982009-02-19 16:33:121388def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:541389 results = []
[email protected]1f7b4172010-01-28 01:17:341390 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:511391 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1392 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1393 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:541394 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:271395 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:341396 input_api,
1397 output_api,
[email protected]2fdd1f362013-01-16 03:56:031398 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:271399
[email protected]3e4eb112011-01-18 03:29:541400 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1401 input_api, output_api))
[email protected]c4b47562011-12-05 23:39:411402 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1403 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:051404 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541405 return results
[email protected]ca8d1982009-02-19 16:33:121406
1407
[email protected]7468ac522014-03-12 23:35:571408def GetPreferredTryMasters(project, change):
[email protected]4ce995ea2012-06-27 02:13:101409 files = change.LocalPaths()
1410
[email protected]751b05f2013-01-10 23:12:171411 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571412 return {}
[email protected]3019c902012-06-29 00:09:031413
[email protected]d668899a2012-09-06 18:16:591414 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
[email protected]d96b1f42014-02-27 19:17:521415 return GetDefaultTryConfigs([
1416 'mac_chromium_compile_dbg',
1417 'mac_chromium_rel',
[email protected]d96b1f42014-02-27 19:17:521418 ])
[email protected]d668899a2012-09-06 18:16:591419 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
[email protected]3630be892013-12-19 05:34:281420 return GetDefaultTryConfigs(['win', 'win_rel'])
[email protected]d668899a2012-09-06 18:16:591421 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011422 return GetDefaultTryConfigs([
1423 'android_aosp',
1424 'android_clang_dbg',
1425 'android_dbg',
1426 ])
[email protected]de142152012-10-03 23:02:451427 if all(re.search('[/_]ios[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011428 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
[email protected]4ce995ea2012-06-27 02:13:101429
[email protected]7468ac522014-03-12 23:35:571430 builders = [
[email protected]3e2f0402012-11-02 16:28:011431 'android_clang_dbg',
1432 'android_dbg',
1433 'ios_dbg_simulator',
1434 'ios_rel_device',
[email protected]d96b1f42014-02-27 19:17:521435 'linux_chromium_chromeos_rel',
1436 'linux_chromium_clang_dbg',
[email protected]d96b1f42014-02-27 19:17:521437 'linux_chromium_rel',
[email protected]d96b1f42014-02-27 19:17:521438 'mac_chromium_compile_dbg',
[email protected]d96b1f42014-02-27 19:17:521439 'mac_chromium_rel',
[email protected]0094fa12014-03-13 03:18:281440 'win_chromium_compile_dbg',
[email protected]3e2f0402012-11-02 16:28:011441 'win_rel',
[email protected]38c6a512013-12-18 23:48:011442 'win_x64_rel',
[email protected]7468ac522014-03-12 23:35:571443 ]
[email protected]911753b2012-08-02 12:11:541444
1445 # Match things like path/aura/file.cc and path/file_aura.cc.
[email protected]95c989162012-11-29 05:58:251446 # Same for chromeos.
1447 if any(re.search('[/_](aura|chromeos)', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571448 builders.extend([
1449 'linux_chromeos_asan',
1450 'linux_chromium_chromeos_clang_dbg'
1451 ])
[email protected]4ce995ea2012-06-27 02:13:101452
[email protected]e8df48f2013-09-30 20:07:541453 # If there are gyp changes to base, build, or chromeos, run a full cros build
1454 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1455 # files have a much higher chance of breaking the cros build, which is
1456 # differnt from the linux_chromeos build that most chrome developers test
1457 # with.
1458 if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571459 builders.extend(['cros_x86'])
[email protected]e8df48f2013-09-30 20:07:541460
[email protected]d95948ef2013-07-02 10:51:001461 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1462 # unless they're .gyp(i) files as changes to those files can break the gyp
1463 # step on that bot.
1464 if (not all(re.search('^chrome', f) for f in files) or
1465 any(re.search('\.gypi?$', f) for f in files)):
[email protected]7468ac522014-03-12 23:35:571466 builders.extend(['android_aosp'])
[email protected]d95948ef2013-07-02 10:51:001467
[email protected]7468ac522014-03-12 23:35:571468 return GetDefaultTryConfigs(builders)