Commit 0303a3ad authored by Robert Ma's avatar Robert Ma Committed by Commit Bot

Use the new inclusive API in blink PRESUBMIT

Change the root PRESUBMIT_test_mocks.py as well to include the new API.
A compatibility layer is added to support the old API for now, and
should be removed when the old API is removed.

Fixed: 1108326
Bug: 1098560
Change-Id: I562686f265779cbdaf33134fd4d5af4bdcae6e0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2314196
Commit-Queue: Robert Ma <robertma@chromium.org>
Commit-Queue: Kentaro Hara <haraken@chromium.org>
Auto-Submit: Robert Ma <robertma@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790926}
parent a8b2ab5a
...@@ -60,6 +60,8 @@ class MockInputApi(object): ...@@ -60,6 +60,8 @@ class MockInputApi(object):
attribute as the list of changed files. attribute as the list of changed files.
""" """
DEFAULT_FILES_TO_SKIP = ()
# TODO(https://crbug.com/1098562): Remove once no longer used)
DEFAULT_BLACK_LIST = () DEFAULT_BLACK_LIST = ()
def __init__(self): def __init__(self):
...@@ -92,25 +94,30 @@ class MockInputApi(object): ...@@ -92,25 +94,30 @@ class MockInputApi(object):
def AffectedSourceFiles(self, file_filter=None): def AffectedSourceFiles(self, file_filter=None):
return self.AffectedFiles(file_filter=file_filter) return self.AffectedFiles(file_filter=file_filter)
def FilterSourceFile(self, file, white_list=(), black_list=()): def FilterSourceFile(self, file,
files_to_check=(), files_to_skip=(),
# TODO(https://crbug.com/1098562): Remove once no longer used
white_list=(), black_list=()):
files_to_check = files_to_check or white_list
files_to_skip = files_to_skip or black_list
local_path = file.LocalPath() local_path = file.LocalPath()
found_in_white_list = not white_list found_in_files_to_check = not files_to_check
if white_list: if files_to_check:
if type(white_list) is str: if type(files_to_check) is str:
raise TypeError('white_list should be an iterable of strings') raise TypeError('files_to_check should be an iterable of strings')
for pattern in white_list: for pattern in files_to_check:
compiled_pattern = re.compile(pattern) compiled_pattern = re.compile(pattern)
if compiled_pattern.search(local_path): if compiled_pattern.search(local_path):
found_in_white_list = True found_in_files_to_check = True
break break
if black_list: if files_to_skip:
if type(black_list) is str: if type(files_to_skip) is str:
raise TypeError('black_list should be an iterable of strings') raise TypeError('files_to_skip should be an iterable of strings')
for pattern in black_list: for pattern in files_to_skip:
compiled_pattern = re.compile(pattern) compiled_pattern = re.compile(pattern)
if compiled_pattern.search(local_path): if compiled_pattern.search(local_path):
return False return False
return found_in_white_list return found_in_files_to_check
def LocalPaths(self): def LocalPaths(self):
return [file.LocalPath() for file in self.files] return [file.LocalPath() for file in self.files]
......
...@@ -38,13 +38,12 @@ def _CheckForWrongMojomIncludes(input_api, output_api): ...@@ -38,13 +38,12 @@ def _CheckForWrongMojomIncludes(input_api, output_api):
# headers, except in public where only -shared.h headers should be # headers, except in public where only -shared.h headers should be
# used to avoid exporting Blink types outside Blink. # used to avoid exporting Blink types outside Blink.
def source_file_filter(path): def source_file_filter(path):
return input_api.FilterSourceFile( return input_api.FilterSourceFile(path,
path, files_to_skip=[
black_list=[ r'third_party/blink/common/',
r'third_party/blink/common/', r'third_party/blink/public/common',
r'third_party/blink/public/common', r'third_party/blink/renderer/platform/loader/fetch/url_loader',
r'third_party/blink/renderer/platform/loader/fetch/url_loader', ])
])
pattern = input_api.re.compile(r'#include\s+[<"](.+)\.mojom(.*)\.h[>"]') pattern = input_api.re.compile(r'#include\s+[<"](.+)\.mojom(.*)\.h[>"]')
public_folder = input_api.os_path.normpath('third_party/blink/public/') public_folder = input_api.os_path.normpath('third_party/blink/public/')
......
...@@ -32,18 +32,19 @@ for more details about the presubmit API built into gcl. ...@@ -32,18 +32,19 @@ for more details about the presubmit API built into gcl.
""" """
# Make sure binding templates are considered as source files. # Make sure binding templates are considered as source files.
WHITE_LIST = (r'.+\.tmpl$', ) FILES_TO_CHECK = (r'.+\.tmpl$', )
# Changes to v8/ do not change generated code or tests, so exclude from # Changes to v8/ do not change generated code or tests, so exclude from
# _RunBindingsTests # _RunBindingsTests
BLACK_LIST = (r'.*\bv8[\\\/].*', ) FILES_TO_SKIP = (r'.*\bv8[\\\/].*', )
def _RunBindingsTests(input_api, output_api): def _RunBindingsTests(input_api, output_api):
# Skip if nothing to do # Skip if nothing to do
source_filter = lambda x: input_api.FilterSourceFile( source_filter = lambda x: input_api.FilterSourceFile(
x, white_list=input_api.DEFAULT_WHITE_LIST + WHITE_LIST, x,
black_list=input_api.DEFAULT_BLACK_LIST + BLACK_LIST) files_to_check=input_api.DEFAULT_FILES_TO_CHECK + FILES_TO_CHECK,
files_to_skip=input_api.DEFAULT_FILES_TO_SKIP + FILES_TO_SKIP)
if not input_api.AffectedFiles(file_filter=source_filter): if not input_api.AffectedFiles(file_filter=source_filter):
return [] return []
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
def _GenerateTestCommand(input_api, output_api, file_name, affected_list): def _GenerateTestCommand(input_api, output_api, file_name, affected_list):
if not input_api.AffectedFiles( if not input_api.AffectedFiles(
file_filter= file_filter=lambda x: input_api.FilterSourceFile(
lambda x: input_api.FilterSourceFile(x, white_list=affected_list)): x, files_to_check=affected_list)):
return None return None
if input_api.is_committing: if input_api.is_committing:
......
...@@ -93,8 +93,7 @@ def _CheckForJSTest(input_api, output_api): ...@@ -93,8 +93,7 @@ def _CheckForJSTest(input_api, output_api):
jstest_re = input_api.re.compile(r'resources/js-test.js') jstest_re = input_api.re.compile(r'resources/js-test.js')
def source_file_filter(path): def source_file_filter(path):
return input_api.FilterSourceFile(path, return input_api.FilterSourceFile(path, files_to_check=[r'\.(html|js|php|pl|svg)$'])
white_list=[r'\.(html|js|php|pl|svg)$'])
errors = input_api.canned_checks._FindNewViolationsOfRule( errors = input_api.canned_checks._FindNewViolationsOfRule(
lambda _, x: not jstest_re.search(x), input_api, source_file_filter) lambda _, x: not jstest_re.search(x), input_api, source_file_filter)
......
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