From 8d9d9fa93aaaa75ce3cf8fb36794fb383d6f4938 Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Tue, 17 May 2022 13:43:52 -0400 Subject: [PATCH] [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 Reviewed-by: Ravi Mistry --- PRESUBMIT.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index b54c80193c..7e0881258f 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -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