Skip to content

Commit

Permalink
Use the new inclusive API in blink PRESUBMIT
Browse files Browse the repository at this point in the history
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: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790926}
  • Loading branch information
Hexcles authored and Commit Bot committed Jul 22, 2020
1 parent a8b2ab5 commit 0303a3a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
31 changes: 19 additions & 12 deletions PRESUBMIT_test_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class MockInputApi(object):
attribute as the list of changed files.
"""

DEFAULT_FILES_TO_SKIP = ()
# TODO(https://crbug.com/1098562): Remove once no longer used)
DEFAULT_BLACK_LIST = ()

def __init__(self):
Expand Down Expand Up @@ -92,25 +94,30 @@ def AffectedFiles(self, file_filter=None, include_deletes=False):
def AffectedSourceFiles(self, file_filter=None):
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()
found_in_white_list = not white_list
if white_list:
if type(white_list) is str:
raise TypeError('white_list should be an iterable of strings')
for pattern in white_list:
found_in_files_to_check = not files_to_check
if files_to_check:
if type(files_to_check) is str:
raise TypeError('files_to_check should be an iterable of strings')
for pattern in files_to_check:
compiled_pattern = re.compile(pattern)
if compiled_pattern.search(local_path):
found_in_white_list = True
found_in_files_to_check = True
break
if black_list:
if type(black_list) is str:
raise TypeError('black_list should be an iterable of strings')
for pattern in black_list:
if files_to_skip:
if type(files_to_skip) is str:
raise TypeError('files_to_skip should be an iterable of strings')
for pattern in files_to_skip:
compiled_pattern = re.compile(pattern)
if compiled_pattern.search(local_path):
return False
return found_in_white_list
return found_in_files_to_check

def LocalPaths(self):
return [file.LocalPath() for file in self.files]
Expand Down
13 changes: 6 additions & 7 deletions third_party/blink/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ def _CheckForWrongMojomIncludes(input_api, output_api):
# headers, except in public where only -shared.h headers should be
# used to avoid exporting Blink types outside Blink.
def source_file_filter(path):
return input_api.FilterSourceFile(
path,
black_list=[
r'third_party/blink/common/',
r'third_party/blink/public/common',
r'third_party/blink/renderer/platform/loader/fetch/url_loader',
])
return input_api.FilterSourceFile(path,
files_to_skip=[
r'third_party/blink/common/',
r'third_party/blink/public/common',
r'third_party/blink/renderer/platform/loader/fetch/url_loader',
])

pattern = input_api.re.compile(r'#include\s+[<"](.+)\.mojom(.*)\.h[>"]')
public_folder = input_api.os_path.normpath('third_party/blink/public/')
Expand Down
9 changes: 5 additions & 4 deletions third_party/blink/renderer/bindings/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@
"""

# 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
# _RunBindingsTests
BLACK_LIST = (r'.*\bv8[\\\/].*', )
FILES_TO_SKIP = (r'.*\bv8[\\\/].*', )


def _RunBindingsTests(input_api, output_api):
# Skip if nothing to do
source_filter = lambda x: input_api.FilterSourceFile(
x, white_list=input_api.DEFAULT_WHITE_LIST + WHITE_LIST,
black_list=input_api.DEFAULT_BLACK_LIST + BLACK_LIST)
x,
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):
return []

Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/renderer/build/scripts/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

def _GenerateTestCommand(input_api, output_api, file_name, affected_list):
if not input_api.AffectedFiles(
file_filter=
lambda x: input_api.FilterSourceFile(x, white_list=affected_list)):
file_filter=lambda x: input_api.FilterSourceFile(
x, files_to_check=affected_list)):
return None

if input_api.is_committing:
Expand Down
3 changes: 1 addition & 2 deletions third_party/blink/web_tests/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def _CheckForJSTest(input_api, output_api):
jstest_re = input_api.re.compile(r'resources/js-test.js')

def source_file_filter(path):
return input_api.FilterSourceFile(path,
white_list=[r'\.(html|js|php|pl|svg)$'])
return input_api.FilterSourceFile(path, files_to_check=[r'\.(html|js|php|pl|svg)$'])

errors = input_api.canned_checks._FindNewViolationsOfRule(
lambda _, x: not jstest_re.search(x), input_api, source_file_filter)
Expand Down

0 comments on commit 0303a3a

Please sign in to comment.