Index: PRESUBMIT.py |
diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
index d4d00ed9796ec373399757dc0fe0929ef0a248c8..e0fb4ca1e4372fb23fa5221444e9ea8e9d68dde8 100644 |
--- a/PRESUBMIT.py |
+++ b/PRESUBMIT.py |
@@ -31,6 +31,66 @@ _TEST_ONLY_WARNING = ( |
'Email joi@chromium.org if you have questions.') |
+_BANNED_FUNCTIONS = ( |
Mark Mentovai
2012/06/15 18:50:53
I would name this _BANNED_FUNCTIONS_OBJC…
|
+ ( |
+ 'addTrackingRect:', |
+ ('The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' |
+ 'prohibited. Please use CrTrackingArea instead.', |
+ 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
+ ), |
+ ), |
+ ( |
+ 'NSTrackingArea', |
+ ('The use of NSTrackingAreas is prohibited. Please use CrTrackingArea', |
+ 'instead.', |
+ 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
+ ), |
+ ), |
+ ( |
+ 'convertPointFromBase:', |
+ ('The use of -[NSView convertPointFromBase:] is almost certainly wrong.', |
+ 'Please use |convertPoint:(point) fromView:nil| instead.', |
+ 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
+ ), |
+ ), |
+ ( |
+ 'convertPointToBase:', |
+ ('The use of -[NSView convertPointToBase:] is almost certainly wrong.', |
+ 'Please use |convertPoint:(point) toView:nil| instead.', |
+ 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
+ ), |
+ ), |
+ ( |
+ 'convertRectFromBase:', |
+ ('The use of -[NSView convertRectFromBase:] is almost certainly wrong.', |
+ 'Please use |convertRect:(point) fromView:nil| instead.', |
+ 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
+ ), |
+ ), |
+ ( |
+ 'convertRectToBase:', |
+ ('The use of -[NSView convertRectToBase:] is almost certainly wrong.', |
+ 'Please use |convertRect:(point) toView:nil| instead.', |
+ 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
+ ), |
+ ), |
+ ( |
+ 'convertSizeFromBase:', |
+ ('The use of -[NSView convertSizeFromBase:] is almost certainly wrong.', |
+ 'Please use |convertSize:(point) fromView:nil| instead.', |
+ 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
+ ), |
+ ), |
+ ( |
+ 'convertSizeToBase:', |
+ ('The use of -[NSView convertSizeToBase:] is almost certainly wrong.', |
+ 'Please use |convertSize:(point) toView:nil| instead.', |
+ 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
+ ), |
+ ), |
+) |
+ |
+ |
def _CheckNoInterfacesInBase(input_api, output_api): |
"""Checks to make sure no files in libbase.a have |@interface|.""" |
@@ -219,6 +279,26 @@ def _CheckNoFilePathWatcherDelegate(input_api, output_api): |
'\n'.join(problems))] |
+def _CheckNoBannedFunctions(input_api, output_api): |
+ """Make sure that banned functions are not used.""" |
+ problems = [] |
+ |
+ file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h')) |
Mark Mentovai
2012/06/15 18:50:53
…and omit .cc but include .m.
Avi (use Gerrit)
2012/06/15 18:55:24
I did it this way deliberately. I wanted a general
Mark Mentovai
2012/06/15 18:58:25
Avi wrote:
|
+ for f in input_api.AffectedFiles(file_filter=file_filter): |
+ for line_num, line in f.ChangedContents(): |
+ for func_name, message in _BANNED_FUNCTIONS: |
+ if func_name in line: |
+ problems.append(' %s:%d:' % (f.LocalPath(), line_num)) |
+ for message_line in message: |
+ problems.append(' %s' % message_line) |
+ |
+ if not problems: |
+ return [] |
+ return [output_api.PresubmitPromptWarning('Banned functions were used.\n' + |
+ '\n'.join(problems))] |
+ |
+ |
+ |
def _CommonChecks(input_api, output_api): |
"""Checks common to both upload and commit.""" |
results = [] |
@@ -234,6 +314,7 @@ def _CommonChecks(input_api, output_api): |
results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) |
results.extend(_CheckNoScopedAllowIO(input_api, output_api)) |
results.extend(_CheckNoFilePathWatcherDelegate(input_api, output_api)) |
+ results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
return results |