mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[ssci] Added CheckChromiumDependencyMetadata in presubmit_canned_checks
This CL adds a new function `CheckChromiumDependencyMetadata` in `presubmit_canned_checks.py`. It can be used to check that files satisfy the format defined by `README.chromium.template` (https://chromium.googlesource.com/chromium/src/+/main/third_party/README.chromium.template). The code for metadata validation can be found in `//metadata`. Note that all metadata validation issues will be returned as warnings only for now, while the quality of metadata is being uplifted. Bug: b:277147404 Change-Id: Iacf1b3a11219ab752549f6dc6e882c93c0fbe780 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4812578 Commit-Queue: Anne Redulla <aredulla@google.com> Reviewed-by: Rachael Newitt <renewitt@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com> Reviewed-by: Bruce Dawson <brucedawson@chromium.org>
This commit is contained in:
@@ -10,6 +10,9 @@ import io as _io
|
||||
import os as _os
|
||||
import zlib
|
||||
|
||||
import metadata.discover
|
||||
import metadata.validate
|
||||
|
||||
_HERE = _os.path.dirname(_os.path.abspath(__file__))
|
||||
|
||||
# These filters will be disabled if callers do not explicitly supply a
|
||||
@@ -375,6 +378,7 @@ def CheckChangeHasNoCrAndHasOnlyOneEol(input_api, output_api,
|
||||
items=eof_files))
|
||||
return outputs
|
||||
|
||||
|
||||
def CheckGenderNeutral(input_api, output_api, source_file_filter=None):
|
||||
"""Checks that there are no gendered pronouns in any of the text files to be
|
||||
submitted.
|
||||
@@ -398,7 +402,6 @@ def CheckGenderNeutral(input_api, output_api, source_file_filter=None):
|
||||
return []
|
||||
|
||||
|
||||
|
||||
def _ReportErrorFileAndLine(filename, line_num, dummy_line):
|
||||
"""Default error formatter for _FindNewViolationsOfRule."""
|
||||
return '%s:%s' % (filename, line_num)
|
||||
@@ -789,6 +792,41 @@ def CheckLicense(input_api, output_api, license_re_param=None,
|
||||
return results
|
||||
|
||||
|
||||
def CheckChromiumDependencyMetadata(input_api, output_api, file_filter=None):
|
||||
"""Check files for Chromium third party dependency metadata have sufficient
|
||||
information, and are correctly formatted.
|
||||
|
||||
See the README.chromium.template at
|
||||
https://chromium.googlesource.com/chromium/src/+/main/third_party/README.chromium.template
|
||||
"""
|
||||
# If the file filter is unspecified, filter to known Chromium metadata files.
|
||||
if file_filter is None:
|
||||
file_filter = lambda f: metadata.discover.is_metadata_file(f.LocalPath())
|
||||
|
||||
# The repo's root directory is required to check license files.
|
||||
repo_root_dir = input_api.change.RepositoryRoot()
|
||||
|
||||
outputs = []
|
||||
for f in input_api.AffectedFiles(file_filter=file_filter):
|
||||
if f.Action() == 'D':
|
||||
# No need to validate a deleted file.
|
||||
continue
|
||||
|
||||
errors, warnings = metadata.validate.check_file(
|
||||
filepath=f.AbsoluteLocalPath(),
|
||||
repo_root_dir=repo_root_dir,
|
||||
reader=input_api.ReadFile,
|
||||
)
|
||||
|
||||
for warning in warnings:
|
||||
outputs.append(output_api.PresubmitPromptWarning(warning, [f]))
|
||||
|
||||
for error in errors:
|
||||
outputs.append(output_api.PresubmitError(error, [f]))
|
||||
|
||||
return outputs
|
||||
|
||||
|
||||
### Other checks
|
||||
|
||||
def CheckDoNotSubmit(input_api, output_api):
|
||||
@@ -843,6 +881,7 @@ def CheckTreeIsOpen(input_api, output_api,
|
||||
long_text=str(e))]
|
||||
return []
|
||||
|
||||
|
||||
def GetUnitTestsInDirectory(input_api,
|
||||
output_api,
|
||||
directory,
|
||||
|
||||
Reference in New Issue
Block a user