OLD | NEW |
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 13 matching lines...) Expand all Loading... |
24 | 24 |
25 | 25 |
26 _TEST_ONLY_WARNING = ( | 26 _TEST_ONLY_WARNING = ( |
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 = ( |
| 35 ( |
| 36 'addTrackingRect:', |
| 37 ('The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' |
| 38 'prohibited. Please use CrTrackingArea instead.', |
| 39 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 40 ), |
| 41 False, |
| 42 ), |
| 43 ( |
| 44 'NSTrackingArea', |
| 45 ('The use of NSTrackingAreas is prohibited. Please use CrTrackingArea', |
| 46 'instead.', |
| 47 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 48 ), |
| 49 False, |
| 50 ), |
| 51 ( |
| 52 'convertPointFromBase:', |
| 53 ('The use of -[NSView convertPointFromBase:] is almost certainly wrong.', |
| 54 'Please use |convertPoint:(point) fromView:nil| instead.', |
| 55 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 56 ), |
| 57 True, |
| 58 ), |
| 59 ( |
| 60 'convertPointToBase:', |
| 61 ('The use of -[NSView convertPointToBase:] is almost certainly wrong.', |
| 62 'Please use |convertPoint:(point) toView:nil| instead.', |
| 63 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 64 ), |
| 65 True, |
| 66 ), |
| 67 ( |
| 68 'convertRectFromBase:', |
| 69 ('The use of -[NSView convertRectFromBase:] is almost certainly wrong.', |
| 70 'Please use |convertRect:(point) fromView:nil| instead.', |
| 71 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 72 ), |
| 73 True, |
| 74 ), |
| 75 ( |
| 76 'convertRectToBase:', |
| 77 ('The use of -[NSView convertRectToBase:] is almost certainly wrong.', |
| 78 'Please use |convertRect:(point) toView:nil| instead.', |
| 79 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 80 ), |
| 81 True, |
| 82 ), |
| 83 ( |
| 84 'convertSizeFromBase:', |
| 85 ('The use of -[NSView convertSizeFromBase:] is almost certainly wrong.', |
| 86 'Please use |convertSize:(point) fromView:nil| instead.', |
| 87 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 88 ), |
| 89 True, |
| 90 ), |
| 91 ( |
| 92 'convertSizeToBase:', |
| 93 ('The use of -[NSView convertSizeToBase:] is almost certainly wrong.', |
| 94 'Please use |convertSize:(point) toView:nil| instead.', |
| 95 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 96 ), |
| 97 True, |
| 98 ), |
| 99 ) |
| 100 |
| 101 |
| 102 _BANNED_CPP_FUNCTIONS = ( |
| 103 ) |
| 104 |
| 105 |
34 | 106 |
35 def _CheckNoInterfacesInBase(input_api, output_api): | 107 def _CheckNoInterfacesInBase(input_api, output_api): |
36 """Checks to make sure no files in libbase.a have |@interface|.""" | 108 """Checks to make sure no files in libbase.a have |@interface|.""" |
37 pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE) | 109 pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE) |
38 files = [] | 110 files = [] |
39 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): | 111 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
40 if (f.LocalPath().startswith('base/') and | 112 if (f.LocalPath().startswith('base/') and |
41 not f.LocalPath().endswith('_unittest.mm')): | 113 not f.LocalPath().endswith('_unittest.mm')): |
42 contents = input_api.ReadFile(f) | 114 contents = input_api.ReadFile(f) |
43 if pattern.search(contents): | 115 if pattern.search(contents): |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if 'FilePathWatcher::Delegate' in line: | 284 if 'FilePathWatcher::Delegate' in line: |
213 problems.append(' %s:%d' % (f.LocalPath(), line_num)) | 285 problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
214 | 286 |
215 if not problems: | 287 if not problems: |
216 return [] | 288 return [] |
217 return [output_api.PresubmitPromptWarning('New code should not use ' | 289 return [output_api.PresubmitPromptWarning('New code should not use ' |
218 'FilePathWatcher::Delegate. Use the callback interface instead.\n' + | 290 'FilePathWatcher::Delegate. Use the callback interface instead.\n' + |
219 '\n'.join(problems))] | 291 '\n'.join(problems))] |
220 | 292 |
221 | 293 |
| 294 def _CheckNoBannedFunctions(input_api, output_api): |
| 295 """Make sure that banned functions are not used.""" |
| 296 warnings = [] |
| 297 errors = [] |
| 298 |
| 299 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) |
| 300 for f in input_api.AffectedFiles(file_filter=file_filter): |
| 301 for line_num, line in f.ChangedContents(): |
| 302 for func_name, message, error in _BANNED_OBJC_FUNCTIONS: |
| 303 if func_name in line: |
| 304 problems = warnings; |
| 305 if error: |
| 306 problems = errors; |
| 307 problems.append(' %s:%d:' % (f.LocalPath(), line_num)) |
| 308 for message_line in message: |
| 309 problems.append(' %s' % message_line) |
| 310 |
| 311 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h')) |
| 312 for f in input_api.AffectedFiles(file_filter=file_filter): |
| 313 for line_num, line in f.ChangedContents(): |
| 314 for func_name, message, error in _BANNED_CPP_FUNCTIONS: |
| 315 if func_name in line: |
| 316 problems = warnings; |
| 317 if error: |
| 318 problems = errors; |
| 319 problems.append(' %s:%d:' % (f.LocalPath(), line_num)) |
| 320 for message_line in message: |
| 321 problems.append(' %s' % message_line) |
| 322 |
| 323 result = [] |
| 324 if (warnings): |
| 325 result.append(output_api.PresubmitPromptWarning( |
| 326 'Banned functions were used.\n' + '\n'.join(warnings))) |
| 327 if (errors): |
| 328 result.append(output_api.PresubmitError( |
| 329 'Banned functions were used.\n' + '\n'.join(errors))) |
| 330 return result |
| 331 |
| 332 |
| 333 |
222 def _CommonChecks(input_api, output_api): | 334 def _CommonChecks(input_api, output_api): |
223 """Checks common to both upload and commit.""" | 335 """Checks common to both upload and commit.""" |
224 results = [] | 336 results = [] |
225 results.extend(input_api.canned_checks.PanProjectChecks( | 337 results.extend(input_api.canned_checks.PanProjectChecks( |
226 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) | 338 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) |
227 results.extend(_CheckNoInterfacesInBase(input_api, output_api)) | 339 results.extend(_CheckNoInterfacesInBase(input_api, output_api)) |
228 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) | 340 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
229 results.extend( | 341 results.extend( |
230 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) | 342 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
231 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) | 343 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
232 results.extend(_CheckNoNewWStrings(input_api, output_api)) | 344 results.extend(_CheckNoNewWStrings(input_api, output_api)) |
233 results.extend(_CheckNoDEPSGIT(input_api, output_api)) | 345 results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
234 results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) | 346 results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) |
235 results.extend(_CheckNoScopedAllowIO(input_api, output_api)) | 347 results.extend(_CheckNoScopedAllowIO(input_api, output_api)) |
236 results.extend(_CheckNoFilePathWatcherDelegate(input_api, output_api)) | 348 results.extend(_CheckNoFilePathWatcherDelegate(input_api, output_api)) |
| 349 results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
237 return results | 350 return results |
238 | 351 |
239 | 352 |
240 def _CheckSubversionConfig(input_api, output_api): | 353 def _CheckSubversionConfig(input_api, output_api): |
241 """Verifies the subversion config file is correctly setup. | 354 """Verifies the subversion config file is correctly setup. |
242 | 355 |
243 Checks that autoprops are enabled, returns an error otherwise. | 356 Checks that autoprops are enabled, returns an error otherwise. |
244 """ | 357 """ |
245 join = input_api.os_path.join | 358 join = input_api.os_path.join |
246 if input_api.platform == 'win32': | 359 if input_api.platform == 'win32': |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 for non_android_re in (aura_re, win_re): | 480 for non_android_re in (aura_re, win_re): |
368 if all(re.search(non_android_re, f) for f in affected_files): | 481 if all(re.search(non_android_re, f) for f in affected_files): |
369 possibly_android = False | 482 possibly_android = False |
370 break | 483 break |
371 if possibly_android: | 484 if possibly_android: |
372 for f in change.AffectedFiles(): | 485 for f in change.AffectedFiles(): |
373 if any(re.search(r, f.LocalPath()) for r in android_re_list): | 486 if any(re.search(r, f.LocalPath()) for r in android_re_list): |
374 preferred.append('android') | 487 preferred.append('android') |
375 break | 488 break |
376 return preferred | 489 return preferred |
OLD | NEW |