blob: 49a366598cfab3ac04b213052409fad3b6251ad2 [file] [log] [blame]
[email protected]a18130a2012-01-03 17:52:081# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ca8d19842009-02-19 16:33:122# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Top-level presubmit script for Chromium.
6
[email protected]f1293792009-07-31 18:09:567See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
[email protected]50d7d721e2009-11-15 17:56:188for more details about the presubmit API built into gcl.
[email protected]ca8d19842009-02-19 16:33:129"""
10
[email protected]eea609a2011-11-18 13:10:1211
[email protected]9d16ad12011-12-14 20:49:4712import re
[email protected]fbcafe5a2012-08-08 15:31:2213import subprocess
[email protected]55f9f382012-07-31 11:02:1814import sys
[email protected]9d16ad12011-12-14 20:49:4715
16
[email protected]379e7dd2010-01-28 17:39:2117_EXCLUDED_PATHS = (
[email protected]3e4eb112011-01-18 03:29:5418 r"^breakpad[\\\/].*",
[email protected]40d1dbb2012-10-26 07:18:0019 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
20 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
[email protected]8886ffcb2013-02-12 04:56:2821 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
[email protected]a18130a2012-01-03 17:52:0822 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
[email protected]3e4eb112011-01-18 03:29:5423 r"^skia[\\\/].*",
24 r"^v8[\\\/].*",
25 r".*MakeFile$",
[email protected]1084ccc2012-03-14 03:22:5326 r".+_autogen\.h$",
[email protected]ce145c02012-09-06 09:49:3427 r".+[\\\/]pnacl_shim\.c$",
[email protected]e07b6ac72013-08-20 00:30:4228 r"^gpu[\\\/]config[\\\/].*_list_json\.cc$",
[email protected]4306417642009-06-11 00:33:4029)
[email protected]ca8d19842009-02-19 16:33:1230
[email protected]06e6d0ff2012-12-11 01:36:4431# Fragment of a regular expression that matches C++ and Objective-C++
32# implementation files.
33_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
34
35# Regular expression that matches code only used for test binaries
36# (best effort).
37_TEST_CODE_EXCLUDED_PATHS = (
38 r'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
39 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
[email protected]11e06082013-04-26 19:09:0340 r'.+_(api|browser|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
[email protected]e2d7e6f2013-04-23 12:57:1241 _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4442 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
43 r'.*[/\\](test|tool(s)?)[/\\].*',
[email protected]ef070cc2013-05-03 11:53:0544 # content_shell is used for running layout tests.
45 r'content[/\\]shell[/\\].*',
[email protected]06e6d0ff2012-12-11 01:36:4446 # At request of folks maintaining this folder.
47 r'chrome[/\\]browser[/\\]automation[/\\].*',
48)
[email protected]ca8d19842009-02-19 16:33:1249
[email protected]eea609a2011-11-18 13:10:1250_TEST_ONLY_WARNING = (
51 'You might be calling functions intended only for testing from\n'
52 'production code. It is OK to ignore this warning if you know what\n'
53 'you are doing, as the heuristics used to detect the situation are\n'
54 'not perfect. The commit queue will not block on this warning.\n'
55 'Email [email protected] if you have questions.')
56
57
[email protected]cf9b78f2012-11-14 11:40:2858_INCLUDE_ORDER_WARNING = (
59 'Your #include order seems to be broken. Send mail to\n'
60 '[email protected] if this is not the case.')
61
62
[email protected]127f18ec2012-06-16 05:05:5963_BANNED_OBJC_FUNCTIONS = (
64 (
65 'addTrackingRect:',
[email protected]23e6cbc2012-06-16 18:51:2066 (
67 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
[email protected]127f18ec2012-06-16 05:05:5968 'prohibited. Please use CrTrackingArea instead.',
69 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
70 ),
71 False,
72 ),
73 (
74 'NSTrackingArea',
[email protected]23e6cbc2012-06-16 18:51:2075 (
76 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
[email protected]127f18ec2012-06-16 05:05:5977 'instead.',
78 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
79 ),
80 False,
81 ),
82 (
83 'convertPointFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2084 (
85 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5986 'Please use |convertPoint:(point) fromView:nil| instead.',
87 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
88 ),
89 True,
90 ),
91 (
92 'convertPointToBase:',
[email protected]23e6cbc2012-06-16 18:51:2093 (
94 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5995 'Please use |convertPoint:(point) toView:nil| instead.',
96 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
97 ),
98 True,
99 ),
100 (
101 'convertRectFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20102 (
103 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59104 'Please use |convertRect:(point) fromView:nil| instead.',
105 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
106 ),
107 True,
108 ),
109 (
110 'convertRectToBase:',
[email protected]23e6cbc2012-06-16 18:51:20111 (
112 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59113 'Please use |convertRect:(point) toView:nil| instead.',
114 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
115 ),
116 True,
117 ),
118 (
119 'convertSizeFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20120 (
121 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59122 'Please use |convertSize:(point) fromView:nil| instead.',
123 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
124 ),
125 True,
126 ),
127 (
128 'convertSizeToBase:',
[email protected]23e6cbc2012-06-16 18:51:20129 (
130 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59131 'Please use |convertSize:(point) toView:nil| instead.',
132 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
133 ),
134 True,
135 ),
136)
137
138
139_BANNED_CPP_FUNCTIONS = (
[email protected]23e6cbc2012-06-16 18:51:20140 # Make sure that gtest's FRIEND_TEST() macro is not used; the
141 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
[email protected]e00ccc92012-11-01 17:32:30142 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
[email protected]23e6cbc2012-06-16 18:51:20143 (
144 'FRIEND_TEST(',
145 (
[email protected]e3c945502012-06-26 20:01:49146 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
[email protected]23e6cbc2012-06-16 18:51:20147 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
148 ),
149 False,
[email protected]7345da02012-11-27 14:31:49150 (),
[email protected]23e6cbc2012-06-16 18:51:20151 ),
152 (
153 'ScopedAllowIO',
154 (
[email protected]e3c945502012-06-26 20:01:49155 'New code should not use ScopedAllowIO. Post a task to the blocking',
156 'pool or the FILE thread instead.',
[email protected]23e6cbc2012-06-16 18:51:20157 ),
[email protected]e3c945502012-06-26 20:01:49158 True,
[email protected]7345da02012-11-27 14:31:49159 (
160 r"^content[\\\/]shell[\\\/]shell_browser_main\.cc$",
[email protected]398ad132013-04-02 15:11:01161 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
[email protected]7345da02012-11-27 14:31:49162 ),
[email protected]23e6cbc2012-06-16 18:51:20163 ),
[email protected]52657f62013-05-20 05:30:31164 (
165 'SkRefPtr',
166 (
167 'The use of SkRefPtr is prohibited. ',
168 'Please use skia::RefPtr instead.'
169 ),
170 True,
171 (),
172 ),
173 (
174 'SkAutoRef',
175 (
176 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
177 'Please use skia::RefPtr instead.'
178 ),
179 True,
180 (),
181 ),
182 (
183 'SkAutoTUnref',
184 (
185 'The use of SkAutoTUnref is dangerous because it implicitly ',
186 'converts to a raw pointer. Please use skia::RefPtr instead.'
187 ),
188 True,
189 (),
190 ),
191 (
192 'SkAutoUnref',
193 (
194 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
195 'because it implicitly converts to a raw pointer. ',
196 'Please use skia::RefPtr instead.'
197 ),
198 True,
199 (),
200 ),
[email protected]127f18ec2012-06-16 05:05:59201)
202
203
[email protected]b00342e7f2013-03-26 16:21:54204_VALID_OS_MACROS = (
205 # Please keep sorted.
206 'OS_ANDROID',
207 'OS_BSD',
208 'OS_CAT', # For testing.
209 'OS_CHROMEOS',
210 'OS_FREEBSD',
211 'OS_IOS',
212 'OS_LINUX',
213 'OS_MACOSX',
214 'OS_NACL',
215 'OS_OPENBSD',
216 'OS_POSIX',
217 'OS_SOLARIS',
[email protected]b00342e7f2013-03-26 16:21:54218 'OS_WIN',
219)
220
221
[email protected]55459852011-08-10 15:17:19222def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
223 """Attempts to prevent use of functions intended only for testing in
224 non-testing code. For now this is just a best-effort implementation
225 that ignores header files and may have some false positives. A
226 better implementation would probably need a proper C++ parser.
227 """
228 # We only scan .cc files and the like, as the declaration of
229 # for-testing functions in header files are hard to distinguish from
230 # calls to such functions without a proper C++ parser.
[email protected]06e6d0ff2012-12-11 01:36:44231 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
[email protected]55459852011-08-10 15:17:19232
233 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
234 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
[email protected]de4f7d22013-05-23 14:27:46235 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
[email protected]55459852011-08-10 15:17:19236 exclusion_pattern = input_api.re.compile(
237 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
238 base_function_pattern, base_function_pattern))
239
240 def FilterFile(affected_file):
[email protected]06e6d0ff2012-12-11 01:36:44241 black_list = (_EXCLUDED_PATHS +
242 _TEST_CODE_EXCLUDED_PATHS +
243 input_api.DEFAULT_BLACK_LIST)
[email protected]55459852011-08-10 15:17:19244 return input_api.FilterSourceFile(
245 affected_file,
246 white_list=(file_inclusion_pattern, ),
247 black_list=black_list)
248
249 problems = []
250 for f in input_api.AffectedSourceFiles(FilterFile):
251 local_path = f.LocalPath()
[email protected]2fdd1f362013-01-16 03:56:03252 lines = input_api.ReadFile(f).splitlines()
253 line_number = 0
254 for line in lines:
255 if (inclusion_pattern.search(line) and
[email protected]de4f7d22013-05-23 14:27:46256 not comment_pattern.search(line) and
[email protected]2fdd1f362013-01-16 03:56:03257 not exclusion_pattern.search(line)):
[email protected]55459852011-08-10 15:17:19258 problems.append(
[email protected]2fdd1f362013-01-16 03:56:03259 '%s:%d\n %s' % (local_path, line_number, line.strip()))
260 line_number += 1
[email protected]55459852011-08-10 15:17:19261
262 if problems:
[email protected]f7051d52013-04-02 18:31:42263 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
[email protected]2fdd1f362013-01-16 03:56:03264 else:
265 return []
[email protected]55459852011-08-10 15:17:19266
267
[email protected]10689ca2011-09-02 02:31:54268def _CheckNoIOStreamInHeaders(input_api, output_api):
269 """Checks to make sure no .h files include <iostream>."""
270 files = []
271 pattern = input_api.re.compile(r'^#include\s*<iostream>',
272 input_api.re.MULTILINE)
273 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
274 if not f.LocalPath().endswith('.h'):
275 continue
276 contents = input_api.ReadFile(f)
277 if pattern.search(contents):
278 files.append(f)
279
280 if len(files):
281 return [ output_api.PresubmitError(
[email protected]6c063c62012-07-11 19:11:06282 'Do not #include <iostream> in header files, since it inserts static '
283 'initialization into every file including the header. Instead, '
[email protected]10689ca2011-09-02 02:31:54284 '#include <ostream>. See http://crbug.com/94794',
285 files) ]
286 return []
287
288
[email protected]72df4e782012-06-21 16:28:18289def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
290 """Checks to make sure no source files use UNIT_TEST"""
291 problems = []
292 for f in input_api.AffectedFiles():
293 if (not f.LocalPath().endswith(('.cc', '.mm'))):
294 continue
295
296 for line_num, line in f.ChangedContents():
297 if 'UNIT_TEST' in line:
298 problems.append(' %s:%d' % (f.LocalPath(), line_num))
299
300 if not problems:
301 return []
302 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
303 '\n'.join(problems))]
304
305
[email protected]8ea5d4b2011-09-13 21:49:22306def _CheckNoNewWStrings(input_api, output_api):
307 """Checks to make sure we don't introduce use of wstrings."""
[email protected]55463aa62011-10-12 00:48:27308 problems = []
[email protected]8ea5d4b2011-09-13 21:49:22309 for f in input_api.AffectedFiles():
[email protected]b5c24292011-11-28 14:38:20310 if (not f.LocalPath().endswith(('.cc', '.h')) or
311 f.LocalPath().endswith('test.cc')):
312 continue
[email protected]8ea5d4b2011-09-13 21:49:22313
[email protected]a11dbe9b2012-08-07 01:32:58314 allowWString = False
[email protected]b5c24292011-11-28 14:38:20315 for line_num, line in f.ChangedContents():
[email protected]a11dbe9b2012-08-07 01:32:58316 if 'presubmit: allow wstring' in line:
317 allowWString = True
318 elif not allowWString and 'wstring' in line:
[email protected]55463aa62011-10-12 00:48:27319 problems.append(' %s:%d' % (f.LocalPath(), line_num))
[email protected]a11dbe9b2012-08-07 01:32:58320 allowWString = False
321 else:
322 allowWString = False
[email protected]8ea5d4b2011-09-13 21:49:22323
[email protected]55463aa62011-10-12 00:48:27324 if not problems:
325 return []
326 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
[email protected]a11dbe9b2012-08-07 01:32:58327 ' If you are calling a cross-platform API that accepts a wstring, '
328 'fix the API.\n' +
[email protected]55463aa62011-10-12 00:48:27329 '\n'.join(problems))]
[email protected]8ea5d4b2011-09-13 21:49:22330
331
[email protected]2a8ac9c2011-10-19 17:20:44332def _CheckNoDEPSGIT(input_api, output_api):
333 """Make sure .DEPS.git is never modified manually."""
334 if any(f.LocalPath().endswith('.DEPS.git') for f in
335 input_api.AffectedFiles()):
336 return [output_api.PresubmitError(
337 'Never commit changes to .DEPS.git. This file is maintained by an\n'
338 'automated system based on what\'s in DEPS and your changes will be\n'
339 'overwritten.\n'
340 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
341 'for more information')]
342 return []
343
344
[email protected]127f18ec2012-06-16 05:05:59345def _CheckNoBannedFunctions(input_api, output_api):
346 """Make sure that banned functions are not used."""
347 warnings = []
348 errors = []
349
350 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
351 for f in input_api.AffectedFiles(file_filter=file_filter):
352 for line_num, line in f.ChangedContents():
353 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
354 if func_name in line:
355 problems = warnings;
356 if error:
357 problems = errors;
358 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
359 for message_line in message:
360 problems.append(' %s' % message_line)
361
362 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
363 for f in input_api.AffectedFiles(file_filter=file_filter):
364 for line_num, line in f.ChangedContents():
[email protected]7345da02012-11-27 14:31:49365 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
366 def IsBlacklisted(affected_file, blacklist):
367 local_path = affected_file.LocalPath()
368 for item in blacklist:
369 if input_api.re.match(item, local_path):
370 return True
371 return False
372 if IsBlacklisted(f, excluded_paths):
373 continue
[email protected]127f18ec2012-06-16 05:05:59374 if func_name in line:
375 problems = warnings;
376 if error:
377 problems = errors;
378 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
379 for message_line in message:
380 problems.append(' %s' % message_line)
381
382 result = []
383 if (warnings):
384 result.append(output_api.PresubmitPromptWarning(
385 'Banned functions were used.\n' + '\n'.join(warnings)))
386 if (errors):
387 result.append(output_api.PresubmitError(
388 'Banned functions were used.\n' + '\n'.join(errors)))
389 return result
390
391
[email protected]6c063c62012-07-11 19:11:06392def _CheckNoPragmaOnce(input_api, output_api):
393 """Make sure that banned functions are not used."""
394 files = []
395 pattern = input_api.re.compile(r'^#pragma\s+once',
396 input_api.re.MULTILINE)
397 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
398 if not f.LocalPath().endswith('.h'):
399 continue
400 contents = input_api.ReadFile(f)
401 if pattern.search(contents):
402 files.append(f)
403
404 if files:
405 return [output_api.PresubmitError(
406 'Do not use #pragma once in header files.\n'
407 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
408 files)]
409 return []
410
[email protected]127f18ec2012-06-16 05:05:59411
[email protected]e7479052012-09-19 00:26:12412def _CheckNoTrinaryTrueFalse(input_api, output_api):
413 """Checks to make sure we don't introduce use of foo ? true : false."""
414 problems = []
415 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
416 for f in input_api.AffectedFiles():
417 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
418 continue
419
420 for line_num, line in f.ChangedContents():
421 if pattern.match(line):
422 problems.append(' %s:%d' % (f.LocalPath(), line_num))
423
424 if not problems:
425 return []
426 return [output_api.PresubmitPromptWarning(
427 'Please consider avoiding the "? true : false" pattern if possible.\n' +
428 '\n'.join(problems))]
429
430
[email protected]55f9f382012-07-31 11:02:18431def _CheckUnwantedDependencies(input_api, output_api):
432 """Runs checkdeps on #include statements added in this
433 change. Breaking - rules is an error, breaking ! rules is a
434 warning.
435 """
436 # We need to wait until we have an input_api object and use this
437 # roundabout construct to import checkdeps because this file is
438 # eval-ed and thus doesn't have __file__.
439 original_sys_path = sys.path
440 try:
441 sys.path = sys.path + [input_api.os_path.join(
442 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
443 import checkdeps
444 from cpp_checker import CppChecker
445 from rules import Rule
446 finally:
447 # Restore sys.path to what it was before.
448 sys.path = original_sys_path
449
450 added_includes = []
451 for f in input_api.AffectedFiles():
452 if not CppChecker.IsCppFile(f.LocalPath()):
453 continue
454
455 changed_lines = [line for line_num, line in f.ChangedContents()]
456 added_includes.append([f.LocalPath(), changed_lines])
457
[email protected]26385172013-05-09 23:11:35458 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
[email protected]55f9f382012-07-31 11:02:18459
460 error_descriptions = []
461 warning_descriptions = []
462 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
463 added_includes):
464 description_with_path = '%s\n %s' % (path, rule_description)
465 if rule_type == Rule.DISALLOW:
466 error_descriptions.append(description_with_path)
467 else:
468 warning_descriptions.append(description_with_path)
469
470 results = []
471 if error_descriptions:
472 results.append(output_api.PresubmitError(
473 'You added one or more #includes that violate checkdeps rules.',
474 error_descriptions))
475 if warning_descriptions:
[email protected]f7051d52013-04-02 18:31:42476 results.append(output_api.PresubmitPromptOrNotify(
[email protected]55f9f382012-07-31 11:02:18477 'You added one or more #includes of files that are temporarily\n'
478 'allowed but being removed. Can you avoid introducing the\n'
479 '#include? See relevant DEPS file(s) for details and contacts.',
480 warning_descriptions))
481 return results
482
483
[email protected]fbcafe5a2012-08-08 15:31:22484def _CheckFilePermissions(input_api, output_api):
485 """Check that all files have their permissions properly set."""
486 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
487 input_api.change.RepositoryRoot()]
488 for f in input_api.AffectedFiles():
489 args += ['--file', f.LocalPath()]
490 errors = []
491 (errors, stderrdata) = subprocess.Popen(args).communicate()
492
493 results = []
494 if errors:
[email protected]c8278b32012-10-30 20:35:49495 results.append(output_api.PresubmitError('checkperms.py failed.',
[email protected]fbcafe5a2012-08-08 15:31:22496 errors))
497 return results
498
499
[email protected]c8278b32012-10-30 20:35:49500def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
501 """Makes sure we don't include ui/aura/window_property.h
502 in header files.
503 """
504 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
505 errors = []
506 for f in input_api.AffectedFiles():
507 if not f.LocalPath().endswith('.h'):
508 continue
509 for line_num, line in f.ChangedContents():
510 if pattern.match(line):
511 errors.append(' %s:%d' % (f.LocalPath(), line_num))
512
513 results = []
514 if errors:
515 results.append(output_api.PresubmitError(
516 'Header files should not include ui/aura/window_property.h', errors))
517 return results
518
519
[email protected]cf9b78f2012-11-14 11:40:28520def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
521 """Checks that the lines in scope occur in the right order.
522
523 1. C system files in alphabetical order
524 2. C++ system files in alphabetical order
525 3. Project's .h files
526 """
527
528 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
529 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
530 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
531
532 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
533
534 state = C_SYSTEM_INCLUDES
535
536 previous_line = ''
[email protected]728b9bb2012-11-14 20:38:57537 previous_line_num = 0
[email protected]cf9b78f2012-11-14 11:40:28538 problem_linenums = []
539 for line_num, line in scope:
540 if c_system_include_pattern.match(line):
541 if state != C_SYSTEM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57542 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28543 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57544 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28545 elif cpp_system_include_pattern.match(line):
546 if state == C_SYSTEM_INCLUDES:
547 state = CPP_SYSTEM_INCLUDES
548 elif state == CUSTOM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57549 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28550 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57551 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28552 elif custom_include_pattern.match(line):
553 if state != CUSTOM_INCLUDES:
554 state = CUSTOM_INCLUDES
555 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57556 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28557 else:
558 problem_linenums.append(line_num)
559 previous_line = line
[email protected]728b9bb2012-11-14 20:38:57560 previous_line_num = line_num
[email protected]cf9b78f2012-11-14 11:40:28561
562 warnings = []
[email protected]728b9bb2012-11-14 20:38:57563 for (line_num, previous_line_num) in problem_linenums:
564 if line_num in changed_linenums or previous_line_num in changed_linenums:
[email protected]cf9b78f2012-11-14 11:40:28565 warnings.append(' %s:%d' % (file_path, line_num))
566 return warnings
567
568
[email protected]ac294a12012-12-06 16:38:43569def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
[email protected]cf9b78f2012-11-14 11:40:28570 """Checks the #include order for the given file f."""
571
[email protected]2299dcf2012-11-15 19:56:24572 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
[email protected]962f117e2012-11-22 18:11:56573 # Exclude #include <.../...> includes from the check; e.g., <sys/...> includes
574 # often need to appear in a specific order.
575 excluded_include_pattern = input_api.re.compile(r'\s*#include \<.*/.*')
[email protected]2299dcf2012-11-15 19:56:24576 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
[email protected]0e5c1852012-12-18 20:17:11577 if_pattern = input_api.re.compile(
578 r'\s*#\s*(if|elif|else|endif|define|undef).*')
579 # Some files need specialized order of includes; exclude such files from this
580 # check.
581 uncheckable_includes_pattern = input_api.re.compile(
582 r'\s*#include '
583 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
[email protected]cf9b78f2012-11-14 11:40:28584
585 contents = f.NewContents()
586 warnings = []
587 line_num = 0
588
[email protected]ac294a12012-12-06 16:38:43589 # Handle the special first include. If the first include file is
590 # some/path/file.h, the corresponding including file can be some/path/file.cc,
591 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
592 # etc. It's also possible that no special first include exists.
593 for line in contents:
594 line_num += 1
595 if system_include_pattern.match(line):
596 # No special first include -> process the line again along with normal
597 # includes.
598 line_num -= 1
599 break
600 match = custom_include_pattern.match(line)
601 if match:
602 match_dict = match.groupdict()
603 header_basename = input_api.os_path.basename(
604 match_dict['FILE']).replace('.h', '')
605 if header_basename not in input_api.os_path.basename(f.LocalPath()):
[email protected]2299dcf2012-11-15 19:56:24606 # No special first include -> process the line again along with normal
607 # includes.
608 line_num -= 1
[email protected]ac294a12012-12-06 16:38:43609 break
[email protected]cf9b78f2012-11-14 11:40:28610
611 # Split into scopes: Each region between #if and #endif is its own scope.
612 scopes = []
613 current_scope = []
614 for line in contents[line_num:]:
615 line_num += 1
[email protected]0e5c1852012-12-18 20:17:11616 if uncheckable_includes_pattern.match(line):
617 return []
[email protected]2309b0fa02012-11-16 12:18:27618 if if_pattern.match(line):
[email protected]cf9b78f2012-11-14 11:40:28619 scopes.append(current_scope)
620 current_scope = []
[email protected]962f117e2012-11-22 18:11:56621 elif ((system_include_pattern.match(line) or
622 custom_include_pattern.match(line)) and
623 not excluded_include_pattern.match(line)):
[email protected]cf9b78f2012-11-14 11:40:28624 current_scope.append((line_num, line))
625 scopes.append(current_scope)
626
627 for scope in scopes:
628 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
629 changed_linenums))
630 return warnings
631
632
633def _CheckIncludeOrder(input_api, output_api):
634 """Checks that the #include order is correct.
635
636 1. The corresponding header for source files.
637 2. C system files in alphabetical order
638 3. C++ system files in alphabetical order
639 4. Project's .h files in alphabetical order
640
[email protected]ac294a12012-12-06 16:38:43641 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
642 these rules separately.
[email protected]cf9b78f2012-11-14 11:40:28643 """
644
645 warnings = []
646 for f in input_api.AffectedFiles():
[email protected]ac294a12012-12-06 16:38:43647 if f.LocalPath().endswith(('.cc', '.h')):
648 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
649 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
[email protected]cf9b78f2012-11-14 11:40:28650
651 results = []
652 if warnings:
[email protected]f7051d52013-04-02 18:31:42653 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
[email protected]120cf540d2012-12-10 17:55:53654 warnings))
[email protected]cf9b78f2012-11-14 11:40:28655 return results
656
657
[email protected]70ca77752012-11-20 03:45:03658def _CheckForVersionControlConflictsInFile(input_api, f):
659 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
660 errors = []
661 for line_num, line in f.ChangedContents():
662 if pattern.match(line):
663 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
664 return errors
665
666
667def _CheckForVersionControlConflicts(input_api, output_api):
668 """Usually this is not intentional and will cause a compile failure."""
669 errors = []
670 for f in input_api.AffectedFiles():
671 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
672
673 results = []
674 if errors:
675 results.append(output_api.PresubmitError(
676 'Version control conflict markers found, please resolve.', errors))
677 return results
678
679
[email protected]06e6d0ff2012-12-11 01:36:44680def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
681 def FilterFile(affected_file):
682 """Filter function for use with input_api.AffectedSourceFiles,
683 below. This filters out everything except non-test files from
684 top-level directories that generally speaking should not hard-code
685 service URLs (e.g. src/android_webview/, src/content/ and others).
686 """
687 return input_api.FilterSourceFile(
688 affected_file,
[email protected]78bb39d62012-12-11 15:11:56689 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
[email protected]06e6d0ff2012-12-11 01:36:44690 black_list=(_EXCLUDED_PATHS +
691 _TEST_CODE_EXCLUDED_PATHS +
692 input_api.DEFAULT_BLACK_LIST))
693
[email protected]de4f7d22013-05-23 14:27:46694 base_pattern = '"[^"]*google\.com[^"]*"'
695 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
696 pattern = input_api.re.compile(base_pattern)
[email protected]06e6d0ff2012-12-11 01:36:44697 problems = [] # items are (filename, line_number, line)
698 for f in input_api.AffectedSourceFiles(FilterFile):
699 for line_num, line in f.ChangedContents():
[email protected]de4f7d22013-05-23 14:27:46700 if not comment_pattern.search(line) and pattern.search(line):
[email protected]06e6d0ff2012-12-11 01:36:44701 problems.append((f.LocalPath(), line_num, line))
702
703 if problems:
[email protected]f7051d52013-04-02 18:31:42704 return [output_api.PresubmitPromptOrNotify(
[email protected]06e6d0ff2012-12-11 01:36:44705 'Most layers below src/chrome/ should not hardcode service URLs.\n'
706 'Are you sure this is correct? (Contact: [email protected])',
707 [' %s:%d: %s' % (
708 problem[0], problem[1], problem[2]) for problem in problems])]
[email protected]2fdd1f362013-01-16 03:56:03709 else:
710 return []
[email protected]06e6d0ff2012-12-11 01:36:44711
712
[email protected]d2530012013-01-25 16:39:27713def _CheckNoAbbreviationInPngFileName(input_api, output_api):
714 """Makes sure there are no abbreviations in the name of PNG files.
715 """
[email protected]4053a48e2013-01-25 21:43:04716 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
[email protected]d2530012013-01-25 16:39:27717 errors = []
718 for f in input_api.AffectedFiles(include_deletes=False):
719 if pattern.match(f.LocalPath()):
720 errors.append(' %s' % f.LocalPath())
721
722 results = []
723 if errors:
724 results.append(output_api.PresubmitError(
725 'The name of PNG files should not have abbreviations. \n'
726 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
727 'Contact [email protected] if you have questions.', errors))
728 return results
729
730
[email protected]f32e2d1e2013-07-26 21:39:08731def _DepsFilesToCheck(re, changed_lines):
732 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
733 a set of DEPS entries that we should look up."""
734 results = set()
735
736 # This pattern grabs the path without basename in the first
737 # parentheses, and the basename (if present) in the second. It
738 # relies on the simple heuristic that if there is a basename it will
739 # be a header file ending in ".h".
740 pattern = re.compile(
741 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
742 for changed_line in changed_lines:
743 m = pattern.match(changed_line)
744 if m:
745 path = m.group(1)
746 if not (path.startswith('grit/') or path == 'grit'):
747 results.add('%s/DEPS' % m.group(1))
748 return results
749
750
[email protected]e871964c2013-05-13 14:14:55751def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
752 """When a dependency prefixed with + is added to a DEPS file, we
753 want to make sure that the change is reviewed by an OWNER of the
754 target file or directory, to avoid layering violations from being
755 introduced. This check verifies that this happens.
756 """
757 changed_lines = set()
758 for f in input_api.AffectedFiles():
759 filename = input_api.os_path.basename(f.LocalPath())
760 if filename == 'DEPS':
761 changed_lines |= set(line.strip()
762 for line_num, line
763 in f.ChangedContents())
764 if not changed_lines:
765 return []
766
[email protected]f32e2d1e2013-07-26 21:39:08767 virtual_depended_on_files = _DepsFilesToCheck(input_api.re, changed_lines)
[email protected]e871964c2013-05-13 14:14:55768 if not virtual_depended_on_files:
769 return []
770
771 if input_api.is_committing:
772 if input_api.tbr:
773 return [output_api.PresubmitNotifyResult(
774 '--tbr was specified, skipping OWNERS check for DEPS additions')]
775 if not input_api.change.issue:
776 return [output_api.PresubmitError(
777 "DEPS approval by OWNERS check failed: this change has "
778 "no Rietveld issue number, so we can't check it for approvals.")]
779 output = output_api.PresubmitError
780 else:
781 output = output_api.PresubmitNotifyResult
782
783 owners_db = input_api.owners_db
784 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
785 input_api,
786 owners_db.email_regexp,
787 approval_needed=input_api.is_committing)
788
789 owner_email = owner_email or input_api.change.author_email
790
[email protected]de4f7d22013-05-23 14:27:46791 reviewers_plus_owner = set(reviewers)
[email protected]e71c6082013-05-22 02:28:51792 if owner_email:
[email protected]de4f7d22013-05-23 14:27:46793 reviewers_plus_owner.add(owner_email)
[email protected]e871964c2013-05-13 14:14:55794 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
795 reviewers_plus_owner)
796 unapproved_dependencies = ["'+%s'," % path[:-len('/DEPS')]
797 for path in missing_files]
798
799 if unapproved_dependencies:
800 output_list = [
801 output('Missing LGTM from OWNERS of directories added to DEPS:\n %s' %
802 '\n '.join(sorted(unapproved_dependencies)))]
803 if not input_api.is_committing:
804 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
805 output_list.append(output(
806 'Suggested missing target path OWNERS:\n %s' %
807 '\n '.join(suggested_owners or [])))
808 return output_list
809
810 return []
811
812
[email protected]22c9bd72011-03-27 16:47:39813def _CommonChecks(input_api, output_api):
814 """Checks common to both upload and commit."""
815 results = []
816 results.extend(input_api.canned_checks.PanProjectChecks(
817 input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
[email protected]66daa702011-05-28 14:41:46818 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]55459852011-08-10 15:17:19819 results.extend(
820 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
[email protected]10689ca2011-09-02 02:31:54821 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
[email protected]72df4e782012-06-21 16:28:18822 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
[email protected]8ea5d4b2011-09-13 21:49:22823 results.extend(_CheckNoNewWStrings(input_api, output_api))
[email protected]2a8ac9c2011-10-19 17:20:44824 results.extend(_CheckNoDEPSGIT(input_api, output_api))
[email protected]127f18ec2012-06-16 05:05:59825 results.extend(_CheckNoBannedFunctions(input_api, output_api))
[email protected]6c063c62012-07-11 19:11:06826 results.extend(_CheckNoPragmaOnce(input_api, output_api))
[email protected]e7479052012-09-19 00:26:12827 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
[email protected]55f9f382012-07-31 11:02:18828 results.extend(_CheckUnwantedDependencies(input_api, output_api))
[email protected]fbcafe5a2012-08-08 15:31:22829 results.extend(_CheckFilePermissions(input_api, output_api))
[email protected]c8278b32012-10-30 20:35:49830 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
[email protected]2309b0fa02012-11-16 12:18:27831 results.extend(_CheckIncludeOrder(input_api, output_api))
[email protected]70ca77752012-11-20 03:45:03832 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
[email protected]b8079ae4a2012-12-05 19:56:49833 results.extend(_CheckPatchFiles(input_api, output_api))
[email protected]06e6d0ff2012-12-11 01:36:44834 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
[email protected]d2530012013-01-25 16:39:27835 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
[email protected]b00342e7f2013-03-26 16:21:54836 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
[email protected]e871964c2013-05-13 14:14:55837 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
[email protected]9f919cc2013-07-31 03:04:04838 results.extend(
839 input_api.canned_checks.CheckChangeHasNoTabs(
840 input_api,
841 output_api,
842 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
[email protected]2299dcf2012-11-15 19:56:24843
844 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
845 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
846 input_api, output_api,
847 input_api.PresubmitLocalPath(),
[email protected]6be63382013-01-21 15:42:38848 whitelist=[r'^PRESUBMIT_test\.py$']))
[email protected]22c9bd72011-03-27 16:47:39849 return results
[email protected]1f7b4172010-01-28 01:17:34850
[email protected]b337cb5b2011-01-23 21:24:05851
852def _CheckSubversionConfig(input_api, output_api):
853 """Verifies the subversion config file is correctly setup.
854
855 Checks that autoprops are enabled, returns an error otherwise.
856 """
857 join = input_api.os_path.join
858 if input_api.platform == 'win32':
859 appdata = input_api.environ.get('APPDATA', '')
860 if not appdata:
861 return [output_api.PresubmitError('%APPDATA% is not configured.')]
862 path = join(appdata, 'Subversion', 'config')
863 else:
864 home = input_api.environ.get('HOME', '')
865 if not home:
866 return [output_api.PresubmitError('$HOME is not configured.')]
867 path = join(home, '.subversion', 'config')
868
869 error_msg = (
870 'Please look at http://dev.chromium.org/developers/coding-style to\n'
871 'configure your subversion configuration file. This enables automatic\n'
[email protected]c6a3c10b2011-01-24 16:14:20872 'properties to simplify the project maintenance.\n'
873 'Pro-tip: just download and install\n'
874 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
[email protected]b337cb5b2011-01-23 21:24:05875
876 try:
877 lines = open(path, 'r').read().splitlines()
878 # Make sure auto-props is enabled and check for 2 Chromium standard
879 # auto-prop.
880 if (not '*.cc = svn:eol-style=LF' in lines or
881 not '*.pdf = svn:mime-type=application/pdf' in lines or
882 not 'enable-auto-props = yes' in lines):
883 return [
[email protected]79ed7e62011-02-21 21:08:53884 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:05885 'It looks like you have not configured your subversion config '
[email protected]b5359c02011-02-01 20:29:56886 'file or it is not up-to-date.\n' + error_msg)
[email protected]b337cb5b2011-01-23 21:24:05887 ]
888 except (OSError, IOError):
889 return [
[email protected]79ed7e62011-02-21 21:08:53890 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:05891 'Can\'t find your subversion config file.\n' + error_msg)
892 ]
893 return []
894
895
[email protected]66daa702011-05-28 14:41:46896def _CheckAuthorizedAuthor(input_api, output_api):
897 """For non-googler/chromites committers, verify the author's email address is
898 in AUTHORS.
899 """
[email protected]9bb9cb82011-06-13 20:43:01900 # TODO(maruel): Add it to input_api?
901 import fnmatch
902
[email protected]66daa702011-05-28 14:41:46903 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:01904 if not author:
905 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:46906 return []
[email protected]c99663292011-05-31 19:46:08907 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:46908 input_api.PresubmitLocalPath(), 'AUTHORS')
909 valid_authors = (
910 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
911 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:18912 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]d8b50be2011-06-15 14:19:44913 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]5861efb2013-01-07 18:33:23914 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
[email protected]66daa702011-05-28 14:41:46915 return [output_api.PresubmitPromptWarning(
916 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
917 '\n'
918 'http://www.chromium.org/developers/contributing-code and read the '
919 '"Legal" section\n'
920 'If you are a chromite, verify the contributor signed the CLA.') %
921 author)]
922 return []
923
924
[email protected]b8079ae4a2012-12-05 19:56:49925def _CheckPatchFiles(input_api, output_api):
926 problems = [f.LocalPath() for f in input_api.AffectedFiles()
927 if f.LocalPath().endswith(('.orig', '.rej'))]
928 if problems:
929 return [output_api.PresubmitError(
930 "Don't commit .rej and .orig files.", problems)]
[email protected]2fdd1f362013-01-16 03:56:03931 else:
932 return []
[email protected]b8079ae4a2012-12-05 19:56:49933
934
[email protected]b00342e7f2013-03-26 16:21:54935def _DidYouMeanOSMacro(bad_macro):
936 try:
937 return {'A': 'OS_ANDROID',
938 'B': 'OS_BSD',
939 'C': 'OS_CHROMEOS',
940 'F': 'OS_FREEBSD',
941 'L': 'OS_LINUX',
942 'M': 'OS_MACOSX',
943 'N': 'OS_NACL',
944 'O': 'OS_OPENBSD',
945 'P': 'OS_POSIX',
946 'S': 'OS_SOLARIS',
947 'W': 'OS_WIN'}[bad_macro[3].upper()]
948 except KeyError:
949 return ''
950
951
952def _CheckForInvalidOSMacrosInFile(input_api, f):
953 """Check for sensible looking, totally invalid OS macros."""
954 preprocessor_statement = input_api.re.compile(r'^\s*#')
955 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
956 results = []
957 for lnum, line in f.ChangedContents():
958 if preprocessor_statement.search(line):
959 for match in os_macro.finditer(line):
960 if not match.group(1) in _VALID_OS_MACROS:
961 good = _DidYouMeanOSMacro(match.group(1))
962 did_you_mean = ' (did you mean %s?)' % good if good else ''
963 results.append(' %s:%d %s%s' % (f.LocalPath(),
964 lnum,
965 match.group(1),
966 did_you_mean))
967 return results
968
969
970def _CheckForInvalidOSMacros(input_api, output_api):
971 """Check all affected files for invalid OS macros."""
972 bad_macros = []
973 for f in input_api.AffectedFiles():
974 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
975 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
976
977 if not bad_macros:
978 return []
979
980 return [output_api.PresubmitError(
981 'Possibly invalid OS macro[s] found. Please fix your code\n'
982 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
983
984
[email protected]1f7b4172010-01-28 01:17:34985def CheckChangeOnUpload(input_api, output_api):
986 results = []
987 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54988 return results
[email protected]ca8d19842009-02-19 16:33:12989
990
991def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54992 results = []
[email protected]1f7b4172010-01-28 01:17:34993 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:51994 # TODO(thestig) temporarily disabled, doesn't work in third_party/
995 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
996 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:54997 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:27998 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:34999 input_api,
1000 output_api,
[email protected]2fdd1f362013-01-16 03:56:031001 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:271002 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
[email protected]2fdd1f362013-01-16 03:56:031003 output_api, 'http://codereview.chromium.org',
[email protected]c1ba4c52012-03-09 14:23:281004 ('win_rel', 'linux_rel', 'mac_rel, win:compile'),
1005 '[email protected]'))
[email protected]806e98e2010-03-19 17:49:271006
[email protected]3e4eb112011-01-18 03:29:541007 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1008 input_api, output_api))
[email protected]c4b47562011-12-05 23:39:411009 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1010 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:051011 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541012 return results
[email protected]ca8d19842009-02-19 16:33:121013
1014
[email protected]5efb2a822011-09-27 23:06:131015def GetPreferredTrySlaves(project, change):
[email protected]4ce995ea2012-06-27 02:13:101016 files = change.LocalPaths()
1017
[email protected]751b05f2013-01-10 23:12:171018 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
[email protected]3019c902012-06-29 00:09:031019 return []
1020
[email protected]d668899a2012-09-06 18:16:591021 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
[email protected]5753cff2013-07-19 23:57:521022 return ['mac_rel', 'mac:compile']
[email protected]d668899a2012-09-06 18:16:591023 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
[email protected]7fab6202013-02-21 17:54:351024 return ['win_rel', 'win7_aura', 'win:compile']
[email protected]d668899a2012-09-06 18:16:591025 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
[email protected]d95948ef2013-07-02 10:51:001026 return ['android_aosp', 'android_dbg', 'android_clang_dbg']
[email protected]356aa542012-09-19 23:31:291027 if all(re.search('^native_client_sdk', f) for f in files):
1028 return ['linux_nacl_sdk', 'win_nacl_sdk', 'mac_nacl_sdk']
[email protected]de142152012-10-03 23:02:451029 if all(re.search('[/_]ios[/_.]', f) for f in files):
1030 return ['ios_rel_device', 'ios_dbg_simulator']
[email protected]4ce995ea2012-06-27 02:13:101031
[email protected]3e2f0402012-11-02 16:28:011032 trybots = [
1033 'android_clang_dbg',
1034 'android_dbg',
1035 'ios_dbg_simulator',
1036 'ios_rel_device',
1037 'linux_asan',
[email protected]95c989162012-11-29 05:58:251038 'linux_aura',
[email protected]3e2f0402012-11-02 16:28:011039 'linux_chromeos',
1040 'linux_clang:compile',
1041 'linux_rel',
[email protected]3e2f0402012-11-02 16:28:011042 'mac_rel',
[email protected]7fab6202013-02-21 17:54:351043 'mac:compile',
[email protected]aa85c8b2013-01-11 04:20:281044 'win7_aura',
[email protected]3e2f0402012-11-02 16:28:011045 'win_rel',
[email protected]7fab6202013-02-21 17:54:351046 'win:compile',
[email protected]24d870f2013-07-23 00:45:461047 'win_x64_rel:compile',
[email protected]3e2f0402012-11-02 16:28:011048 ]
[email protected]911753b2012-08-02 12:11:541049
1050 # Match things like path/aura/file.cc and path/file_aura.cc.
[email protected]95c989162012-11-29 05:58:251051 # Same for chromeos.
1052 if any(re.search('[/_](aura|chromeos)', f) for f in files):
[email protected]3e2f0402012-11-02 16:28:011053 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan']
[email protected]4ce995ea2012-06-27 02:13:101054
[email protected]d95948ef2013-07-02 10:51:001055 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1056 # unless they're .gyp(i) files as changes to those files can break the gyp
1057 # step on that bot.
1058 if (not all(re.search('^chrome', f) for f in files) or
1059 any(re.search('\.gypi?$', f) for f in files)):
1060 trybots += ['android_aosp']
1061
[email protected]4ce995ea2012-06-27 02:13:101062 return trybots