[bazel] Add Presubmit to remind devs about adding/deleting files.

Bug: skia:12541
Change-Id: Idc8f9e721dc172d4ff2b4884d36363a882293ee6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541416
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Ravi Mistry <rmistry@google.com>
This commit is contained in:
Kevin Lubick 2022-05-17 13:43:52 -04:00
parent 94d7609696
commit 8d9d9fa93a

View File

@ -290,6 +290,29 @@ def _CheckBazelBUILDFiles(input_api, output_api):
))
return results
def _CheckPublicBzl(input_api, output_api):
"""Reminds devs to add/remove files from public.bzl."""
results = []
public_bzl = ''
with open('public.bzl', 'r', encoding='utf-8') as f:
public_bzl = f.read().strip()
for affected_file in input_api.AffectedFiles(include_deletes=True):
# action is A for newly added, D for newly deleted, M for modified
action = affected_file.Action()
affected_file_path = affected_file.LocalPath()
if ((affected_file_path.startswith("include") or affected_file_path.startswith("src")) and
(affected_file_path.endswith(".cpp") or affected_file_path.endswith(".h"))):
affected_file_path = '"' + affected_file_path + '"'
if action == "D" and affected_file_path in public_bzl:
results.append(output_api.PresubmitError(
"Need to delete %s from public.bzl (or rename it)" % affected_file_path))
elif action == "A" and affected_file_path not in public_bzl:
results.append(output_api.PresubmitPromptWarning(
"You may need to add %s to public.bzl" % affected_file_path))
return results
def _CommonChecks(input_api, output_api):
"""Presubmit checks common to upload and commit."""
results = []
@ -330,6 +353,9 @@ def CheckChangeOnUpload(input_api, output_api):
# coverage or Go installed.
results.extend(_InfraTests(input_api, output_api))
results.extend(_CheckReleaseNotesForPublicAPI(input_api, output_api))
# Only check public.bzl on upload because new files are likely to be a source
# of false positives and we don't want to unnecessarily block commits.
results.extend(_CheckPublicBzl(input_api, output_api))
return results