blob: 1260528a060cb4fbba58acd614c83263ac286a77 [file] [log] [blame]
[email protected]a18130a2012-01-03 17:52:081# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ca8d1982009-02-19 16:33:122# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Top-level presubmit script for Chromium.
6
[email protected]f1293792009-07-31 18:09:567See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
[email protected]50d7d721e2009-11-15 17:56:188for more details about the presubmit API built into gcl.
[email protected]ca8d1982009-02-19 16:33:129"""
10
[email protected]eea609a2011-11-18 13:10:1211
[email protected]9d16ad12011-12-14 20:49:4712import re
[email protected]55f9f382012-07-31 11:02:1813import sys
[email protected]9d16ad12011-12-14 20:49:4714
15
[email protected]379e7dd2010-01-28 17:39:2116_EXCLUDED_PATHS = (
[email protected]3e4eb112011-01-18 03:29:5417 r"^breakpad[\\\/].*",
[email protected]40d1dbb2012-10-26 07:18:0018 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
19 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
[email protected]8886ffcb2013-02-12 04:56:2820 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
[email protected]a18130a2012-01-03 17:52:0821 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
[email protected]3e4eb112011-01-18 03:29:5422 r"^skia[\\\/].*",
23 r"^v8[\\\/].*",
24 r".*MakeFile$",
[email protected]1084ccc2012-03-14 03:22:5325 r".+_autogen\.h$",
[email protected]ce145c02012-09-06 09:49:3426 r".+[\\\/]pnacl_shim\.c$",
[email protected]e07b6ac72013-08-20 00:30:4227 r"^gpu[\\\/]config[\\\/].*_list_json\.cc$",
[email protected]d2600602014-02-19 00:09:1928 r"^chrome[\\\/]browser[\\\/]resources[\\\/]pdf[\\\/]index.js"
[email protected]4306417642009-06-11 00:33:4029)
[email protected]ca8d1982009-02-19 16:33:1230
[email protected]de28fed2e2014-02-01 14:36:3231# TestRunner and NetscapePlugIn library is temporarily excluded from pan-project
32# checks until it's transitioned to chromium coding style.
[email protected]3de922f2013-12-20 13:27:3833_TESTRUNNER_PATHS = (
34 r"^content[\\\/]shell[\\\/]renderer[\\\/]test_runner[\\\/].*",
[email protected]de28fed2e2014-02-01 14:36:3235 r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*",
[email protected]3de922f2013-12-20 13:27:3836)
37
[email protected]06e6d0ff2012-12-11 01:36:4438# Fragment of a regular expression that matches C++ and Objective-C++
39# implementation files.
40_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
41
42# Regular expression that matches code only used for test binaries
43# (best effort).
44_TEST_CODE_EXCLUDED_PATHS = (
45 r'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
46 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
[email protected]6e04f8c2014-01-29 18:08:3247 r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
[email protected]e2d7e6f2013-04-23 12:57:1248 _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4449 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
50 r'.*[/\\](test|tool(s)?)[/\\].*',
[email protected]ef070cc2013-05-03 11:53:0551 # content_shell is used for running layout tests.
52 r'content[/\\]shell[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4453 # At request of folks maintaining this folder.
54 r'chrome[/\\]browser[/\\]automation[/\\].*',
[email protected]7b054982013-11-27 00:44:4755 # Non-production example code.
56 r'mojo[/\\]examples[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4457)
[email protected]ca8d1982009-02-19 16:33:1258
[email protected]eea609a2011-11-18 13:10:1259_TEST_ONLY_WARNING = (
60 'You might be calling functions intended only for testing from\n'
61 'production code. It is OK to ignore this warning if you know what\n'
62 'you are doing, as the heuristics used to detect the situation are\n'
[email protected]b0149772014-03-27 16:47:5863 'not perfect. The commit queue will not block on this warning.')
[email protected]eea609a2011-11-18 13:10:1264
65
[email protected]cf9b78f2012-11-14 11:40:2866_INCLUDE_ORDER_WARNING = (
67 'Your #include order seems to be broken. Send mail to\n'
68 '[email protected] if this is not the case.')
69
70
[email protected]127f18ec2012-06-16 05:05:5971_BANNED_OBJC_FUNCTIONS = (
72 (
73 'addTrackingRect:',
[email protected]23e6cbc2012-06-16 18:51:2074 (
75 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
[email protected]127f18ec2012-06-16 05:05:5976 'prohibited. Please use CrTrackingArea instead.',
77 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
78 ),
79 False,
80 ),
81 (
82 'NSTrackingArea',
[email protected]23e6cbc2012-06-16 18:51:2083 (
84 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
[email protected]127f18ec2012-06-16 05:05:5985 'instead.',
86 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
87 ),
88 False,
89 ),
90 (
91 'convertPointFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2092 (
93 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5994 'Please use |convertPoint:(point) fromView:nil| instead.',
95 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
96 ),
97 True,
98 ),
99 (
100 'convertPointToBase:',
[email protected]23e6cbc2012-06-16 18:51:20101 (
102 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59103 'Please use |convertPoint:(point) toView:nil| instead.',
104 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
105 ),
106 True,
107 ),
108 (
109 'convertRectFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20110 (
111 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59112 'Please use |convertRect:(point) fromView:nil| instead.',
113 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
114 ),
115 True,
116 ),
117 (
118 'convertRectToBase:',
[email protected]23e6cbc2012-06-16 18:51:20119 (
120 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59121 'Please use |convertRect:(point) toView:nil| instead.',
122 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
123 ),
124 True,
125 ),
126 (
127 'convertSizeFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20128 (
129 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59130 'Please use |convertSize:(point) fromView:nil| instead.',
131 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
132 ),
133 True,
134 ),
135 (
136 'convertSizeToBase:',
[email protected]23e6cbc2012-06-16 18:51:20137 (
138 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59139 'Please use |convertSize:(point) toView:nil| instead.',
140 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
141 ),
142 True,
143 ),
144)
145
146
147_BANNED_CPP_FUNCTIONS = (
[email protected]23e6cbc2012-06-16 18:51:20148 # Make sure that gtest's FRIEND_TEST() macro is not used; the
149 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
[email protected]e00ccc92012-11-01 17:32:30150 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
[email protected]23e6cbc2012-06-16 18:51:20151 (
152 'FRIEND_TEST(',
153 (
[email protected]e3c945502012-06-26 20:01:49154 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
[email protected]23e6cbc2012-06-16 18:51:20155 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
156 ),
157 False,
[email protected]7345da02012-11-27 14:31:49158 (),
[email protected]23e6cbc2012-06-16 18:51:20159 ),
160 (
161 'ScopedAllowIO',
162 (
[email protected]e3c945502012-06-26 20:01:49163 'New code should not use ScopedAllowIO. Post a task to the blocking',
164 'pool or the FILE thread instead.',
[email protected]23e6cbc2012-06-16 18:51:20165 ),
[email protected]e3c945502012-06-26 20:01:49166 True,
[email protected]7345da02012-11-27 14:31:49167 (
[email protected]0b818f72013-10-22 00:11:03168 r"^components[\\\/]breakpad[\\\/]app[\\\/]breakpad_mac\.mm$",
[email protected]de7d61ff2013-08-20 11:30:41169 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
170 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
[email protected]ac1df702014-03-21 20:45:27171 r"^mojo[\\\/]system[\\\/]raw_shared_buffer_posix\.cc$",
[email protected]398ad132013-04-02 15:11:01172 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
[email protected]7345da02012-11-27 14:31:49173 ),
[email protected]23e6cbc2012-06-16 18:51:20174 ),
[email protected]52657f62013-05-20 05:30:31175 (
176 'SkRefPtr',
177 (
178 'The use of SkRefPtr is prohibited. ',
179 'Please use skia::RefPtr instead.'
180 ),
181 True,
182 (),
183 ),
184 (
185 'SkAutoRef',
186 (
187 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
188 'Please use skia::RefPtr instead.'
189 ),
190 True,
191 (),
192 ),
193 (
194 'SkAutoTUnref',
195 (
196 'The use of SkAutoTUnref is dangerous because it implicitly ',
197 'converts to a raw pointer. Please use skia::RefPtr instead.'
198 ),
199 True,
200 (),
201 ),
202 (
203 'SkAutoUnref',
204 (
205 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
206 'because it implicitly converts to a raw pointer. ',
207 'Please use skia::RefPtr instead.'
208 ),
209 True,
210 (),
211 ),
[email protected]d89eec82013-12-03 14:10:59212 (
213 r'/HANDLE_EINTR\(.*close',
214 (
215 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
216 'descriptor will be closed, and it is incorrect to retry the close.',
217 'Either call close directly and ignore its return value, or wrap close',
218 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
219 ),
220 True,
221 (),
222 ),
223 (
224 r'/IGNORE_EINTR\((?!.*close)',
225 (
226 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
227 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
228 ),
229 True,
230 (
231 # Files that #define IGNORE_EINTR.
232 r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
233 r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
234 ),
235 ),
[email protected]ec5b3f02014-04-04 18:43:43236 (
237 r'/v8::Extension\(',
238 (
239 'Do not introduce new v8::Extensions into the code base, use',
240 'gin::Wrappable instead. See http://crbug.com/334679',
241 ),
242 True,
[email protected]f55c90ee62014-04-12 00:50:03243 (
244 r'extensions[/\\]renderer[/\\]safe_builtins\.*',
245 ),
[email protected]ec5b3f02014-04-04 18:43:43246 ),
[email protected]127f18ec2012-06-16 05:05:59247)
248
249
[email protected]b00342e7f2013-03-26 16:21:54250_VALID_OS_MACROS = (
251 # Please keep sorted.
252 'OS_ANDROID',
[email protected]f4440b42014-03-19 05:47:01253 'OS_ANDROID_HOST',
[email protected]b00342e7f2013-03-26 16:21:54254 'OS_BSD',
255 'OS_CAT', # For testing.
256 'OS_CHROMEOS',
257 'OS_FREEBSD',
258 'OS_IOS',
259 'OS_LINUX',
260 'OS_MACOSX',
261 'OS_NACL',
262 'OS_OPENBSD',
263 'OS_POSIX',
[email protected]eda7afa12014-02-06 12:27:37264 'OS_QNX',
[email protected]b00342e7f2013-03-26 16:21:54265 'OS_SOLARIS',
[email protected]b00342e7f2013-03-26 16:21:54266 'OS_WIN',
267)
268
269
[email protected]55459852011-08-10 15:17:19270def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
271 """Attempts to prevent use of functions intended only for testing in
272 non-testing code. For now this is just a best-effort implementation
273 that ignores header files and may have some false positives. A
274 better implementation would probably need a proper C++ parser.
275 """
276 # We only scan .cc files and the like, as the declaration of
277 # for-testing functions in header files are hard to distinguish from
278 # calls to such functions without a proper C++ parser.
[email protected]06e6d0ff2012-12-11 01:36:44279 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
[email protected]55459852011-08-10 15:17:19280
281 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
282 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
[email protected]de4f7d22013-05-23 14:27:46283 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
[email protected]55459852011-08-10 15:17:19284 exclusion_pattern = input_api.re.compile(
285 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
286 base_function_pattern, base_function_pattern))
287
288 def FilterFile(affected_file):
[email protected]06e6d0ff2012-12-11 01:36:44289 black_list = (_EXCLUDED_PATHS +
290 _TEST_CODE_EXCLUDED_PATHS +
291 input_api.DEFAULT_BLACK_LIST)
[email protected]55459852011-08-10 15:17:19292 return input_api.FilterSourceFile(
293 affected_file,
294 white_list=(file_inclusion_pattern, ),
295 black_list=black_list)
296
297 problems = []
298 for f in input_api.AffectedSourceFiles(FilterFile):
299 local_path = f.LocalPath()
[email protected]825d27182014-01-02 21:24:24300 for line_number, line in f.ChangedContents():
[email protected]2fdd1f362013-01-16 03:56:03301 if (inclusion_pattern.search(line) and
[email protected]de4f7d22013-05-23 14:27:46302 not comment_pattern.search(line) and
[email protected]2fdd1f362013-01-16 03:56:03303 not exclusion_pattern.search(line)):
[email protected]55459852011-08-10 15:17:19304 problems.append(
[email protected]2fdd1f362013-01-16 03:56:03305 '%s:%d\n %s' % (local_path, line_number, line.strip()))
[email protected]55459852011-08-10 15:17:19306
307 if problems:
[email protected]f7051d52013-04-02 18:31:42308 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
[email protected]2fdd1f362013-01-16 03:56:03309 else:
310 return []
[email protected]55459852011-08-10 15:17:19311
312
[email protected]10689ca2011-09-02 02:31:54313def _CheckNoIOStreamInHeaders(input_api, output_api):
314 """Checks to make sure no .h files include <iostream>."""
315 files = []
316 pattern = input_api.re.compile(r'^#include\s*<iostream>',
317 input_api.re.MULTILINE)
318 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
319 if not f.LocalPath().endswith('.h'):
320 continue
321 contents = input_api.ReadFile(f)
322 if pattern.search(contents):
323 files.append(f)
324
325 if len(files):
326 return [ output_api.PresubmitError(
[email protected]6c063c62012-07-11 19:11:06327 'Do not #include <iostream> in header files, since it inserts static '
328 'initialization into every file including the header. Instead, '
[email protected]10689ca2011-09-02 02:31:54329 '#include <ostream>. See http://crbug.com/94794',
330 files) ]
331 return []
332
333
[email protected]72df4e782012-06-21 16:28:18334def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
335 """Checks to make sure no source files use UNIT_TEST"""
336 problems = []
337 for f in input_api.AffectedFiles():
338 if (not f.LocalPath().endswith(('.cc', '.mm'))):
339 continue
340
341 for line_num, line in f.ChangedContents():
[email protected]549f86a2013-11-19 13:00:04342 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
[email protected]72df4e782012-06-21 16:28:18343 problems.append(' %s:%d' % (f.LocalPath(), line_num))
344
345 if not problems:
346 return []
347 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
348 '\n'.join(problems))]
349
350
[email protected]8ea5d4b2011-09-13 21:49:22351def _CheckNoNewWStrings(input_api, output_api):
352 """Checks to make sure we don't introduce use of wstrings."""
[email protected]55463aa62011-10-12 00:48:27353 problems = []
[email protected]8ea5d4b2011-09-13 21:49:22354 for f in input_api.AffectedFiles():
[email protected]b5c24292011-11-28 14:38:20355 if (not f.LocalPath().endswith(('.cc', '.h')) or
[email protected]24be83c2013-08-29 23:01:23356 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
[email protected]b5c24292011-11-28 14:38:20357 continue
[email protected]8ea5d4b2011-09-13 21:49:22358
[email protected]a11dbe9b2012-08-07 01:32:58359 allowWString = False
[email protected]b5c24292011-11-28 14:38:20360 for line_num, line in f.ChangedContents():
[email protected]a11dbe9b2012-08-07 01:32:58361 if 'presubmit: allow wstring' in line:
362 allowWString = True
363 elif not allowWString and 'wstring' in line:
[email protected]55463aa62011-10-12 00:48:27364 problems.append(' %s:%d' % (f.LocalPath(), line_num))
[email protected]a11dbe9b2012-08-07 01:32:58365 allowWString = False
366 else:
367 allowWString = False
[email protected]8ea5d4b2011-09-13 21:49:22368
[email protected]55463aa62011-10-12 00:48:27369 if not problems:
370 return []
371 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
[email protected]a11dbe9b2012-08-07 01:32:58372 ' If you are calling a cross-platform API that accepts a wstring, '
373 'fix the API.\n' +
[email protected]55463aa62011-10-12 00:48:27374 '\n'.join(problems))]
[email protected]8ea5d4b2011-09-13 21:49:22375
376
[email protected]2a8ac9c2011-10-19 17:20:44377def _CheckNoDEPSGIT(input_api, output_api):
378 """Make sure .DEPS.git is never modified manually."""
379 if any(f.LocalPath().endswith('.DEPS.git') for f in
380 input_api.AffectedFiles()):
381 return [output_api.PresubmitError(
382 'Never commit changes to .DEPS.git. This file is maintained by an\n'
383 'automated system based on what\'s in DEPS and your changes will be\n'
384 'overwritten.\n'
385 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
386 'for more information')]
387 return []
388
389
[email protected]127f18ec2012-06-16 05:05:59390def _CheckNoBannedFunctions(input_api, output_api):
391 """Make sure that banned functions are not used."""
392 warnings = []
393 errors = []
394
395 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
396 for f in input_api.AffectedFiles(file_filter=file_filter):
397 for line_num, line in f.ChangedContents():
398 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
399 if func_name in line:
400 problems = warnings;
401 if error:
402 problems = errors;
403 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
404 for message_line in message:
405 problems.append(' %s' % message_line)
406
407 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
408 for f in input_api.AffectedFiles(file_filter=file_filter):
409 for line_num, line in f.ChangedContents():
[email protected]7345da02012-11-27 14:31:49410 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
411 def IsBlacklisted(affected_file, blacklist):
412 local_path = affected_file.LocalPath()
413 for item in blacklist:
414 if input_api.re.match(item, local_path):
415 return True
416 return False
417 if IsBlacklisted(f, excluded_paths):
418 continue
[email protected]d89eec82013-12-03 14:10:59419 matched = False
420 if func_name[0:1] == '/':
421 regex = func_name[1:]
422 if input_api.re.search(regex, line):
423 matched = True
424 elif func_name in line:
425 matched = True
426 if matched:
[email protected]127f18ec2012-06-16 05:05:59427 problems = warnings;
428 if error:
429 problems = errors;
430 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
431 for message_line in message:
432 problems.append(' %s' % message_line)
433
434 result = []
435 if (warnings):
436 result.append(output_api.PresubmitPromptWarning(
437 'Banned functions were used.\n' + '\n'.join(warnings)))
438 if (errors):
439 result.append(output_api.PresubmitError(
440 'Banned functions were used.\n' + '\n'.join(errors)))
441 return result
442
443
[email protected]6c063c62012-07-11 19:11:06444def _CheckNoPragmaOnce(input_api, output_api):
445 """Make sure that banned functions are not used."""
446 files = []
447 pattern = input_api.re.compile(r'^#pragma\s+once',
448 input_api.re.MULTILINE)
449 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
450 if not f.LocalPath().endswith('.h'):
451 continue
452 contents = input_api.ReadFile(f)
453 if pattern.search(contents):
454 files.append(f)
455
456 if files:
457 return [output_api.PresubmitError(
458 'Do not use #pragma once in header files.\n'
459 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
460 files)]
461 return []
462
[email protected]127f18ec2012-06-16 05:05:59463
[email protected]e7479052012-09-19 00:26:12464def _CheckNoTrinaryTrueFalse(input_api, output_api):
465 """Checks to make sure we don't introduce use of foo ? true : false."""
466 problems = []
467 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
468 for f in input_api.AffectedFiles():
469 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
470 continue
471
472 for line_num, line in f.ChangedContents():
473 if pattern.match(line):
474 problems.append(' %s:%d' % (f.LocalPath(), line_num))
475
476 if not problems:
477 return []
478 return [output_api.PresubmitPromptWarning(
479 'Please consider avoiding the "? true : false" pattern if possible.\n' +
480 '\n'.join(problems))]
481
482
[email protected]55f9f382012-07-31 11:02:18483def _CheckUnwantedDependencies(input_api, output_api):
484 """Runs checkdeps on #include statements added in this
485 change. Breaking - rules is an error, breaking ! rules is a
486 warning.
487 """
488 # We need to wait until we have an input_api object and use this
489 # roundabout construct to import checkdeps because this file is
490 # eval-ed and thus doesn't have __file__.
491 original_sys_path = sys.path
492 try:
493 sys.path = sys.path + [input_api.os_path.join(
494 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
495 import checkdeps
496 from cpp_checker import CppChecker
497 from rules import Rule
498 finally:
499 # Restore sys.path to what it was before.
500 sys.path = original_sys_path
501
502 added_includes = []
503 for f in input_api.AffectedFiles():
504 if not CppChecker.IsCppFile(f.LocalPath()):
505 continue
506
507 changed_lines = [line for line_num, line in f.ChangedContents()]
508 added_includes.append([f.LocalPath(), changed_lines])
509
[email protected]26385172013-05-09 23:11:35510 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
[email protected]55f9f382012-07-31 11:02:18511
512 error_descriptions = []
513 warning_descriptions = []
514 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
515 added_includes):
516 description_with_path = '%s\n %s' % (path, rule_description)
517 if rule_type == Rule.DISALLOW:
518 error_descriptions.append(description_with_path)
519 else:
520 warning_descriptions.append(description_with_path)
521
522 results = []
523 if error_descriptions:
524 results.append(output_api.PresubmitError(
525 'You added one or more #includes that violate checkdeps rules.',
526 error_descriptions))
527 if warning_descriptions:
[email protected]f7051d52013-04-02 18:31:42528 results.append(output_api.PresubmitPromptOrNotify(
[email protected]55f9f382012-07-31 11:02:18529 'You added one or more #includes of files that are temporarily\n'
530 'allowed but being removed. Can you avoid introducing the\n'
531 '#include? See relevant DEPS file(s) for details and contacts.',
532 warning_descriptions))
533 return results
534
535
[email protected]fbcafe5a2012-08-08 15:31:22536def _CheckFilePermissions(input_api, output_api):
537 """Check that all files have their permissions properly set."""
[email protected]791507202014-02-03 23:19:15538 if input_api.platform == 'win32':
539 return []
[email protected]fbcafe5a2012-08-08 15:31:22540 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
541 input_api.change.RepositoryRoot()]
542 for f in input_api.AffectedFiles():
543 args += ['--file', f.LocalPath()]
[email protected]f0d330f2014-01-30 01:44:34544 checkperms = input_api.subprocess.Popen(args,
545 stdout=input_api.subprocess.PIPE)
546 errors = checkperms.communicate()[0].strip()
[email protected]fbcafe5a2012-08-08 15:31:22547 if errors:
[email protected]f0d330f2014-01-30 01:44:34548 return [output_api.PresubmitError('checkperms.py failed.',
549 errors.splitlines())]
550 return []
[email protected]fbcafe5a2012-08-08 15:31:22551
552
[email protected]c8278b32012-10-30 20:35:49553def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
554 """Makes sure we don't include ui/aura/window_property.h
555 in header files.
556 """
557 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
558 errors = []
559 for f in input_api.AffectedFiles():
560 if not f.LocalPath().endswith('.h'):
561 continue
562 for line_num, line in f.ChangedContents():
563 if pattern.match(line):
564 errors.append(' %s:%d' % (f.LocalPath(), line_num))
565
566 results = []
567 if errors:
568 results.append(output_api.PresubmitError(
569 'Header files should not include ui/aura/window_property.h', errors))
570 return results
571
572
[email protected]cf9b78f2012-11-14 11:40:28573def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
574 """Checks that the lines in scope occur in the right order.
575
576 1. C system files in alphabetical order
577 2. C++ system files in alphabetical order
578 3. Project's .h files
579 """
580
581 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
582 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
583 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
584
585 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
586
587 state = C_SYSTEM_INCLUDES
588
589 previous_line = ''
[email protected]728b9bb2012-11-14 20:38:57590 previous_line_num = 0
[email protected]cf9b78f2012-11-14 11:40:28591 problem_linenums = []
592 for line_num, line in scope:
593 if c_system_include_pattern.match(line):
594 if state != C_SYSTEM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57595 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28596 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57597 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28598 elif cpp_system_include_pattern.match(line):
599 if state == C_SYSTEM_INCLUDES:
600 state = CPP_SYSTEM_INCLUDES
601 elif state == CUSTOM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57602 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28603 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57604 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28605 elif custom_include_pattern.match(line):
606 if state != CUSTOM_INCLUDES:
607 state = CUSTOM_INCLUDES
608 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57609 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28610 else:
611 problem_linenums.append(line_num)
612 previous_line = line
[email protected]728b9bb2012-11-14 20:38:57613 previous_line_num = line_num
[email protected]cf9b78f2012-11-14 11:40:28614
615 warnings = []
[email protected]728b9bb2012-11-14 20:38:57616 for (line_num, previous_line_num) in problem_linenums:
617 if line_num in changed_linenums or previous_line_num in changed_linenums:
[email protected]cf9b78f2012-11-14 11:40:28618 warnings.append(' %s:%d' % (file_path, line_num))
619 return warnings
620
621
[email protected]ac294a12012-12-06 16:38:43622def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
[email protected]cf9b78f2012-11-14 11:40:28623 """Checks the #include order for the given file f."""
624
[email protected]2299dcf2012-11-15 19:56:24625 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
[email protected]23093b62013-09-20 12:16:30626 # Exclude the following includes from the check:
627 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
628 # specific order.
629 # 2) <atlbase.h>, "build/build_config.h"
630 excluded_include_pattern = input_api.re.compile(
631 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
[email protected]2299dcf2012-11-15 19:56:24632 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
[email protected]3e83618c2013-10-09 22:32:33633 # Match the final or penultimate token if it is xxxtest so we can ignore it
634 # when considering the special first include.
635 test_file_tag_pattern = input_api.re.compile(
636 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
[email protected]0e5c1852012-12-18 20:17:11637 if_pattern = input_api.re.compile(
638 r'\s*#\s*(if|elif|else|endif|define|undef).*')
639 # Some files need specialized order of includes; exclude such files from this
640 # check.
641 uncheckable_includes_pattern = input_api.re.compile(
642 r'\s*#include '
643 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
[email protected]cf9b78f2012-11-14 11:40:28644
645 contents = f.NewContents()
646 warnings = []
647 line_num = 0
648
[email protected]ac294a12012-12-06 16:38:43649 # Handle the special first include. If the first include file is
650 # some/path/file.h, the corresponding including file can be some/path/file.cc,
651 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
652 # etc. It's also possible that no special first include exists.
[email protected]3e83618c2013-10-09 22:32:33653 # If the included file is some/path/file_platform.h the including file could
654 # also be some/path/file_xxxtest_platform.h.
655 including_file_base_name = test_file_tag_pattern.sub(
656 '', input_api.os_path.basename(f.LocalPath()))
657
[email protected]ac294a12012-12-06 16:38:43658 for line in contents:
659 line_num += 1
660 if system_include_pattern.match(line):
661 # No special first include -> process the line again along with normal
662 # includes.
663 line_num -= 1
664 break
665 match = custom_include_pattern.match(line)
666 if match:
667 match_dict = match.groupdict()
[email protected]3e83618c2013-10-09 22:32:33668 header_basename = test_file_tag_pattern.sub(
669 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
670
671 if header_basename not in including_file_base_name:
[email protected]2299dcf2012-11-15 19:56:24672 # No special first include -> process the line again along with normal
673 # includes.
674 line_num -= 1
[email protected]ac294a12012-12-06 16:38:43675 break
[email protected]cf9b78f2012-11-14 11:40:28676
677 # Split into scopes: Each region between #if and #endif is its own scope.
678 scopes = []
679 current_scope = []
680 for line in contents[line_num:]:
681 line_num += 1
[email protected]0e5c1852012-12-18 20:17:11682 if uncheckable_includes_pattern.match(line):
[email protected]4436c9e2014-01-07 23:19:54683 continue
[email protected]2309b0fa02012-11-16 12:18:27684 if if_pattern.match(line):
[email protected]cf9b78f2012-11-14 11:40:28685 scopes.append(current_scope)
686 current_scope = []
[email protected]962f117e2012-11-22 18:11:56687 elif ((system_include_pattern.match(line) or
688 custom_include_pattern.match(line)) and
689 not excluded_include_pattern.match(line)):
[email protected]cf9b78f2012-11-14 11:40:28690 current_scope.append((line_num, line))
691 scopes.append(current_scope)
692
693 for scope in scopes:
694 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
695 changed_linenums))
696 return warnings
697
698
699def _CheckIncludeOrder(input_api, output_api):
700 """Checks that the #include order is correct.
701
702 1. The corresponding header for source files.
703 2. C system files in alphabetical order
704 3. C++ system files in alphabetical order
705 4. Project's .h files in alphabetical order
706
[email protected]ac294a12012-12-06 16:38:43707 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
708 these rules separately.
[email protected]cf9b78f2012-11-14 11:40:28709 """
710
711 warnings = []
712 for f in input_api.AffectedFiles():
[email protected]ac294a12012-12-06 16:38:43713 if f.LocalPath().endswith(('.cc', '.h')):
714 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
715 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
[email protected]cf9b78f2012-11-14 11:40:28716
717 results = []
718 if warnings:
[email protected]f7051d52013-04-02 18:31:42719 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
[email protected]120cf540d2012-12-10 17:55:53720 warnings))
[email protected]cf9b78f2012-11-14 11:40:28721 return results
722
723
[email protected]70ca77752012-11-20 03:45:03724def _CheckForVersionControlConflictsInFile(input_api, f):
725 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
726 errors = []
727 for line_num, line in f.ChangedContents():
728 if pattern.match(line):
729 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
730 return errors
731
732
733def _CheckForVersionControlConflicts(input_api, output_api):
734 """Usually this is not intentional and will cause a compile failure."""
735 errors = []
736 for f in input_api.AffectedFiles():
737 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
738
739 results = []
740 if errors:
741 results.append(output_api.PresubmitError(
742 'Version control conflict markers found, please resolve.', errors))
743 return results
744
745
[email protected]06e6d0ff2012-12-11 01:36:44746def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
747 def FilterFile(affected_file):
748 """Filter function for use with input_api.AffectedSourceFiles,
749 below. This filters out everything except non-test files from
750 top-level directories that generally speaking should not hard-code
751 service URLs (e.g. src/android_webview/, src/content/ and others).
752 """
753 return input_api.FilterSourceFile(
754 affected_file,
[email protected]78bb39d62012-12-11 15:11:56755 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
[email protected]06e6d0ff2012-12-11 01:36:44756 black_list=(_EXCLUDED_PATHS +
757 _TEST_CODE_EXCLUDED_PATHS +
758 input_api.DEFAULT_BLACK_LIST))
759
[email protected]de4f7d22013-05-23 14:27:46760 base_pattern = '"[^"]*google\.com[^"]*"'
761 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
762 pattern = input_api.re.compile(base_pattern)
[email protected]06e6d0ff2012-12-11 01:36:44763 problems = [] # items are (filename, line_number, line)
764 for f in input_api.AffectedSourceFiles(FilterFile):
765 for line_num, line in f.ChangedContents():
[email protected]de4f7d22013-05-23 14:27:46766 if not comment_pattern.search(line) and pattern.search(line):
[email protected]06e6d0ff2012-12-11 01:36:44767 problems.append((f.LocalPath(), line_num, line))
768
769 if problems:
[email protected]f7051d52013-04-02 18:31:42770 return [output_api.PresubmitPromptOrNotify(
[email protected]06e6d0ff2012-12-11 01:36:44771 'Most layers below src/chrome/ should not hardcode service URLs.\n'
[email protected]b0149772014-03-27 16:47:58772 'Are you sure this is correct?',
[email protected]06e6d0ff2012-12-11 01:36:44773 [' %s:%d: %s' % (
774 problem[0], problem[1], problem[2]) for problem in problems])]
[email protected]2fdd1f362013-01-16 03:56:03775 else:
776 return []
[email protected]06e6d0ff2012-12-11 01:36:44777
778
[email protected]d2530012013-01-25 16:39:27779def _CheckNoAbbreviationInPngFileName(input_api, output_api):
780 """Makes sure there are no abbreviations in the name of PNG files.
781 """
[email protected]4053a48e2013-01-25 21:43:04782 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
[email protected]d2530012013-01-25 16:39:27783 errors = []
784 for f in input_api.AffectedFiles(include_deletes=False):
785 if pattern.match(f.LocalPath()):
786 errors.append(' %s' % f.LocalPath())
787
788 results = []
789 if errors:
790 results.append(output_api.PresubmitError(
791 'The name of PNG files should not have abbreviations. \n'
792 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
793 'Contact [email protected] if you have questions.', errors))
794 return results
795
796
[email protected]14a6131c2014-01-08 01:15:41797def _FilesToCheckForIncomingDeps(re, changed_lines):
[email protected]f32e2d1e2013-07-26 21:39:08798 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
[email protected]14a6131c2014-01-08 01:15:41799 a set of DEPS entries that we should look up.
800
801 For a directory (rather than a specific filename) we fake a path to
802 a specific filename by adding /DEPS. This is chosen as a file that
803 will seldom or never be subject to per-file include_rules.
804 """
[email protected]2b438d62013-11-14 17:54:14805 # We ignore deps entries on auto-generated directories.
806 AUTO_GENERATED_DIRS = ['grit', 'jni']
[email protected]f32e2d1e2013-07-26 21:39:08807
808 # This pattern grabs the path without basename in the first
809 # parentheses, and the basename (if present) in the second. It
810 # relies on the simple heuristic that if there is a basename it will
811 # be a header file ending in ".h".
812 pattern = re.compile(
813 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
[email protected]2b438d62013-11-14 17:54:14814 results = set()
[email protected]f32e2d1e2013-07-26 21:39:08815 for changed_line in changed_lines:
816 m = pattern.match(changed_line)
817 if m:
818 path = m.group(1)
[email protected]2b438d62013-11-14 17:54:14819 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
[email protected]14a6131c2014-01-08 01:15:41820 if m.group(2):
821 results.add('%s%s' % (path, m.group(2)))
822 else:
823 results.add('%s/DEPS' % path)
[email protected]f32e2d1e2013-07-26 21:39:08824 return results
825
826
[email protected]e871964c2013-05-13 14:14:55827def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
828 """When a dependency prefixed with + is added to a DEPS file, we
829 want to make sure that the change is reviewed by an OWNER of the
830 target file or directory, to avoid layering violations from being
831 introduced. This check verifies that this happens.
832 """
833 changed_lines = set()
834 for f in input_api.AffectedFiles():
835 filename = input_api.os_path.basename(f.LocalPath())
836 if filename == 'DEPS':
837 changed_lines |= set(line.strip()
838 for line_num, line
839 in f.ChangedContents())
840 if not changed_lines:
841 return []
842
[email protected]14a6131c2014-01-08 01:15:41843 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
844 changed_lines)
[email protected]e871964c2013-05-13 14:14:55845 if not virtual_depended_on_files:
846 return []
847
848 if input_api.is_committing:
849 if input_api.tbr:
850 return [output_api.PresubmitNotifyResult(
851 '--tbr was specified, skipping OWNERS check for DEPS additions')]
852 if not input_api.change.issue:
853 return [output_api.PresubmitError(
854 "DEPS approval by OWNERS check failed: this change has "
855 "no Rietveld issue number, so we can't check it for approvals.")]
856 output = output_api.PresubmitError
857 else:
858 output = output_api.PresubmitNotifyResult
859
860 owners_db = input_api.owners_db
861 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
862 input_api,
863 owners_db.email_regexp,
864 approval_needed=input_api.is_committing)
865
866 owner_email = owner_email or input_api.change.author_email
867
[email protected]de4f7d22013-05-23 14:27:46868 reviewers_plus_owner = set(reviewers)
[email protected]e71c6082013-05-22 02:28:51869 if owner_email:
[email protected]de4f7d22013-05-23 14:27:46870 reviewers_plus_owner.add(owner_email)
[email protected]e871964c2013-05-13 14:14:55871 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
872 reviewers_plus_owner)
[email protected]14a6131c2014-01-08 01:15:41873
874 # We strip the /DEPS part that was added by
875 # _FilesToCheckForIncomingDeps to fake a path to a file in a
876 # directory.
877 def StripDeps(path):
878 start_deps = path.rfind('/DEPS')
879 if start_deps != -1:
880 return path[:start_deps]
881 else:
882 return path
883 unapproved_dependencies = ["'+%s'," % StripDeps(path)
[email protected]e871964c2013-05-13 14:14:55884 for path in missing_files]
885
886 if unapproved_dependencies:
887 output_list = [
[email protected]14a6131c2014-01-08 01:15:41888 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
[email protected]e871964c2013-05-13 14:14:55889 '\n '.join(sorted(unapproved_dependencies)))]
890 if not input_api.is_committing:
891 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
892 output_list.append(output(
893 'Suggested missing target path OWNERS:\n %s' %
894 '\n '.join(suggested_owners or [])))
895 return output_list
896
897 return []
898
899
[email protected]85218562013-11-22 07:41:40900def _CheckSpamLogging(input_api, output_api):
901 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
902 black_list = (_EXCLUDED_PATHS +
903 _TEST_CODE_EXCLUDED_PATHS +
904 input_api.DEFAULT_BLACK_LIST +
[email protected]6f742dd02013-11-26 23:19:50905 (r"^base[\\\/]logging\.h$",
[email protected]80f360a2014-01-23 01:36:19906 r"^base[\\\/]logging\.cc$",
[email protected]b3643872014-02-11 23:29:39907 r"^cloud_print[\\\/]",
[email protected]c80b35022014-03-03 17:01:41908 r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
[email protected]8dc338c2013-12-09 16:28:48909 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
[email protected]6e268db2013-12-04 01:41:46910 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
[email protected]4de75262013-12-18 23:16:12911 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
912 r"startup_browser_creator\.cc$",
[email protected]fe0e6e12013-12-04 05:52:58913 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
[email protected]95c6b3012013-12-02 14:30:31914 r"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
[email protected]6e268db2013-12-04 01:41:46915 r"logging_native_handler\.cc$",
[email protected]9056e732014-01-08 06:25:25916 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
917 r"gl_helper_benchmark\.cc$",
[email protected]9c36d922014-03-24 16:47:52918 r"^native_client_sdk[\\\/]",
[email protected]cdbdced2013-11-27 21:35:50919 r"^remoting[\\\/]base[\\\/]logging\.h$",
[email protected]67c96ab2013-12-17 02:05:36920 r"^remoting[\\\/]host[\\\/].*",
[email protected]8232f8fd2013-12-14 00:52:31921 r"^sandbox[\\\/]linux[\\\/].*",
[email protected]0b7a21e2014-02-11 18:38:13922 r"^tools[\\\/]",
[email protected]8232f8fd2013-12-14 00:52:31923 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
[email protected]85218562013-11-22 07:41:40924 source_file_filter = lambda x: input_api.FilterSourceFile(
925 x, white_list=(file_inclusion_pattern,), black_list=black_list)
926
927 log_info = []
928 printf = []
929
930 for f in input_api.AffectedSourceFiles(source_file_filter):
931 contents = input_api.ReadFile(f, 'rb')
932 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
933 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37934 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
[email protected]85210652013-11-28 05:50:13935 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:37936
937 if re.search(r"\bprintf\(", contents):
938 printf.append(f.LocalPath())
939 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
[email protected]85218562013-11-22 07:41:40940 printf.append(f.LocalPath())
941
942 if log_info:
943 return [output_api.PresubmitError(
944 'These files spam the console log with LOG(INFO):',
945 items=log_info)]
946 if printf:
947 return [output_api.PresubmitError(
948 'These files spam the console log with printf/fprintf:',
949 items=printf)]
950 return []
951
952
[email protected]49aa76a2013-12-04 06:59:16953def _CheckForAnonymousVariables(input_api, output_api):
954 """These types are all expected to hold locks while in scope and
955 so should never be anonymous (which causes them to be immediately
956 destroyed)."""
957 they_who_must_be_named = [
958 'base::AutoLock',
959 'base::AutoReset',
960 'base::AutoUnlock',
961 'SkAutoAlphaRestore',
962 'SkAutoBitmapShaderInstall',
963 'SkAutoBlitterChoose',
964 'SkAutoBounderCommit',
965 'SkAutoCallProc',
966 'SkAutoCanvasRestore',
967 'SkAutoCommentBlock',
968 'SkAutoDescriptor',
969 'SkAutoDisableDirectionCheck',
970 'SkAutoDisableOvalCheck',
971 'SkAutoFree',
972 'SkAutoGlyphCache',
973 'SkAutoHDC',
974 'SkAutoLockColors',
975 'SkAutoLockPixels',
976 'SkAutoMalloc',
977 'SkAutoMaskFreeImage',
978 'SkAutoMutexAcquire',
979 'SkAutoPathBoundsUpdate',
980 'SkAutoPDFRelease',
981 'SkAutoRasterClipValidate',
982 'SkAutoRef',
983 'SkAutoTime',
984 'SkAutoTrace',
985 'SkAutoUnref',
986 ]
987 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
988 # bad: base::AutoLock(lock.get());
989 # not bad: base::AutoLock lock(lock.get());
990 bad_pattern = input_api.re.compile(anonymous)
991 # good: new base::AutoLock(lock.get())
992 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
993 errors = []
994
995 for f in input_api.AffectedFiles():
996 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
997 continue
998 for linenum, line in f.ChangedContents():
999 if bad_pattern.search(line) and not good_pattern.search(line):
1000 errors.append('%s:%d' % (f.LocalPath(), linenum))
1001
1002 if errors:
1003 return [output_api.PresubmitError(
1004 'These lines create anonymous variables that need to be named:',
1005 items=errors)]
1006 return []
1007
1008
[email protected]5fe0f8742013-11-29 01:04:591009def _CheckCygwinShell(input_api, output_api):
1010 source_file_filter = lambda x: input_api.FilterSourceFile(
1011 x, white_list=(r'.+\.(gyp|gypi)$',))
1012 cygwin_shell = []
1013
1014 for f in input_api.AffectedSourceFiles(source_file_filter):
1015 for linenum, line in f.ChangedContents():
1016 if 'msvs_cygwin_shell' in line:
1017 cygwin_shell.append(f.LocalPath())
1018 break
1019
1020 if cygwin_shell:
1021 return [output_api.PresubmitError(
1022 'These files should not use msvs_cygwin_shell (the default is 0):',
1023 items=cygwin_shell)]
1024 return []
1025
[email protected]85218562013-11-22 07:41:401026
[email protected]999261d2014-03-03 20:08:081027def _CheckUserActionUpdate(input_api, output_api):
1028 """Checks if any new user action has been added."""
[email protected]2f92dec2014-03-07 19:21:521029 if any('actions.xml' == input_api.os_path.basename(f) for f in
[email protected]999261d2014-03-03 20:08:081030 input_api.LocalPaths()):
[email protected]2f92dec2014-03-07 19:21:521031 # If actions.xml is already included in the changelist, the PRESUBMIT
1032 # for actions.xml will do a more complete presubmit check.
[email protected]999261d2014-03-03 20:08:081033 return []
1034
[email protected]999261d2014-03-03 20:08:081035 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm'))
1036 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)'
[email protected]2f92dec2014-03-07 19:21:521037 current_actions = None
[email protected]999261d2014-03-03 20:08:081038 for f in input_api.AffectedFiles(file_filter=file_filter):
1039 for line_num, line in f.ChangedContents():
1040 match = input_api.re.search(action_re, line)
1041 if match:
[email protected]2f92dec2014-03-07 19:21:521042 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1043 # loaded only once.
1044 if not current_actions:
1045 with open('tools/metrics/actions/actions.xml') as actions_f:
1046 current_actions = actions_f.read()
1047 # Search for the matched user action name in |current_actions|.
[email protected]999261d2014-03-03 20:08:081048 for action_name in match.groups():
[email protected]2f92dec2014-03-07 19:21:521049 action = 'name="{0}"'.format(action_name)
1050 if action not in current_actions:
[email protected]999261d2014-03-03 20:08:081051 return [output_api.PresubmitPromptWarning(
1052 'File %s line %d: %s is missing in '
[email protected]2f92dec2014-03-07 19:21:521053 'tools/metrics/actions/actions.xml. Please run '
1054 'tools/metrics/actions/extract_actions.py to update.'
[email protected]999261d2014-03-03 20:08:081055 % (f.LocalPath(), line_num, action_name))]
1056 return []
1057
1058
[email protected]760deea2013-12-10 19:33:491059def _CheckJavaStyle(input_api, output_api):
1060 """Runs checkstyle on changed java files and returns errors if any exist."""
1061 original_sys_path = sys.path
1062 try:
1063 sys.path = sys.path + [input_api.os_path.join(
1064 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1065 import checkstyle
1066 finally:
1067 # Restore sys.path to what it was before.
1068 sys.path = original_sys_path
1069
1070 return checkstyle.RunCheckstyle(
1071 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1072
1073
[email protected]22c9bd72011-03-27 16:47:391074def _CommonChecks(input_api, output_api):
1075 """Checks common to both upload and commit."""
1076 results = []
1077 results.extend(input_api.canned_checks.PanProjectChecks(
[email protected]3de922f2013-12-20 13:27:381078 input_api, output_api,
1079 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
[email protected]66daa702011-05-28 14:41:461080 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]55459852011-08-10 15:17:191081 results.extend(
[email protected]760deea2013-12-10 19:33:491082 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
[email protected]10689ca2011-09-02 02:31:541083 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
[email protected]72df4e782012-06-21 16:28:181084 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
[email protected]8ea5d4b2011-09-13 21:49:221085 results.extend(_CheckNoNewWStrings(input_api, output_api))
[email protected]2a8ac9c2011-10-19 17:20:441086 results.extend(_CheckNoDEPSGIT(input_api, output_api))
[email protected]127f18ec2012-06-16 05:05:591087 results.extend(_CheckNoBannedFunctions(input_api, output_api))
[email protected]6c063c62012-07-11 19:11:061088 results.extend(_CheckNoPragmaOnce(input_api, output_api))
[email protected]e7479052012-09-19 00:26:121089 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
[email protected]55f9f382012-07-31 11:02:181090 results.extend(_CheckUnwantedDependencies(input_api, output_api))
[email protected]fbcafe5a2012-08-08 15:31:221091 results.extend(_CheckFilePermissions(input_api, output_api))
[email protected]c8278b32012-10-30 20:35:491092 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
[email protected]2309b0fa02012-11-16 12:18:271093 results.extend(_CheckIncludeOrder(input_api, output_api))
[email protected]70ca77752012-11-20 03:45:031094 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
[email protected]b8079ae4a2012-12-05 19:56:491095 results.extend(_CheckPatchFiles(input_api, output_api))
[email protected]06e6d0ff2012-12-11 01:36:441096 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
[email protected]d2530012013-01-25 16:39:271097 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
[email protected]b00342e7f2013-03-26 16:21:541098 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
[email protected]e871964c2013-05-13 14:14:551099 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
[email protected]9f919cc2013-07-31 03:04:041100 results.extend(
1101 input_api.canned_checks.CheckChangeHasNoTabs(
1102 input_api,
1103 output_api,
1104 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
[email protected]85218562013-11-22 07:41:401105 results.extend(_CheckSpamLogging(input_api, output_api))
[email protected]49aa76a2013-12-04 06:59:161106 results.extend(_CheckForAnonymousVariables(input_api, output_api))
[email protected]5fe0f8742013-11-29 01:04:591107 results.extend(_CheckCygwinShell(input_api, output_api))
[email protected]999261d2014-03-03 20:08:081108 results.extend(_CheckUserActionUpdate(input_api, output_api))
[email protected]2299dcf2012-11-15 19:56:241109
1110 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1111 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1112 input_api, output_api,
1113 input_api.PresubmitLocalPath(),
[email protected]6be63382013-01-21 15:42:381114 whitelist=[r'^PRESUBMIT_test\.py$']))
[email protected]22c9bd72011-03-27 16:47:391115 return results
[email protected]1f7b4172010-01-28 01:17:341116
[email protected]b337cb5b2011-01-23 21:24:051117
1118def _CheckSubversionConfig(input_api, output_api):
1119 """Verifies the subversion config file is correctly setup.
1120
1121 Checks that autoprops are enabled, returns an error otherwise.
1122 """
1123 join = input_api.os_path.join
1124 if input_api.platform == 'win32':
1125 appdata = input_api.environ.get('APPDATA', '')
1126 if not appdata:
1127 return [output_api.PresubmitError('%APPDATA% is not configured.')]
1128 path = join(appdata, 'Subversion', 'config')
1129 else:
1130 home = input_api.environ.get('HOME', '')
1131 if not home:
1132 return [output_api.PresubmitError('$HOME is not configured.')]
1133 path = join(home, '.subversion', 'config')
1134
1135 error_msg = (
1136 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1137 'configure your subversion configuration file. This enables automatic\n'
[email protected]c6a3c10b2011-01-24 16:14:201138 'properties to simplify the project maintenance.\n'
1139 'Pro-tip: just download and install\n'
1140 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
[email protected]b337cb5b2011-01-23 21:24:051141
1142 try:
1143 lines = open(path, 'r').read().splitlines()
1144 # Make sure auto-props is enabled and check for 2 Chromium standard
1145 # auto-prop.
1146 if (not '*.cc = svn:eol-style=LF' in lines or
1147 not '*.pdf = svn:mime-type=application/pdf' in lines or
1148 not 'enable-auto-props = yes' in lines):
1149 return [
[email protected]79ed7e62011-02-21 21:08:531150 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:051151 'It looks like you have not configured your subversion config '
[email protected]b5359c02011-02-01 20:29:561152 'file or it is not up-to-date.\n' + error_msg)
[email protected]b337cb5b2011-01-23 21:24:051153 ]
1154 except (OSError, IOError):
1155 return [
[email protected]79ed7e62011-02-21 21:08:531156 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:051157 'Can\'t find your subversion config file.\n' + error_msg)
1158 ]
1159 return []
1160
1161
[email protected]66daa702011-05-28 14:41:461162def _CheckAuthorizedAuthor(input_api, output_api):
1163 """For non-googler/chromites committers, verify the author's email address is
1164 in AUTHORS.
1165 """
[email protected]9bb9cb82011-06-13 20:43:011166 # TODO(maruel): Add it to input_api?
1167 import fnmatch
1168
[email protected]66daa702011-05-28 14:41:461169 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:011170 if not author:
1171 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:461172 return []
[email protected]c99663292011-05-31 19:46:081173 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:461174 input_api.PresubmitLocalPath(), 'AUTHORS')
1175 valid_authors = (
1176 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1177 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:181178 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]d8b50be2011-06-15 14:19:441179 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]5861efb2013-01-07 18:33:231180 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
[email protected]66daa702011-05-28 14:41:461181 return [output_api.PresubmitPromptWarning(
1182 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1183 '\n'
1184 'http://www.chromium.org/developers/contributing-code and read the '
1185 '"Legal" section\n'
1186 'If you are a chromite, verify the contributor signed the CLA.') %
1187 author)]
1188 return []
1189
1190
[email protected]b8079ae4a2012-12-05 19:56:491191def _CheckPatchFiles(input_api, output_api):
1192 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1193 if f.LocalPath().endswith(('.orig', '.rej'))]
1194 if problems:
1195 return [output_api.PresubmitError(
1196 "Don't commit .rej and .orig files.", problems)]
[email protected]2fdd1f362013-01-16 03:56:031197 else:
1198 return []
[email protected]b8079ae4a2012-12-05 19:56:491199
1200
[email protected]b00342e7f2013-03-26 16:21:541201def _DidYouMeanOSMacro(bad_macro):
1202 try:
1203 return {'A': 'OS_ANDROID',
1204 'B': 'OS_BSD',
1205 'C': 'OS_CHROMEOS',
1206 'F': 'OS_FREEBSD',
1207 'L': 'OS_LINUX',
1208 'M': 'OS_MACOSX',
1209 'N': 'OS_NACL',
1210 'O': 'OS_OPENBSD',
1211 'P': 'OS_POSIX',
1212 'S': 'OS_SOLARIS',
1213 'W': 'OS_WIN'}[bad_macro[3].upper()]
1214 except KeyError:
1215 return ''
1216
1217
1218def _CheckForInvalidOSMacrosInFile(input_api, f):
1219 """Check for sensible looking, totally invalid OS macros."""
1220 preprocessor_statement = input_api.re.compile(r'^\s*#')
1221 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1222 results = []
1223 for lnum, line in f.ChangedContents():
1224 if preprocessor_statement.search(line):
1225 for match in os_macro.finditer(line):
1226 if not match.group(1) in _VALID_OS_MACROS:
1227 good = _DidYouMeanOSMacro(match.group(1))
1228 did_you_mean = ' (did you mean %s?)' % good if good else ''
1229 results.append(' %s:%d %s%s' % (f.LocalPath(),
1230 lnum,
1231 match.group(1),
1232 did_you_mean))
1233 return results
1234
1235
1236def _CheckForInvalidOSMacros(input_api, output_api):
1237 """Check all affected files for invalid OS macros."""
1238 bad_macros = []
1239 for f in input_api.AffectedFiles():
1240 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1241 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1242
1243 if not bad_macros:
1244 return []
1245
1246 return [output_api.PresubmitError(
1247 'Possibly invalid OS macro[s] found. Please fix your code\n'
1248 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1249
1250
[email protected]1f7b4172010-01-28 01:17:341251def CheckChangeOnUpload(input_api, output_api):
1252 results = []
1253 results.extend(_CommonChecks(input_api, output_api))
[email protected]ae69ae72014-02-20 13:09:361254 results.extend(_CheckJavaStyle(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541255 return results
[email protected]ca8d1982009-02-19 16:33:121256
1257
[email protected]38c6a512013-12-18 23:48:011258def GetDefaultTryConfigs(bots=None):
1259 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1260
1261 To add tests to this list, they MUST be in the the corresponding master's
1262 gatekeeper config. For example, anything on master.chromium would be closed by
1263 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1264
1265 If 'bots' is specified, will only return configurations for bots in that list.
1266 """
1267
1268 standard_tests = [
1269 'base_unittests',
1270 'browser_tests',
1271 'cacheinvalidation_unittests',
1272 'check_deps',
1273 'check_deps2git',
1274 'content_browsertests',
1275 'content_unittests',
1276 'crypto_unittests',
[email protected]38c6a512013-12-18 23:48:011277 'gpu_unittests',
1278 'interactive_ui_tests',
1279 'ipc_tests',
1280 'jingle_unittests',
1281 'media_unittests',
1282 'net_unittests',
1283 'ppapi_unittests',
1284 'printing_unittests',
1285 'sql_unittests',
1286 'sync_unit_tests',
1287 'unit_tests',
1288 # Broken in release.
1289 #'url_unittests',
1290 #'webkit_unit_tests',
1291 ]
1292
[email protected]38c6a512013-12-18 23:48:011293 builders_and_tests = {
1294 # TODO(maruel): Figure out a way to run 'sizes' where people can
1295 # effectively update the perf expectation correctly. This requires a
1296 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1297 # incremental build. Reference:
1298 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1299 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1300 # of this step as a try job failure.
1301 'android_aosp': ['compile'],
1302 'android_clang_dbg': ['slave_steps'],
1303 'android_dbg': ['slave_steps'],
1304 'cros_x86': ['defaulttests'],
1305 'ios_dbg_simulator': [
1306 'compile',
1307 'base_unittests',
1308 'content_unittests',
1309 'crypto_unittests',
1310 'url_unittests',
1311 'net_unittests',
1312 'sql_unittests',
1313 'ui_unittests',
1314 ],
1315 'ios_rel_device': ['compile'],
[email protected]971b08ce2014-03-19 22:03:561316 'linux_asan': ['compile'],
1317 'mac_asan': ['compile'],
[email protected]38c6a512013-12-18 23:48:011318 #TODO(stip): Change the name of this builder to reflect that it's release.
[email protected]71afb4ec2014-02-07 02:45:131319 'linux_gtk': standard_tests,
[email protected]971b08ce2014-03-19 22:03:561320 'linux_chromeos_asan': ['compile'],
[email protected]d910b6082014-02-27 18:15:431321 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
1322 'linux_chromium_chromeos_rel': ['defaulttests'],
1323 'linux_chromium_compile_dbg': ['defaulttests'],
[email protected]23c81d552014-01-07 13:45:461324 'linux_chromium_rel': ['defaulttests'],
[email protected]d910b6082014-02-27 18:15:431325 'linux_chromium_clang_dbg': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021326 'linux_nacl_sdk_build': ['compile'],
[email protected]d910b6082014-02-27 18:15:431327 'linux_rel': [
[email protected]9021a5f72014-01-24 19:02:381328 'telemetry_perf_unittests',
1329 'telemetry_unittests',
[email protected]38c6a512013-12-18 23:48:011330 ],
[email protected]d910b6082014-02-27 18:15:431331 'mac_chromium_compile_dbg': ['defaulttests'],
[email protected]23c81d552014-01-07 13:45:461332 'mac_chromium_rel': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021333 'mac_nacl_sdk_build': ['compile'],
[email protected]d910b6082014-02-27 18:15:431334 'mac_rel': [
[email protected]9021a5f72014-01-24 19:02:381335 'telemetry_perf_unittests',
[email protected]38c6a512013-12-18 23:48:011336 'telemetry_unittests',
1337 ],
1338 'win': ['compile'],
[email protected]0094fa12014-03-13 03:18:281339 'win_chromium_compile_dbg': ['defaulttests'],
[email protected]c17144e42014-04-15 09:32:431340 'win_chromium_dbg': ['defaulttests'],
1341 'win_chromium_rel': ['defaulttests'],
[email protected]2a207162014-04-15 17:05:301342 'win_chromium_x64_rel': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021343 'win_nacl_sdk_build': ['compile'],
[email protected]38c6a512013-12-18 23:48:011344 'win_rel': standard_tests + [
1345 'app_list_unittests',
1346 'ash_unittests',
1347 'aura_unittests',
1348 'cc_unittests',
1349 'chrome_elf_unittests',
[email protected]5d0413fc2014-01-03 18:24:301350 'chromedriver_unittests',
[email protected]38c6a512013-12-18 23:48:011351 'components_unittests',
1352 'compositor_unittests',
1353 'events_unittests',
[email protected]0df555e2014-02-27 14:53:111354 'gfx_unittests',
[email protected]38c6a512013-12-18 23:48:011355 'google_apis_unittests',
1356 'installer_util_unittests',
1357 'mini_installer_test',
1358 'nacl_integration',
1359 'remoting_unittests',
1360 'sync_integration_tests',
[email protected]9021a5f72014-01-24 19:02:381361 'telemetry_perf_unittests',
[email protected]38c6a512013-12-18 23:48:011362 'telemetry_unittests',
1363 'views_unittests',
1364 ],
1365 'win_x64_rel': [
1366 'base_unittests',
1367 ],
1368 }
1369
1370 swarm_enabled_builders = (
[email protected]9714f3b2014-03-20 19:50:111371 # http://crbug.com/354263
1372 # 'linux_rel',
1373 # 'mac_rel',
1374 # 'win_rel',
[email protected]38c6a512013-12-18 23:48:011375 )
1376
1377 swarm_enabled_tests = (
1378 'base_unittests',
1379 'browser_tests',
1380 'interactive_ui_tests',
1381 'net_unittests',
1382 'unit_tests',
1383 )
1384
1385 for bot in builders_and_tests:
1386 if bot in swarm_enabled_builders:
1387 builders_and_tests[bot] = [x + '_swarm' if x in swarm_enabled_tests else x
1388 for x in builders_and_tests[bot]]
1389
1390 if bots:
[email protected]7468ac522014-03-12 23:35:571391 return {
1392 'tryserver.chromium': dict((bot, set(builders_and_tests[bot]))
1393 for bot in bots)
1394 }
[email protected]38c6a512013-12-18 23:48:011395 else:
[email protected]7468ac522014-03-12 23:35:571396 return {
1397 'tryserver.chromium': dict(
1398 (bot, set(tests))
1399 for bot, tests in builders_and_tests.iteritems())
1400 }
[email protected]38c6a512013-12-18 23:48:011401
1402
[email protected]ca8d1982009-02-19 16:33:121403def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:541404 results = []
[email protected]1f7b4172010-01-28 01:17:341405 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:511406 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1407 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1408 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:541409 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:271410 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:341411 input_api,
1412 output_api,
[email protected]2fdd1f362013-01-16 03:56:031413 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:271414
[email protected]3e4eb112011-01-18 03:29:541415 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1416 input_api, output_api))
[email protected]c4b47562011-12-05 23:39:411417 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1418 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:051419 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541420 return results
[email protected]ca8d1982009-02-19 16:33:121421
1422
[email protected]7468ac522014-03-12 23:35:571423def GetPreferredTryMasters(project, change):
[email protected]4ce995ea2012-06-27 02:13:101424 files = change.LocalPaths()
1425
[email protected]751b05f2013-01-10 23:12:171426 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571427 return {}
[email protected]3019c902012-06-29 00:09:031428
[email protected]d668899a2012-09-06 18:16:591429 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
[email protected]d96b1f42014-02-27 19:17:521430 return GetDefaultTryConfigs([
1431 'mac_chromium_compile_dbg',
1432 'mac_chromium_rel',
[email protected]d96b1f42014-02-27 19:17:521433 ])
[email protected]d668899a2012-09-06 18:16:591434 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
[email protected]c17144e42014-04-15 09:32:431435 return GetDefaultTryConfigs(['win_chromium_dbg', 'win_chromium_rel'])
[email protected]d668899a2012-09-06 18:16:591436 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011437 return GetDefaultTryConfigs([
1438 'android_aosp',
1439 'android_clang_dbg',
1440 'android_dbg',
1441 ])
[email protected]de142152012-10-03 23:02:451442 if all(re.search('[/_]ios[/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011443 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
[email protected]4ce995ea2012-06-27 02:13:101444
[email protected]7468ac522014-03-12 23:35:571445 builders = [
[email protected]3e2f0402012-11-02 16:28:011446 'android_clang_dbg',
1447 'android_dbg',
1448 'ios_dbg_simulator',
1449 'ios_rel_device',
[email protected]d96b1f42014-02-27 19:17:521450 'linux_chromium_chromeos_rel',
1451 'linux_chromium_clang_dbg',
[email protected]d96b1f42014-02-27 19:17:521452 'linux_chromium_rel',
[email protected]d96b1f42014-02-27 19:17:521453 'mac_chromium_compile_dbg',
[email protected]d96b1f42014-02-27 19:17:521454 'mac_chromium_rel',
[email protected]0094fa12014-03-13 03:18:281455 'win_chromium_compile_dbg',
[email protected]c17144e42014-04-15 09:32:431456 'win_chromium_rel',
[email protected]2a207162014-04-15 17:05:301457 'win_chromium_x64_rel',
[email protected]7468ac522014-03-12 23:35:571458 ]
[email protected]911753b2012-08-02 12:11:541459
1460 # Match things like path/aura/file.cc and path/file_aura.cc.
[email protected]95c989162012-11-29 05:58:251461 # Same for chromeos.
1462 if any(re.search('[/_](aura|chromeos)', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571463 builders.extend([
1464 'linux_chromeos_asan',
1465 'linux_chromium_chromeos_clang_dbg'
1466 ])
[email protected]4ce995ea2012-06-27 02:13:101467
[email protected]e8df48f2013-09-30 20:07:541468 # If there are gyp changes to base, build, or chromeos, run a full cros build
1469 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1470 # files have a much higher chance of breaking the cros build, which is
1471 # differnt from the linux_chromeos build that most chrome developers test
1472 # with.
1473 if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571474 builders.extend(['cros_x86'])
[email protected]e8df48f2013-09-30 20:07:541475
[email protected]d95948ef2013-07-02 10:51:001476 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1477 # unless they're .gyp(i) files as changes to those files can break the gyp
1478 # step on that bot.
1479 if (not all(re.search('^chrome', f) for f in files) or
1480 any(re.search('\.gypi?$', f) for f in files)):
[email protected]7468ac522014-03-12 23:35:571481 builders.extend(['android_aosp'])
[email protected]d95948ef2013-07-02 10:51:001482
[email protected]7468ac522014-03-12 23:35:571483 return GetDefaultTryConfigs(builders)