diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-28 18:40:07 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-28 18:40:07 +0000 |
commit | ecdf8ea54dd5cc25f9a24a1c9108f8a50bbd25c6 (patch) | |
tree | b27b73baaad4283936f17bb5b27c6c815602d56b /PRESUBMIT.py | |
parent | 0633e315df85edb2b96dff1518ab05a74dad15d1 (diff) | |
download | chromium_src-ecdf8ea54dd5cc25f9a24a1c9108f8a50bbd25c6.zip chromium_src-ecdf8ea54dd5cc25f9a24a1c9108f8a50bbd25c6.tar.gz chromium_src-ecdf8ea54dd5cc25f9a24a1c9108f8a50bbd25c6.tar.bz2 |
Add a presubmit to find new uses of the old callback system.
BUG=none
TEST=edit files locally, add random references to the old callback system, and run presubmit.
Review URL: http://codereview.chromium.org/8714008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111729 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'PRESUBMIT.py')
-rw-r--r-- | PRESUBMIT.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index dce79ab..c97c1ac9 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -178,6 +178,36 @@ def _CheckNoFRIEND_TEST(input_api, output_api): 'FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))] +def _CheckNoNewOldCallback(input_api, output_api): + """Checks to make sure we don't introduce new uses of old callbacks.""" + + def HasOldCallbackKeywords(line): + """Returns True if a line of text contains keywords that indicate the use + of the old callback system. + """ + return ('NewRunnableMethod' in line or + 'NewRunnableFunction' in line or + 'NewCallback' in line or + input_api.re.search(r'\bCallback\d<', line) or + input_api.re.search(r'\bpublic Task\b', line) or + 'public CancelableTask' in line) + + problems = [] + file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h')) + for f in input_api.AffectedFiles(file_filter=file_filter): + if not any(HasOldCallbackKeywords(line) for line in f.NewContents()): + continue + for line_num, line in f.ChangedContents(): + if HasOldCallbackKeywords(line): + problems.append(' %s:%d' % (f.LocalPath(), line_num)) + + if not problems: + return [] + return [output_api.PresubmitPromptWarning('The old callback system is ' + 'deprecated. If possible, use base::Bind and base::Callback instead.\n' + + '\n'.join(problems))] + + def _CommonChecks(input_api, output_api): """Checks common to both upload and commit.""" results = [] @@ -191,6 +221,7 @@ def _CommonChecks(input_api, output_api): results.extend(_CheckNoNewWStrings(input_api, output_api)) results.extend(_CheckNoDEPSGIT(input_api, output_api)) results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) + results.extend(_CheckNoNewOldCallback(input_api, output_api)) return results |