Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: PRESUBMIT.py

Issue 10554009: Simplify PRESUBMITs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/PRESUBMIT.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Top-level presubmit script for Chromium. 5 """Top-level presubmit script for Chromium.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl. 8 for more details about the presubmit API built into gcl.
9 """ 9 """
10 10
(...skipping 16 matching lines...) Expand all
27 'You might be calling functions intended only for testing from\n' 27 'You might be calling functions intended only for testing from\n'
28 'production code. It is OK to ignore this warning if you know what\n' 28 'production code. It is OK to ignore this warning if you know what\n'
29 'you are doing, as the heuristics used to detect the situation are\n' 29 'you are doing, as the heuristics used to detect the situation are\n'
30 'not perfect. The commit queue will not block on this warning.\n' 30 'not perfect. The commit queue will not block on this warning.\n'
31 'Email joi@chromium.org if you have questions.') 31 'Email joi@chromium.org if you have questions.')
32 32
33 33
34 _BANNED_OBJC_FUNCTIONS = ( 34 _BANNED_OBJC_FUNCTIONS = (
35 ( 35 (
36 'addTrackingRect:', 36 'addTrackingRect:',
37 ('The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' 37 (
38 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
38 'prohibited. Please use CrTrackingArea instead.', 39 'prohibited. Please use CrTrackingArea instead.',
39 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', 40 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
40 ), 41 ),
41 False, 42 False,
42 ), 43 ),
43 ( 44 (
44 'NSTrackingArea', 45 'NSTrackingArea',
45 ('The use of NSTrackingAreas is prohibited. Please use CrTrackingArea', 46 (
47 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
46 'instead.', 48 'instead.',
47 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', 49 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
48 ), 50 ),
49 False, 51 False,
50 ), 52 ),
51 ( 53 (
52 'convertPointFromBase:', 54 'convertPointFromBase:',
53 ('The use of -[NSView convertPointFromBase:] is almost certainly wrong.', 55 (
56 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
54 'Please use |convertPoint:(point) fromView:nil| instead.', 57 'Please use |convertPoint:(point) fromView:nil| instead.',
55 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', 58 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
56 ), 59 ),
57 True, 60 True,
58 ), 61 ),
59 ( 62 (
60 'convertPointToBase:', 63 'convertPointToBase:',
61 ('The use of -[NSView convertPointToBase:] is almost certainly wrong.', 64 (
65 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
62 'Please use |convertPoint:(point) toView:nil| instead.', 66 'Please use |convertPoint:(point) toView:nil| instead.',
63 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', 67 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
64 ), 68 ),
65 True, 69 True,
66 ), 70 ),
67 ( 71 (
68 'convertRectFromBase:', 72 'convertRectFromBase:',
69 ('The use of -[NSView convertRectFromBase:] is almost certainly wrong.', 73 (
74 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
70 'Please use |convertRect:(point) fromView:nil| instead.', 75 'Please use |convertRect:(point) fromView:nil| instead.',
71 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', 76 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
72 ), 77 ),
73 True, 78 True,
74 ), 79 ),
75 ( 80 (
76 'convertRectToBase:', 81 'convertRectToBase:',
77 ('The use of -[NSView convertRectToBase:] is almost certainly wrong.', 82 (
83 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
78 'Please use |convertRect:(point) toView:nil| instead.', 84 'Please use |convertRect:(point) toView:nil| instead.',
79 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', 85 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
80 ), 86 ),
81 True, 87 True,
82 ), 88 ),
83 ( 89 (
84 'convertSizeFromBase:', 90 'convertSizeFromBase:',
85 ('The use of -[NSView convertSizeFromBase:] is almost certainly wrong.', 91 (
92 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
86 'Please use |convertSize:(point) fromView:nil| instead.', 93 'Please use |convertSize:(point) fromView:nil| instead.',
87 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', 94 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
88 ), 95 ),
89 True, 96 True,
90 ), 97 ),
91 ( 98 (
92 'convertSizeToBase:', 99 'convertSizeToBase:',
93 ('The use of -[NSView convertSizeToBase:] is almost certainly wrong.', 100 (
101 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
94 'Please use |convertSize:(point) toView:nil| instead.', 102 'Please use |convertSize:(point) toView:nil| instead.',
95 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', 103 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
96 ), 104 ),
97 True, 105 True,
98 ), 106 ),
99 ) 107 )
100 108
101 109
102 _BANNED_CPP_FUNCTIONS = ( 110 _BANNED_CPP_FUNCTIONS = (
111 # Make sure that gtest's FRIEND_TEST() macro is not used; the
112 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
113 # used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes.
114 (
115 'FRIEND_TEST(',
116 (
117 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include'
118 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
119 ),
120 False,
121 ),
122 (
123 'ScopedAllowIO',
124 (
125 'New code should not use ScopedAllowIO. Post a task to the blocking pool'
126 'or the FILE thread instead.',
127 ),
128 False,
129 ),
130 (
131 'FilePathWatcher::Delegate',
132 (
133 'New code should not use FilePathWatcher::Delegate. Use the callback'
134 'interface instead.',
135 ),
136 False,
137 ),
103 ) 138 )
104 139
105 140
106 141
107 def _CheckNoInterfacesInBase(input_api, output_api):
108 """Checks to make sure no files in libbase.a have |@interface|."""
109 pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE)
110 files = []
111 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
112 if (f.LocalPath().startswith('base/') and
113 not f.LocalPath().endswith('_unittest.mm')):
114 contents = input_api.ReadFile(f)
115 if pattern.search(contents):
116 files.append(f)
117
118 if len(files):
119 return [ output_api.PresubmitError(
120 'Objective-C interfaces or categories are forbidden in libbase. ' +
121 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
122 'browse_thread/thread/efb28c10435987fd',
123 files) ]
124 return []
125
126
127 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): 142 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
128 """Attempts to prevent use of functions intended only for testing in 143 """Attempts to prevent use of functions intended only for testing in
129 non-testing code. For now this is just a best-effort implementation 144 non-testing code. For now this is just a best-effort implementation
130 that ignores header files and may have some false positives. A 145 that ignores header files and may have some false positives. A
131 better implementation would probably need a proper C++ parser. 146 better implementation would probably need a proper C++ parser.
132 """ 147 """
133 # We only scan .cc files and the like, as the declaration of 148 # We only scan .cc files and the like, as the declaration of
134 # for-testing functions in header files are hard to distinguish from 149 # for-testing functions in header files are hard to distinguish from
135 # calls to such functions without a proper C++ parser. 150 # calls to such functions without a proper C++ parser.
136 platform_specifiers = r'(_(android|chromeos|gtk|mac|posix|win))?' 151 platform_specifiers = r'(_(android|chromeos|gtk|mac|posix|win))?'
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 input_api.AffectedFiles()): 246 input_api.AffectedFiles()):
232 return [output_api.PresubmitError( 247 return [output_api.PresubmitError(
233 'Never commit changes to .DEPS.git. This file is maintained by an\n' 248 'Never commit changes to .DEPS.git. This file is maintained by an\n'
234 'automated system based on what\'s in DEPS and your changes will be\n' 249 'automated system based on what\'s in DEPS and your changes will be\n'
235 'overwritten.\n' 250 'overwritten.\n'
236 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n' 251 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
237 'for more information')] 252 'for more information')]
238 return [] 253 return []
239 254
240 255
241 def _CheckNoFRIEND_TEST(input_api, output_api):
242 """Make sure that gtest's FRIEND_TEST() macro is not used, the
243 FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be used
244 instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
245 problems = []
246
247 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
248 for f in input_api.AffectedFiles(file_filter=file_filter):
249 for line_num, line in f.ChangedContents():
250 if 'FRIEND_TEST(' in line:
251 problems.append(' %s:%d' % (f.LocalPath(), line_num))
252
253 if not problems:
254 return []
255 return [output_api.PresubmitPromptWarning('Chromium code should not use '
256 'gtest\'s FRIEND_TEST() macro. Include base/gtest_prod_util.h and use '
257 'FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
258
259
260 def _CheckNoScopedAllowIO(input_api, output_api):
261 """Make sure that ScopedAllowIO is not used."""
262 problems = []
263
264 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
265 for f in input_api.AffectedFiles(file_filter=file_filter):
266 for line_num, line in f.ChangedContents():
267 if 'ScopedAllowIO' in line:
268 problems.append(' %s:%d' % (f.LocalPath(), line_num))
269
270 if not problems:
271 return []
272 return [output_api.PresubmitPromptWarning('New code should not use '
273 'ScopedAllowIO. Post a task to the blocking pool or the FILE thread '
274 'instead.\n' + '\n'.join(problems))]
275
276
277 def _CheckNoFilePathWatcherDelegate(input_api, output_api):
278 """Make sure that FilePathWatcher::Delegate is not used."""
279 problems = []
280
281 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
282 for f in input_api.AffectedFiles(file_filter=file_filter):
283 for line_num, line in f.ChangedContents():
284 if 'FilePathWatcher::Delegate' in line:
285 problems.append(' %s:%d' % (f.LocalPath(), line_num))
286
287 if not problems:
288 return []
289 return [output_api.PresubmitPromptWarning('New code should not use '
290 'FilePathWatcher::Delegate. Use the callback interface instead.\n' +
291 '\n'.join(problems))]
292
293
294 def _CheckNoBannedFunctions(input_api, output_api): 256 def _CheckNoBannedFunctions(input_api, output_api):
295 """Make sure that banned functions are not used.""" 257 """Make sure that banned functions are not used."""
296 warnings = [] 258 warnings = []
297 errors = [] 259 errors = []
298 260
299 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) 261 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
300 for f in input_api.AffectedFiles(file_filter=file_filter): 262 for f in input_api.AffectedFiles(file_filter=file_filter):
301 for line_num, line in f.ChangedContents(): 263 for line_num, line in f.ChangedContents():
302 for func_name, message, error in _BANNED_OBJC_FUNCTIONS: 264 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
303 if func_name in line: 265 if func_name in line:
(...skipping 25 matching lines...) Expand all
329 'Banned functions were used.\n' + '\n'.join(errors))) 291 'Banned functions were used.\n' + '\n'.join(errors)))
330 return result 292 return result
331 293
332 294
333 295
334 def _CommonChecks(input_api, output_api): 296 def _CommonChecks(input_api, output_api):
335 """Checks common to both upload and commit.""" 297 """Checks common to both upload and commit."""
336 results = [] 298 results = []
337 results.extend(input_api.canned_checks.PanProjectChecks( 299 results.extend(input_api.canned_checks.PanProjectChecks(
338 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) 300 input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
339 results.extend(_CheckNoInterfacesInBase(input_api, output_api))
340 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) 301 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
341 results.extend( 302 results.extend(
342 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) 303 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
343 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 304 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
344 results.extend(_CheckNoNewWStrings(input_api, output_api)) 305 results.extend(_CheckNoNewWStrings(input_api, output_api))
345 results.extend(_CheckNoDEPSGIT(input_api, output_api)) 306 results.extend(_CheckNoDEPSGIT(input_api, output_api))
346 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
347 results.extend(_CheckNoScopedAllowIO(input_api, output_api))
348 results.extend(_CheckNoFilePathWatcherDelegate(input_api, output_api))
349 results.extend(_CheckNoBannedFunctions(input_api, output_api)) 307 results.extend(_CheckNoBannedFunctions(input_api, output_api))
350 return results 308 return results
351 309
352 310
353 def _CheckSubversionConfig(input_api, output_api): 311 def _CheckSubversionConfig(input_api, output_api):
354 """Verifies the subversion config file is correctly setup. 312 """Verifies the subversion config file is correctly setup.
355 313
356 Checks that autoprops are enabled, returns an error otherwise. 314 Checks that autoprops are enabled, returns an error otherwise.
357 """ 315 """
358 join = input_api.os_path.join 316 join = input_api.os_path.join
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 for non_android_re in (aura_re, win_re): 438 for non_android_re in (aura_re, win_re):
481 if all(re.search(non_android_re, f) for f in affected_files): 439 if all(re.search(non_android_re, f) for f in affected_files):
482 possibly_android = False 440 possibly_android = False
483 break 441 break
484 if possibly_android: 442 if possibly_android:
485 for f in change.AffectedFiles(): 443 for f in change.AffectedFiles():
486 if any(re.search(r, f.LocalPath()) for r in android_re_list): 444 if any(re.search(r, f.LocalPath()) for r in android_re_list):
487 preferred.append('android') 445 preferred.append('android')
488 break 446 break
489 return preferred 447 return preferred
OLDNEW
« no previous file with comments | « no previous file | base/PRESUBMIT.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698