From 0b90e2d2875d8c92418b21349c57e8a89cfd6b9c Mon Sep 17 00:00:00 2001 From: Shikugawa Date: Fri, 17 Jul 2020 19:27:30 +0900 Subject: [PATCH 1/2] format: add api-shadow starlark files checker Signed-off-by: Shikugawa --- tools/code_format/check_format.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tools/code_format/check_format.py b/tools/code_format/check_format.py index 351414da436b0..83bbab778cc8e 100755 --- a/tools/code_format/check_format.py +++ b/tools/code_format/check_format.py @@ -898,6 +898,24 @@ def checkOwners(dir_name, owned_directories, error_messages): error_messages.append("New directory %s appears to not have owners in CODEOWNERS" % dir_name) +def checkApiShadowStarlarkFiles(api_shadow_root, file_path, error_messages): + command = "diff -u " + command += file_path + " " + api_shadow_starlark_path = api_shadow_root + re.sub(r"\./api/", '', file_path) + command += api_shadow_starlark_path + + if not os.path.exists(api_shadow_starlark_path): + return error_messages + + error_message = executeCommand(command, "invalid .bzl in generated_api_shadow", file_path) + if operation_type == "check": + error_messages += error_message + elif operation_type == "fix" and len(error_message) != 0: + shutil.copy(file_path, api_shadow_starlark_path) + + return error_messages + + def checkFormatVisitor(arg, dir_name, names): """Run checkFormat in parallel for the given files. @@ -914,7 +932,7 @@ def checkFormatVisitor(arg, dir_name, names): # python lists are passed as references, this is used to collect the list of # async results (futures) from running checkFormat and passing them back to # the caller. - pool, result_list, owned_directories, error_messages = arg + pool, result_list, owned_directories, api_shadow_root, error_messages = arg # Sanity check CODEOWNERS. This doesn't need to be done in a multi-threaded # manner as it is a small and limited list. @@ -927,6 +945,10 @@ def checkFormatVisitor(arg, dir_name, names): checkOwners(dir_name[len(source_prefix):], owned_directories, error_messages) for file_name in names: + if dir_name.startswith("./api") and isSkylarkFile(file_name): + result = pool.apply_async(checkApiShadowStarlarkFiles, + args=(api_shadow_root, dir_name + "/" + file_name, error_messages)) + result_list.append(result) result = pool.apply_async(checkFormatReturnTraceOnError, args=(dir_name + "/" + file_name,)) result_list.append(result) @@ -993,6 +1015,7 @@ def checkErrorMessages(error_messages): operation_type = args.operation_type target_path = args.target_path + api_shadow_root = args.api_shadow_prefix envoy_build_rule_check = not args.skip_envoy_build_rule_check namespace_check = args.namespace_check namespace_check_excluded_paths = args.namespace_check_excluded_paths + [ @@ -1058,8 +1081,8 @@ def PooledCheckFormat(path_predicate): # For each file in target_path, start a new task in the pool and collect the # results (results is passed by reference, and is used as an output). for root, _, files in os.walk(target_path): - checkFormatVisitor((pool, results, owned_directories, error_messages), root, - [f for f in files if path_predicate(f)]) + checkFormatVisitor((pool, results, owned_directories, api_shadow_root, error_messages), + root, [f for f in files if path_predicate(f)]) # Close the pool to new tasks, wait for all of the running tasks to finish, # then collect the error messages. From 15f41c04144d2a5498d8609e8af343e96ec03fc7 Mon Sep 17 00:00:00 2001 From: Shikugawa Date: Fri, 17 Jul 2020 20:21:27 +0900 Subject: [PATCH 2/2] fix Signed-off-by: Shikugawa --- tools/code_format/check_format.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/code_format/check_format.py b/tools/code_format/check_format.py index 83bbab778cc8e..f107ce2d6d182 100755 --- a/tools/code_format/check_format.py +++ b/tools/code_format/check_format.py @@ -904,9 +904,6 @@ def checkApiShadowStarlarkFiles(api_shadow_root, file_path, error_messages): api_shadow_starlark_path = api_shadow_root + re.sub(r"\./api/", '', file_path) command += api_shadow_starlark_path - if not os.path.exists(api_shadow_starlark_path): - return error_messages - error_message = executeCommand(command, "invalid .bzl in generated_api_shadow", file_path) if operation_type == "check": error_messages += error_message