Remove the #undef check from the Presubmit for .cc files
This CL attempts to remove the #undef check from the Presubmit for .cc files because we are removing Jumbo support. Bug: chromium:994387 Change-Id: I1bb6d22393c1b533f23dd586e5028ecc6d254c99 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2013119 Reviewed-by: Clemens Backes <clemensb@chromium.org> Reviewed-by: Wez <wez@chromium.org> Reviewed-by: Michael Achenbach <machenbach@chromium.org> Commit-Queue: Almothana Athamneh <almuthanna@chromium.org> Cr-Commit-Position: refs/heads/master@{#65978}
This commit is contained in:
parent
3fa75eca1b
commit
1830560967
63
PRESUBMIT.py
63
PRESUBMIT.py
@ -391,7 +391,6 @@ def _CommonChecks(input_api, output_api):
|
|||||||
_CheckHeadersHaveIncludeGuards,
|
_CheckHeadersHaveIncludeGuards,
|
||||||
_CheckNoInlineHeaderIncludesInNormalHeaders,
|
_CheckNoInlineHeaderIncludesInNormalHeaders,
|
||||||
_CheckJSONFiles,
|
_CheckJSONFiles,
|
||||||
_CheckMacroUndefs,
|
|
||||||
_CheckNoexceptAnnotations,
|
_CheckNoexceptAnnotations,
|
||||||
_RunTestsWithVPythonSpec,
|
_RunTestsWithVPythonSpec,
|
||||||
]
|
]
|
||||||
@ -454,68 +453,6 @@ def _CheckJSONFiles(input_api, output_api):
|
|||||||
return [output_api.PresubmitError(r) for r in results]
|
return [output_api.PresubmitError(r) for r in results]
|
||||||
|
|
||||||
|
|
||||||
def _CheckMacroUndefs(input_api, output_api):
|
|
||||||
"""
|
|
||||||
Checks that each #define in a .cc file is eventually followed by an #undef.
|
|
||||||
|
|
||||||
TODO(clemensb): This check should eventually be enabled for all cc files via
|
|
||||||
tools/presubmit.py (https://crbug.com/v8/6811).
|
|
||||||
"""
|
|
||||||
def FilterFile(affected_file):
|
|
||||||
# Skip header files, as they often define type lists which are used in
|
|
||||||
# other files.
|
|
||||||
white_list = (r'.+\.cc',r'.+\.cpp',r'.+\.c')
|
|
||||||
return input_api.FilterSourceFile(affected_file, white_list=white_list)
|
|
||||||
|
|
||||||
def Touches(line):
|
|
||||||
return line.startswith('+') or line.startswith('-')
|
|
||||||
|
|
||||||
def InvolvesMacros(text):
|
|
||||||
return define_pattern.match(text) or undef_pattern.match(text)
|
|
||||||
|
|
||||||
def TouchesMacros(f):
|
|
||||||
return any(Touches(line) and InvolvesMacros(line[1:])
|
|
||||||
for line in f.GenerateScmDiff().splitlines())
|
|
||||||
|
|
||||||
def CollectUndefsWithNoDef(defined_macros, errors, f, line, line_nr):
|
|
||||||
define_match = define_pattern.match(line)
|
|
||||||
if define_match:
|
|
||||||
name = define_match.group(1)
|
|
||||||
defined_macros[name] = line_nr
|
|
||||||
undef_match = undef_pattern.match(line)
|
|
||||||
if undef_match and not "// NOLINT" in line:
|
|
||||||
name = undef_match.group(1)
|
|
||||||
if name in defined_macros:
|
|
||||||
del defined_macros[name]
|
|
||||||
else:
|
|
||||||
errors.append('{}:{}: Macro named \'{}\' was not defined before.'
|
|
||||||
.format(f.LocalPath(), line_nr, name))
|
|
||||||
|
|
||||||
define_pattern = input_api.re.compile(r'#define (\w+)')
|
|
||||||
undef_pattern = input_api.re.compile(r'#undef (\w+)')
|
|
||||||
errors = []
|
|
||||||
for f in input_api.AffectedFiles(
|
|
||||||
file_filter=FilterFile, include_deletes=False):
|
|
||||||
if not TouchesMacros(f):
|
|
||||||
continue
|
|
||||||
|
|
||||||
defined_macros = dict()
|
|
||||||
with open(f.LocalPath()) as fh:
|
|
||||||
for line_nr, line in enumerate(fh, start=1):
|
|
||||||
CollectUndefsWithNoDef(defined_macros, errors, f, line, line_nr)
|
|
||||||
|
|
||||||
for name, line_nr in sorted(defined_macros.items(), key=lambda e: e[1]):
|
|
||||||
errors.append('{}:{}: Macro missing #undef: {}'
|
|
||||||
.format(f.LocalPath(), line_nr, name))
|
|
||||||
|
|
||||||
if errors:
|
|
||||||
return [output_api.PresubmitPromptOrNotify(
|
|
||||||
'Detected mismatches in #define / #undef in the file(s) where you '
|
|
||||||
'modified preprocessor macros.',
|
|
||||||
errors)]
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
def _CheckNoexceptAnnotations(input_api, output_api):
|
def _CheckNoexceptAnnotations(input_api, output_api):
|
||||||
"""
|
"""
|
||||||
Checks that all user-defined constructors and assignment operators are marked
|
Checks that all user-defined constructors and assignment operators are marked
|
||||||
|
Loading…
Reference in New Issue
Block a user