Skip to content

Commit 3f8c00c

Browse files
authored
tools: disallowing visibility changes by default (#20590)
Testing: ran against #20552 :-) Leaving those BUILD files in as example exemptions. Fixes #20589 Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
1 parent 5642536 commit 3f8c00c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tools/code_format/check_format.py

+31
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,34 @@ def normalize_path(path):
11641164
if format_checker.check_error_messages(ct_error_messages):
11651165
sys.exit(1)
11661166

1167+
def check_visibility(error_messages):
1168+
# https://github.com/envoyproxy/envoy/issues/20589
1169+
# https://github.com/envoyproxy/envoy/issues/9953
1170+
# PLEASE DO NOT ADD FILES TO THIS LIST WITHOUT SENIOR MAINTAINER APPROVAL
1171+
exclude_list = (
1172+
"':(exclude)source/extensions/filters/http/buffer/BUILD' "
1173+
"':(exclude)source/extensions/filters/network/common/BUILD' ")
1174+
command = (
1175+
"git diff $(tools/git/last_github_commit.sh) -- source/extensions/* %s |grep '+.*visibility ='"
1176+
% exclude_list)
1177+
try:
1178+
output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT).strip()
1179+
if output:
1180+
error_messages.append(
1181+
"This change appears to add visibility rules. Please get senior maintainer "
1182+
"approval to add an exemption to check_visibility tools/code_format/check_format.py"
1183+
)
1184+
output = subprocess.check_output(
1185+
"grep -r --include BUILD envoy_package source/extensions/*",
1186+
shell=True,
1187+
stderr=subprocess.STDOUT).strip()
1188+
if output:
1189+
error_messages.append(
1190+
"envoy_package is not allowed to be used in source/extensions BUILD files.")
1191+
except subprocess.CalledProcessError as e:
1192+
if (e.returncode != 0 and e.returncode != 1):
1193+
error_messages.append("Failed to check visibility with command %s" % command)
1194+
11671195
# Returns the list of directories with owners listed in CODEOWNERS. May append errors to
11681196
# error_messages.
11691197
def owned_directories(error_messages):
@@ -1239,6 +1267,9 @@ def owned_directories(error_messages):
12391267
# Calculate the list of owned directories once per run.
12401268
error_messages = []
12411269
owned_directories = owned_directories(error_messages)
1270+
1271+
check_visibility(error_messages)
1272+
12421273
if os.path.isfile(args.target_path):
12431274
# All of our EXCLUDED_PREFIXES start with "./", but the provided
12441275
# target path argument might not. Add it here if it is missing,

0 commit comments

Comments
 (0)