blob: 08f34527228f693bcf3b6ee19a8474ccdddc2491 [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]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]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]94f206c12012-08-25 00:09:1426 r"^cc[\\\/].*",
[email protected]39849c6c2012-09-14 22:15:5927 r"^webkit[\\\/]compositor_bindings[\\\/].*",
[email protected]ce145c02012-09-06 09:49:3428 r".+[\\\/]pnacl_shim\.c$",
[email protected]4306417642009-06-11 00:33:4029)
[email protected]ca8d1982009-02-19 16:33:1230
[email protected]ca8d1982009-02-19 16:33:1231
[email protected]eea609a2011-11-18 13:10:1232_TEST_ONLY_WARNING = (
33 'You might be calling functions intended only for testing from\n'
34 'production code. It is OK to ignore this warning if you know what\n'
35 'you are doing, as the heuristics used to detect the situation are\n'
36 'not perfect. The commit queue will not block on this warning.\n'
37 'Email [email protected] if you have questions.')
38
39
[email protected]127f18ec2012-06-16 05:05:5940_BANNED_OBJC_FUNCTIONS = (
41 (
42 'addTrackingRect:',
[email protected]23e6cbc2012-06-16 18:51:2043 (
44 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
[email protected]127f18ec2012-06-16 05:05:5945 'prohibited. Please use CrTrackingArea instead.',
46 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
47 ),
48 False,
49 ),
50 (
51 'NSTrackingArea',
[email protected]23e6cbc2012-06-16 18:51:2052 (
53 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
[email protected]127f18ec2012-06-16 05:05:5954 'instead.',
55 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
56 ),
57 False,
58 ),
59 (
60 'convertPointFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2061 (
62 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5963 'Please use |convertPoint:(point) fromView:nil| instead.',
64 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
65 ),
66 True,
67 ),
68 (
69 'convertPointToBase:',
[email protected]23e6cbc2012-06-16 18:51:2070 (
71 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5972 'Please use |convertPoint:(point) toView:nil| instead.',
73 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
74 ),
75 True,
76 ),
77 (
78 'convertRectFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2079 (
80 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5981 'Please use |convertRect:(point) fromView:nil| instead.',
82 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
83 ),
84 True,
85 ),
86 (
87 'convertRectToBase:',
[email protected]23e6cbc2012-06-16 18:51:2088 (
89 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5990 'Please use |convertRect:(point) toView:nil| instead.',
91 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
92 ),
93 True,
94 ),
95 (
96 'convertSizeFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2097 (
98 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5999 'Please use |convertSize:(point) fromView:nil| instead.',
100 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
101 ),
102 True,
103 ),
104 (
105 'convertSizeToBase:',
[email protected]23e6cbc2012-06-16 18:51:20106 (
107 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59108 'Please use |convertSize:(point) toView:nil| instead.',
109 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
110 ),
111 True,
112 ),
113)
114
115
116_BANNED_CPP_FUNCTIONS = (
[email protected]23e6cbc2012-06-16 18:51:20117 # Make sure that gtest's FRIEND_TEST() macro is not used; the
118 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
[email protected]e00ccc92012-11-01 17:32:30119 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
[email protected]23e6cbc2012-06-16 18:51:20120 (
121 'FRIEND_TEST(',
122 (
[email protected]e3c945502012-06-26 20:01:49123 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
[email protected]23e6cbc2012-06-16 18:51:20124 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
125 ),
126 False,
127 ),
128 (
129 'ScopedAllowIO',
130 (
[email protected]e3c945502012-06-26 20:01:49131 'New code should not use ScopedAllowIO. Post a task to the blocking',
132 'pool or the FILE thread instead.',
[email protected]23e6cbc2012-06-16 18:51:20133 ),
[email protected]e3c945502012-06-26 20:01:49134 True,
[email protected]23e6cbc2012-06-16 18:51:20135 ),
136 (
137 'FilePathWatcher::Delegate',
138 (
[email protected]e3c945502012-06-26 20:01:49139 'New code should not use FilePathWatcher::Delegate. Use the callback',
[email protected]23e6cbc2012-06-16 18:51:20140 'interface instead.',
141 ),
142 False,
143 ),
[email protected]e3c945502012-06-26 20:01:49144 (
[email protected]aebced32012-11-12 01:32:20145 'chrome::FindLastActiveWithProfile',
[email protected]e3c945502012-06-26 20:01:49146 (
147 'This function is deprecated and we\'re working on removing it. Pass',
148 'more context to get a Browser*, like a WebContents, window, or session',
[email protected]1099dbd2012-11-01 19:56:02149 'id. Talk to robertshield@ for more information.',
[email protected]e3c945502012-06-26 20:01:49150 ),
151 True,
152 ),
153 (
[email protected]e3c945502012-06-26 20:01:49154 'browser::FindAnyBrowser',
155 (
156 'This function is deprecated and we\'re working on removing it. Pass',
157 'more context to get a Browser*, like a WebContents, window, or session',
[email protected]1099dbd2012-11-01 19:56:02158 'id. Talk to robertshield@ for more information.',
[email protected]e3c945502012-06-26 20:01:49159 ),
160 True,
161 ),
162 (
163 'browser::FindOrCreateTabbedBrowser',
164 (
165 'This function is deprecated and we\'re working on removing it. Pass',
166 'more context to get a Browser*, like a WebContents, window, or session',
[email protected]1099dbd2012-11-01 19:56:02167 'id. Talk to robertshield@ for more information.',
[email protected]e3c945502012-06-26 20:01:49168 ),
169 True,
170 ),
171 (
[email protected]1099dbd2012-11-01 19:56:02172 'browser::FindTabbedBrowserDeprecated',
[email protected]e3c945502012-06-26 20:01:49173 (
174 'This function is deprecated and we\'re working on removing it. Pass',
175 'more context to get a Browser*, like a WebContents, window, or session',
[email protected]1099dbd2012-11-01 19:56:02176 'id. Talk to robertshield@ for more information.',
[email protected]e3c945502012-06-26 20:01:49177 ),
178 True,
179 ),
[email protected]bb5eff1cc2012-11-01 20:46:29180 (
181 'RunAllPending()',
182 (
183 'This function is deprecated and we\'re working on removing it. Rename',
184 'to RunUntilIdle',
185 ),
186 True,
187 ),
[email protected]127f18ec2012-06-16 05:05:59188)
189
190
[email protected]eea609a2011-11-18 13:10:12191
[email protected]55459852011-08-10 15:17:19192def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
193 """Attempts to prevent use of functions intended only for testing in
194 non-testing code. For now this is just a best-effort implementation
195 that ignores header files and may have some false positives. A
196 better implementation would probably need a proper C++ parser.
197 """
198 # We only scan .cc files and the like, as the declaration of
199 # for-testing functions in header files are hard to distinguish from
200 # calls to such functions without a proper C++ parser.
[email protected]403bfbc92012-06-11 23:30:09201 platform_specifiers = r'(_(android|chromeos|gtk|mac|posix|win))?'
[email protected]55459852011-08-10 15:17:19202 source_extensions = r'\.(cc|cpp|cxx|mm)$'
203 file_inclusion_pattern = r'.+%s' % source_extensions
[email protected]19e77fd2011-10-20 05:24:05204 file_exclusion_patterns = (
[email protected]44e376e2012-10-26 19:40:21205 r'.*[/\\](fake_|test_|mock_).+%s' % source_extensions,
[email protected]c762d252012-02-28 02:07:24206 r'.+_test_(base|support|util)%s' % source_extensions,
[email protected]403bfbc92012-06-11 23:30:09207 r'.+_(api|browser|perf|unit|ui)?test%s%s' % (platform_specifiers,
208 source_extensions),
[email protected]19e77fd2011-10-20 05:24:05209 r'.+profile_sync_service_harness%s' % source_extensions,
210 )
211 path_exclusion_patterns = (
212 r'.*[/\\](test|tool(s)?)[/\\].*',
213 # At request of folks maintaining this folder.
214 r'chrome[/\\]browser[/\\]automation[/\\].*',
215 )
[email protected]55459852011-08-10 15:17:19216
217 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
218 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
219 exclusion_pattern = input_api.re.compile(
220 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
221 base_function_pattern, base_function_pattern))
222
223 def FilterFile(affected_file):
[email protected]19e77fd2011-10-20 05:24:05224 black_list = (file_exclusion_patterns + path_exclusion_patterns +
[email protected]3afb12a42011-08-15 13:48:33225 _EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST)
[email protected]55459852011-08-10 15:17:19226 return input_api.FilterSourceFile(
227 affected_file,
228 white_list=(file_inclusion_pattern, ),
229 black_list=black_list)
230
231 problems = []
232 for f in input_api.AffectedSourceFiles(FilterFile):
233 local_path = f.LocalPath()
234 lines = input_api.ReadFile(f).splitlines()
235 line_number = 0
236 for line in lines:
237 if (inclusion_pattern.search(line) and
238 not exclusion_pattern.search(line)):
239 problems.append(
240 '%s:%d\n %s' % (local_path, line_number, line.strip()))
241 line_number += 1
242
243 if problems:
[email protected]eea609a2011-11-18 13:10:12244 if not input_api.is_committing:
245 return [output_api.PresubmitPromptWarning(_TEST_ONLY_WARNING, problems)]
246 else:
247 # We don't warn on commit, to avoid stopping commits going through CQ.
248 return [output_api.PresubmitNotifyResult(_TEST_ONLY_WARNING, problems)]
[email protected]55459852011-08-10 15:17:19249 else:
250 return []
251
252
[email protected]10689ca2011-09-02 02:31:54253def _CheckNoIOStreamInHeaders(input_api, output_api):
254 """Checks to make sure no .h files include <iostream>."""
255 files = []
256 pattern = input_api.re.compile(r'^#include\s*<iostream>',
257 input_api.re.MULTILINE)
258 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
259 if not f.LocalPath().endswith('.h'):
260 continue
261 contents = input_api.ReadFile(f)
262 if pattern.search(contents):
263 files.append(f)
264
265 if len(files):
266 return [ output_api.PresubmitError(
[email protected]6c063c62012-07-11 19:11:06267 'Do not #include <iostream> in header files, since it inserts static '
268 'initialization into every file including the header. Instead, '
[email protected]10689ca2011-09-02 02:31:54269 '#include <ostream>. See http://crbug.com/94794',
270 files) ]
271 return []
272
273
[email protected]72df4e782012-06-21 16:28:18274def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
275 """Checks to make sure no source files use UNIT_TEST"""
276 problems = []
277 for f in input_api.AffectedFiles():
278 if (not f.LocalPath().endswith(('.cc', '.mm'))):
279 continue
280
281 for line_num, line in f.ChangedContents():
282 if 'UNIT_TEST' in line:
283 problems.append(' %s:%d' % (f.LocalPath(), line_num))
284
285 if not problems:
286 return []
287 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
288 '\n'.join(problems))]
289
290
[email protected]8ea5d4b2011-09-13 21:49:22291def _CheckNoNewWStrings(input_api, output_api):
292 """Checks to make sure we don't introduce use of wstrings."""
[email protected]55463aa62011-10-12 00:48:27293 problems = []
[email protected]8ea5d4b2011-09-13 21:49:22294 for f in input_api.AffectedFiles():
[email protected]b5c24292011-11-28 14:38:20295 if (not f.LocalPath().endswith(('.cc', '.h')) or
296 f.LocalPath().endswith('test.cc')):
297 continue
[email protected]8ea5d4b2011-09-13 21:49:22298
[email protected]a11dbe9b2012-08-07 01:32:58299 allowWString = False
[email protected]b5c24292011-11-28 14:38:20300 for line_num, line in f.ChangedContents():
[email protected]a11dbe9b2012-08-07 01:32:58301 if 'presubmit: allow wstring' in line:
302 allowWString = True
303 elif not allowWString and 'wstring' in line:
[email protected]55463aa62011-10-12 00:48:27304 problems.append(' %s:%d' % (f.LocalPath(), line_num))
[email protected]a11dbe9b2012-08-07 01:32:58305 allowWString = False
306 else:
307 allowWString = False
[email protected]8ea5d4b2011-09-13 21:49:22308
[email protected]55463aa62011-10-12 00:48:27309 if not problems:
310 return []
311 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
[email protected]a11dbe9b2012-08-07 01:32:58312 ' If you are calling a cross-platform API that accepts a wstring, '
313 'fix the API.\n' +
[email protected]55463aa62011-10-12 00:48:27314 '\n'.join(problems))]
[email protected]8ea5d4b2011-09-13 21:49:22315
316
[email protected]2a8ac9c2011-10-19 17:20:44317def _CheckNoDEPSGIT(input_api, output_api):
318 """Make sure .DEPS.git is never modified manually."""
319 if any(f.LocalPath().endswith('.DEPS.git') for f in
320 input_api.AffectedFiles()):
321 return [output_api.PresubmitError(
322 'Never commit changes to .DEPS.git. This file is maintained by an\n'
323 'automated system based on what\'s in DEPS and your changes will be\n'
324 'overwritten.\n'
325 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
326 'for more information')]
327 return []
328
329
[email protected]127f18ec2012-06-16 05:05:59330def _CheckNoBannedFunctions(input_api, output_api):
331 """Make sure that banned functions are not used."""
332 warnings = []
333 errors = []
334
335 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
336 for f in input_api.AffectedFiles(file_filter=file_filter):
337 for line_num, line in f.ChangedContents():
338 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
339 if func_name in line:
340 problems = warnings;
341 if error:
342 problems = errors;
343 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
344 for message_line in message:
345 problems.append(' %s' % message_line)
346
347 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
348 for f in input_api.AffectedFiles(file_filter=file_filter):
349 for line_num, line in f.ChangedContents():
350 for func_name, message, error in _BANNED_CPP_FUNCTIONS:
351 if func_name in line:
352 problems = warnings;
353 if error:
354 problems = errors;
355 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
356 for message_line in message:
357 problems.append(' %s' % message_line)
358
359 result = []
360 if (warnings):
361 result.append(output_api.PresubmitPromptWarning(
362 'Banned functions were used.\n' + '\n'.join(warnings)))
363 if (errors):
364 result.append(output_api.PresubmitError(
365 'Banned functions were used.\n' + '\n'.join(errors)))
366 return result
367
368
[email protected]6c063c62012-07-11 19:11:06369def _CheckNoPragmaOnce(input_api, output_api):
370 """Make sure that banned functions are not used."""
371 files = []
372 pattern = input_api.re.compile(r'^#pragma\s+once',
373 input_api.re.MULTILINE)
374 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
375 if not f.LocalPath().endswith('.h'):
376 continue
377 contents = input_api.ReadFile(f)
378 if pattern.search(contents):
379 files.append(f)
380
381 if files:
382 return [output_api.PresubmitError(
383 'Do not use #pragma once in header files.\n'
384 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
385 files)]
386 return []
387
[email protected]127f18ec2012-06-16 05:05:59388
[email protected]e7479052012-09-19 00:26:12389def _CheckNoTrinaryTrueFalse(input_api, output_api):
390 """Checks to make sure we don't introduce use of foo ? true : false."""
391 problems = []
392 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
393 for f in input_api.AffectedFiles():
394 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
395 continue
396
397 for line_num, line in f.ChangedContents():
398 if pattern.match(line):
399 problems.append(' %s:%d' % (f.LocalPath(), line_num))
400
401 if not problems:
402 return []
403 return [output_api.PresubmitPromptWarning(
404 'Please consider avoiding the "? true : false" pattern if possible.\n' +
405 '\n'.join(problems))]
406
407
[email protected]55f9f382012-07-31 11:02:18408def _CheckUnwantedDependencies(input_api, output_api):
409 """Runs checkdeps on #include statements added in this
410 change. Breaking - rules is an error, breaking ! rules is a
411 warning.
412 """
413 # We need to wait until we have an input_api object and use this
414 # roundabout construct to import checkdeps because this file is
415 # eval-ed and thus doesn't have __file__.
416 original_sys_path = sys.path
417 try:
418 sys.path = sys.path + [input_api.os_path.join(
419 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
420 import checkdeps
421 from cpp_checker import CppChecker
422 from rules import Rule
423 finally:
424 # Restore sys.path to what it was before.
425 sys.path = original_sys_path
426
427 added_includes = []
428 for f in input_api.AffectedFiles():
429 if not CppChecker.IsCppFile(f.LocalPath()):
430 continue
431
432 changed_lines = [line for line_num, line in f.ChangedContents()]
433 added_includes.append([f.LocalPath(), changed_lines])
434
435 deps_checker = checkdeps.DepsChecker()
436
437 error_descriptions = []
438 warning_descriptions = []
439 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
440 added_includes):
441 description_with_path = '%s\n %s' % (path, rule_description)
442 if rule_type == Rule.DISALLOW:
443 error_descriptions.append(description_with_path)
444 else:
445 warning_descriptions.append(description_with_path)
446
447 results = []
448 if error_descriptions:
449 results.append(output_api.PresubmitError(
450 'You added one or more #includes that violate checkdeps rules.',
451 error_descriptions))
452 if warning_descriptions:
[email protected]779caa52012-08-21 17:05:59453 if not input_api.is_committing:
454 warning_factory = output_api.PresubmitPromptWarning
455 else:
456 # We don't want to block use of the CQ when there is a warning
457 # of this kind, so we only show a message when committing.
458 warning_factory = output_api.PresubmitNotifyResult
459 results.append(warning_factory(
[email protected]55f9f382012-07-31 11:02:18460 'You added one or more #includes of files that are temporarily\n'
461 'allowed but being removed. Can you avoid introducing the\n'
462 '#include? See relevant DEPS file(s) for details and contacts.',
463 warning_descriptions))
464 return results
465
466
[email protected]fbcafe5a2012-08-08 15:31:22467def _CheckFilePermissions(input_api, output_api):
468 """Check that all files have their permissions properly set."""
469 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
470 input_api.change.RepositoryRoot()]
471 for f in input_api.AffectedFiles():
472 args += ['--file', f.LocalPath()]
473 errors = []
474 (errors, stderrdata) = subprocess.Popen(args).communicate()
475
476 results = []
477 if errors:
[email protected]c8278b32012-10-30 20:35:49478 results.append(output_api.PresubmitError('checkperms.py failed.',
[email protected]fbcafe5a2012-08-08 15:31:22479 errors))
480 return results
481
482
[email protected]c8278b32012-10-30 20:35:49483def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
484 """Makes sure we don't include ui/aura/window_property.h
485 in header files.
486 """
487 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
488 errors = []
489 for f in input_api.AffectedFiles():
490 if not f.LocalPath().endswith('.h'):
491 continue
492 for line_num, line in f.ChangedContents():
493 if pattern.match(line):
494 errors.append(' %s:%d' % (f.LocalPath(), line_num))
495
496 results = []
497 if errors:
498 results.append(output_api.PresubmitError(
499 'Header files should not include ui/aura/window_property.h', errors))
500 return results
501
502
[email protected]22c9bd72011-03-27 16:47:39503def _CommonChecks(input_api, output_api):
504 """Checks common to both upload and commit."""
505 results = []
506 results.extend(input_api.canned_checks.PanProjectChecks(
507 input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
[email protected]66daa702011-05-28 14:41:46508 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]55459852011-08-10 15:17:19509 results.extend(
510 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
[email protected]10689ca2011-09-02 02:31:54511 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
[email protected]72df4e782012-06-21 16:28:18512 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
[email protected]8ea5d4b2011-09-13 21:49:22513 results.extend(_CheckNoNewWStrings(input_api, output_api))
[email protected]2a8ac9c2011-10-19 17:20:44514 results.extend(_CheckNoDEPSGIT(input_api, output_api))
[email protected]127f18ec2012-06-16 05:05:59515 results.extend(_CheckNoBannedFunctions(input_api, output_api))
[email protected]6c063c62012-07-11 19:11:06516 results.extend(_CheckNoPragmaOnce(input_api, output_api))
[email protected]e7479052012-09-19 00:26:12517 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
[email protected]55f9f382012-07-31 11:02:18518 results.extend(_CheckUnwantedDependencies(input_api, output_api))
[email protected]fbcafe5a2012-08-08 15:31:22519 results.extend(_CheckFilePermissions(input_api, output_api))
[email protected]c8278b32012-10-30 20:35:49520 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
[email protected]22c9bd72011-03-27 16:47:39521 return results
[email protected]1f7b4172010-01-28 01:17:34522
[email protected]b337cb5b2011-01-23 21:24:05523
524def _CheckSubversionConfig(input_api, output_api):
525 """Verifies the subversion config file is correctly setup.
526
527 Checks that autoprops are enabled, returns an error otherwise.
528 """
529 join = input_api.os_path.join
530 if input_api.platform == 'win32':
531 appdata = input_api.environ.get('APPDATA', '')
532 if not appdata:
533 return [output_api.PresubmitError('%APPDATA% is not configured.')]
534 path = join(appdata, 'Subversion', 'config')
535 else:
536 home = input_api.environ.get('HOME', '')
537 if not home:
538 return [output_api.PresubmitError('$HOME is not configured.')]
539 path = join(home, '.subversion', 'config')
540
541 error_msg = (
542 'Please look at http://dev.chromium.org/developers/coding-style to\n'
543 'configure your subversion configuration file. This enables automatic\n'
[email protected]c6a3c10b2011-01-24 16:14:20544 'properties to simplify the project maintenance.\n'
545 'Pro-tip: just download and install\n'
546 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
[email protected]b337cb5b2011-01-23 21:24:05547
548 try:
549 lines = open(path, 'r').read().splitlines()
550 # Make sure auto-props is enabled and check for 2 Chromium standard
551 # auto-prop.
552 if (not '*.cc = svn:eol-style=LF' in lines or
553 not '*.pdf = svn:mime-type=application/pdf' in lines or
554 not 'enable-auto-props = yes' in lines):
555 return [
[email protected]79ed7e62011-02-21 21:08:53556 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:05557 'It looks like you have not configured your subversion config '
[email protected]b5359c02011-02-01 20:29:56558 'file or it is not up-to-date.\n' + error_msg)
[email protected]b337cb5b2011-01-23 21:24:05559 ]
560 except (OSError, IOError):
561 return [
[email protected]79ed7e62011-02-21 21:08:53562 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:05563 'Can\'t find your subversion config file.\n' + error_msg)
564 ]
565 return []
566
567
[email protected]66daa702011-05-28 14:41:46568def _CheckAuthorizedAuthor(input_api, output_api):
569 """For non-googler/chromites committers, verify the author's email address is
570 in AUTHORS.
571 """
[email protected]9bb9cb82011-06-13 20:43:01572 # TODO(maruel): Add it to input_api?
573 import fnmatch
574
[email protected]66daa702011-05-28 14:41:46575 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:01576 if not author:
577 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:46578 return []
[email protected]c99663292011-05-31 19:46:08579 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:46580 input_api.PresubmitLocalPath(), 'AUTHORS')
581 valid_authors = (
582 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
583 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:18584 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]9bb9cb82011-06-13 20:43:01585 if input_api.verbose:
586 print 'Valid authors are %s' % ', '.join(valid_authors)
[email protected]d8b50be2011-06-15 14:19:44587 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]66daa702011-05-28 14:41:46588 return [output_api.PresubmitPromptWarning(
589 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
590 '\n'
591 'http://www.chromium.org/developers/contributing-code and read the '
592 '"Legal" section\n'
593 'If you are a chromite, verify the contributor signed the CLA.') %
594 author)]
595 return []
596
597
[email protected]1f7b4172010-01-28 01:17:34598def CheckChangeOnUpload(input_api, output_api):
599 results = []
600 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54601 return results
[email protected]ca8d1982009-02-19 16:33:12602
603
604def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54605 results = []
[email protected]1f7b4172010-01-28 01:17:34606 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:51607 # TODO(thestig) temporarily disabled, doesn't work in third_party/
608 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
609 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:54610 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:27611 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:34612 input_api,
613 output_api,
[email protected]4efa42142010-08-26 01:29:26614 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:27615 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
[email protected]4ddc5df2011-12-12 03:05:04616 output_api, 'http://codereview.chromium.org',
[email protected]c1ba4c52012-03-09 14:23:28617 ('win_rel', 'linux_rel', 'mac_rel, win:compile'),
618 '[email protected]'))
[email protected]806e98e2010-03-19 17:49:27619
[email protected]3e4eb112011-01-18 03:29:54620 results.extend(input_api.canned_checks.CheckChangeHasBugField(
621 input_api, output_api))
[email protected]c4b47562011-12-05 23:39:41622 results.extend(input_api.canned_checks.CheckChangeHasDescription(
623 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:05624 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54625 return results
[email protected]ca8d1982009-02-19 16:33:12626
627
[email protected]5efb2a822011-09-27 23:06:13628def GetPreferredTrySlaves(project, change):
[email protected]4ce995ea2012-06-27 02:13:10629 files = change.LocalPaths()
630
[email protected]3019c902012-06-29 00:09:03631 if not files:
632 return []
633
[email protected]d668899a2012-09-06 18:16:59634 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
[email protected]641f2e3e2012-09-03 11:16:24635 return ['mac_rel', 'mac_asan']
[email protected]d668899a2012-09-06 18:16:59636 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
[email protected]4ce995ea2012-06-27 02:13:10637 return ['win_rel']
[email protected]d668899a2012-09-06 18:16:59638 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
[email protected]3e2f0402012-11-02 16:28:01639 return ['android_dbg', 'android_clang_dbg']
[email protected]356aa542012-09-19 23:31:29640 if all(re.search('^native_client_sdk', f) for f in files):
641 return ['linux_nacl_sdk', 'win_nacl_sdk', 'mac_nacl_sdk']
[email protected]de142152012-10-03 23:02:45642 if all(re.search('[/_]ios[/_.]', f) for f in files):
643 return ['ios_rel_device', 'ios_dbg_simulator']
[email protected]4ce995ea2012-06-27 02:13:10644
[email protected]3e2f0402012-11-02 16:28:01645 trybots = [
646 'android_clang_dbg',
647 'android_dbg',
648 'ios_dbg_simulator',
649 'ios_rel_device',
650 'linux_asan',
651 'linux_chromeos',
652 'linux_clang:compile',
653 'linux_rel',
654 'mac_asan',
655 'mac_rel',
656 'win_rel',
657 ]
[email protected]911753b2012-08-02 12:11:54658
659 # Match things like path/aura/file.cc and path/file_aura.cc.
[email protected]0be9553a2012-08-10 00:14:45660 # Same for ash and chromeos.
661 if any(re.search('[/_](ash|aura)', f) for f in files):
[email protected]3e2f0402012-11-02 16:28:01662 trybots += ['linux_chromeos_clang:compile', 'win_aura',
[email protected]641f2e3e2012-09-03 11:16:24663 'linux_chromeos_asan']
[email protected]3e2f0402012-11-02 16:28:01664 elif any(re.search('[/_]chromeos', f) for f in files):
665 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan']
[email protected]4ce995ea2012-06-27 02:13:10666
[email protected]4ce995ea2012-06-27 02:13:10667 return trybots