The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#) https://grpc.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.9 KiB

#!/usr/bin/env python3
# Copyright 2024 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Explicitly ban select functions from being used in gRPC.
# Any new instance of a deprecated function being used in the code will be
# flagged by the script. If there is a new instance of a deprecated function in
# a Pull Request, then the Sanity tests will fail for the Pull Request.
# The allow list has a list of files where clean up of deprecated functions is
# pending.
import os
import sys
os.chdir(os.path.join(os.path.dirname(sys.argv[0]), "../../.."))
[Gpr_To_Absl_Logging] Remove gpr_log. Adding absl LOG wrappers. (#37431) [Gpr_To_Absl_Logging] Remove gpr_log. Adding absl LOG wrappers List of changes in this PR 1. Replacing all instances of gpr_log in PHP and RUBY with the new absl wrapper APIs. The replacement mapping is given below gpr_log(GPR_ERROR, ...) => grpc_absl_log_error gpr_log(GPR_INFO, ...) => grpc_absl_log_info - Printing a simple message => grpc_absl_log_info_int - Printing a message and a number => grpc_absl_log_info_str - Printing 2 strings. gpr_log(GPR_DEBUG, ...) => grpc_absl_vlog - Printing a simple message => grpc_absl_vlog_int - Printing a message and a number => grpc_absl_vlog_str - Printing 2 strings. Adding grpc_absl_vlog2_enabled() check around gpr_log(GPR_DEBUG, ...) 2. src/python/grpcio_observability/grpc_observability/observability_util.cc One instance of gpr_log to absl LOG replacement was missed earlier. Fixing that. 3. Deleting deprecated gpr stuff : gpr_log_severity , GPR_DEBUG , GPR_INFO , GPR_ERROR , gpr_log . 4. Adding new APIs for Ruby and PHP. These APIs are very simple wrappers around absl. 5. Removing the legacy functions in platform specific log.cc files. These files are safe to delete now. 6. Fixing the allow list in banned_functions.py . This makes sure that these new wrappers don't get used all over the place by everyone. We carefully only allow list the PHP and RUBY files and allow the use of these wrappers. Everywhere else - using these wrappers should fail Sanity Tests. Closes #37431 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37431 from tanvi-jagtap:remove_gpr_error 6e5e9bcfcc5e08f2ce7f5bf583544ee91ef00350 PiperOrigin-RevId: 668586873
6 months ago
# More files may be added to the RUBY_PHP_ALLOW_LIST
# if they belong to the PHP or RUBY folder.
RUBY_PHP_ALLOW_LIST = [
"./include/grpc/support/log.h",
"./src/core/util/log.cc",
"./src/php/ext/grpc/call_credentials.c",
"./src/php/ext/grpc/channel.c",
"./src/ruby/ext/grpc/rb_call.c",
"./src/ruby/ext/grpc/rb_call_credentials.c",
"./src/ruby/ext/grpc/rb_channel.c",
"./src/ruby/ext/grpc/rb_event_thread.c",
"./src/ruby/ext/grpc/rb_grpc.c",
"./src/ruby/ext/grpc/rb_server.c",
]
# Map of deprecated functions to allowlist files
DEPRECATED_FUNCTION_TEMP_ALLOW_LIST = {
[Gpr_To_Absl_Logging] Remove gpr_log. Adding absl LOG wrappers. (#37431) [Gpr_To_Absl_Logging] Remove gpr_log. Adding absl LOG wrappers List of changes in this PR 1. Replacing all instances of gpr_log in PHP and RUBY with the new absl wrapper APIs. The replacement mapping is given below gpr_log(GPR_ERROR, ...) => grpc_absl_log_error gpr_log(GPR_INFO, ...) => grpc_absl_log_info - Printing a simple message => grpc_absl_log_info_int - Printing a message and a number => grpc_absl_log_info_str - Printing 2 strings. gpr_log(GPR_DEBUG, ...) => grpc_absl_vlog - Printing a simple message => grpc_absl_vlog_int - Printing a message and a number => grpc_absl_vlog_str - Printing 2 strings. Adding grpc_absl_vlog2_enabled() check around gpr_log(GPR_DEBUG, ...) 2. src/python/grpcio_observability/grpc_observability/observability_util.cc One instance of gpr_log to absl LOG replacement was missed earlier. Fixing that. 3. Deleting deprecated gpr stuff : gpr_log_severity , GPR_DEBUG , GPR_INFO , GPR_ERROR , gpr_log . 4. Adding new APIs for Ruby and PHP. These APIs are very simple wrappers around absl. 5. Removing the legacy functions in platform specific log.cc files. These files are safe to delete now. 6. Fixing the allow list in banned_functions.py . This makes sure that these new wrappers don't get used all over the place by everyone. We carefully only allow list the PHP and RUBY files and allow the use of these wrappers. Everywhere else - using these wrappers should fail Sanity Tests. Closes #37431 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37431 from tanvi-jagtap:remove_gpr_error 6e5e9bcfcc5e08f2ce7f5bf583544ee91ef00350 PiperOrigin-RevId: 668586873
6 months ago
# These experimental logging functions are only for php and ruby.
"grpc_absl_log(": RUBY_PHP_ALLOW_LIST,
"grpc_absl_log_int(": RUBY_PHP_ALLOW_LIST,
"grpc_absl_log_str(": RUBY_PHP_ALLOW_LIST,
# These have been deprecated.
# Most of these have been deleted.
# Putting this check here just to prevent people from
# submitting PRs with any of these commented out.
"gpr_assertion_failed": [], # Safe to delete this entry after Nov 2024.
"gpr_log(": [], # Safe to delete this entry after Nov 2024.
"gpr_log_func_args": [], # Safe to delete this entry after Nov 2024.
[Gpr_To_Absl_Logging] Remove gpr_log. Adding absl LOG wrappers. (#37431) [Gpr_To_Absl_Logging] Remove gpr_log. Adding absl LOG wrappers List of changes in this PR 1. Replacing all instances of gpr_log in PHP and RUBY with the new absl wrapper APIs. The replacement mapping is given below gpr_log(GPR_ERROR, ...) => grpc_absl_log_error gpr_log(GPR_INFO, ...) => grpc_absl_log_info - Printing a simple message => grpc_absl_log_info_int - Printing a message and a number => grpc_absl_log_info_str - Printing 2 strings. gpr_log(GPR_DEBUG, ...) => grpc_absl_vlog - Printing a simple message => grpc_absl_vlog_int - Printing a message and a number => grpc_absl_vlog_str - Printing 2 strings. Adding grpc_absl_vlog2_enabled() check around gpr_log(GPR_DEBUG, ...) 2. src/python/grpcio_observability/grpc_observability/observability_util.cc One instance of gpr_log to absl LOG replacement was missed earlier. Fixing that. 3. Deleting deprecated gpr stuff : gpr_log_severity , GPR_DEBUG , GPR_INFO , GPR_ERROR , gpr_log . 4. Adding new APIs for Ruby and PHP. These APIs are very simple wrappers around absl. 5. Removing the legacy functions in platform specific log.cc files. These files are safe to delete now. 6. Fixing the allow list in banned_functions.py . This makes sure that these new wrappers don't get used all over the place by everyone. We carefully only allow list the PHP and RUBY files and allow the use of these wrappers. Everywhere else - using these wrappers should fail Sanity Tests. Closes #37431 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37431 from tanvi-jagtap:remove_gpr_error 6e5e9bcfcc5e08f2ce7f5bf583544ee91ef00350 PiperOrigin-RevId: 668586873
6 months ago
"gpr_log_message": [], # Safe to delete this entry after Nov 2024.
"gpr_log_severity_string": [], # Safe to delete this entry after Nov 2024.
"gpr_set_log_function": [], # Safe to delete this entry after Nov 2024.
"gpr_set_log_verbosity": [], # Safe to delete this entry after Nov 2024.
"gpr_should_log": [], # Safe to delete this entry after Nov 2024.
"GPR_ASSERT": [], # Safe to delete this entry after Nov 2024.
"GPR_DEBUG_ASSERT": [], # Safe to delete this entry after Nov 2024.
}
errors = 0
num_files = 0
for root, dirs, files in os.walk("."):
for filename in files:
num_files += 1
path = os.path.join(root, filename)
if os.path.splitext(path)[1] not in (".h", ".cc", ".c"):
continue
with open(path) as f:
text = f.read()
for deprecated, allowlist in list(
DEPRECATED_FUNCTION_TEMP_ALLOW_LIST.items()
):
if path in allowlist:
continue
if deprecated in text:
print(
(
'Illegal use of "%s" in %s. Use absl functions instead.'
% (deprecated, path)
)
)
errors += 1
assert errors == 0
if errors > 0:
print(("Number of errors : %d " % (errors)))
# This check comes about from this issue:
# https://github.com/grpc/grpc/issues/15381
# Basically, a change rendered this script useless and we did not realize it.
# This check ensures that this type of issue doesn't occur again.
assert num_files > 18000
print("Number of files checked : %d " % (num_files))