Commit 9bbaed53 authored by Luis Hector Chavez's avatar Luis Hector Chavez Committed by Commit Bot

Add presubmit check for base::Bind/base::Callback

In order to reduce the number of base::Bind/base::Callback uses added to
the codebase while we are in the process of a migration, we can add a
global PRESUBMIT.py hook to nudge people to use the new interfaces.

Bug: 714018
Test: git cl try
Change-Id: I60741a1532a060fc75f3aeb1533e88abbdf9cfe7
Reviewed-on: https://chromium-review.googlesource.com/794879Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarTaiju Tsuiki <tzik@chromium.org>
Commit-Queue: Luis Hector Chavez <lhchavez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520611}
parent 56db65a6
......@@ -437,6 +437,33 @@ _BANNED_CPP_FUNCTIONS = (
True,
(),
),
(
r'/\bbase::Bind\(',
(
'Please consider using base::Bind{Once,Repeating} instead '
'of base::Bind. (crbug/714018)',
),
False,
(),
),
(
r'/\bbase::Callback<',
(
'Please consider using base::{Once,Repeating}Callback instead '
'of base::Callback. (crbug/714018)',
),
False,
(),
),
(
r'/\bbase::Closure\b',
(
'Please consider using base::{Once,Repeating}Closure instead '
'of base::Closure. (crbug/714018)',
),
False,
(),
),
)
......
......@@ -5,39 +5,6 @@
_CPP_WHITE_LIST = (r'.+\.cc$', r'.+\.h$')
def CheckCallback(input_api, output_api):
"""Discourages the use of deprecated base::{Bind,Callback,Closure}."""
# This contains a list of regex and a human-readable error message.
patterns = [
(r'\bbase::Bind\(',
'uses base::Bind. Please consider using base::Bind{Once,Repeating} '
'instead.'),
(r'\bbase::Callback<',
'uses base::Callback. Please consider using '
'base::{Once,Repeating}Callback instead'),
(r'\bbase::Closure\b',
'uses base::Closure. Please consider using '
'base::{Once,Repeating}Closure instead'),
]
problems = []
def SourceFilter(affected_file):
return input_api.FilterSourceFile(affected_file, _CPP_WHITE_LIST,
input_api.DEFAULT_BLACK_LIST)
for f in input_api.AffectedSourceFiles(SourceFilter):
for line_number, line in f.ChangedContents():
for pattern in patterns:
if input_api.re.search(pattern[0], line):
problems.append(
'%s:%d %s' % (f.LocalPath(), line_number, pattern[1]))
if problems:
return [output_api.PresubmitPromptWarning(
'base::Bind, base::Closure, and base::Callback are in the process ' +
'of being deprecated. See crbug.com/714018 for more information ' +
'about the migration\n',
items=problems)]
return []
def CheckMakeUnique(input_api, output_api):
"""Encourage to use std::make_unique, instead of base::MakeUnique."""
errors = []
......@@ -68,7 +35,6 @@ def CheckChangeOnUpload(input_api, output_api):
results = []
results += input_api.canned_checks.CheckChangeLintsClean(
input_api, output_api)
results += CheckCallback(input_api, output_api)
results += CheckUniquePtr(input_api, output_api)
results += CheckMakeUnique(input_api, output_api)
return results
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment