@@ -1164,6 +1164,34 @@ def normalize_path(path):
1164
1164
if format_checker .check_error_messages (ct_error_messages ):
1165
1165
sys .exit (1 )
1166
1166
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
+
1167
1195
# Returns the list of directories with owners listed in CODEOWNERS. May append errors to
1168
1196
# error_messages.
1169
1197
def owned_directories (error_messages ):
@@ -1239,6 +1267,9 @@ def owned_directories(error_messages):
1239
1267
# Calculate the list of owned directories once per run.
1240
1268
error_messages = []
1241
1269
owned_directories = owned_directories (error_messages )
1270
+
1271
+ check_visibility (error_messages )
1272
+
1242
1273
if os .path .isfile (args .target_path ):
1243
1274
# All of our EXCLUDED_PREFIXES start with "./", but the provided
1244
1275
# target path argument might not. Add it here if it is missing,
0 commit comments