@ -14,19 +14,31 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
""" Explicitly ban select functions from being used in gRPC. """
# 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.
# We are currently working on clearing out the usage of deprecated functions in
# the entire gRPC code base.
# While our cleaning is in progress we have a temporary allow list. The allow
# list has a list of files where clean up of deprecated functions is pending.
# As we clean up the deprecated function from files, we will remove them from
# the allow list.
# It would be wise to do the file clean up and the altering of the allow list
# in the same PR. This will make sure that any roll back of a clean up PR will
# also alter the allow list and avoid build failures.
import os
import os
import sys
import sys
os . chdir ( os . path . join ( os . path . dirname ( sys . argv [ 0 ] ) , " ../../.. " ) )
os . chdir ( os . path . join ( os . path . dirname ( sys . argv [ 0 ] ) , " ../../.. " ) )
# map of banned function signature to allowlist
# Map of deprecated functions to allowlist files
BANNED_EXCEPT = {
DEPRECATED_FUNCTION_TEMP_ALLOW_LIS T = {
" gpr_log_severity " : [
" gpr_log_severity " : [
" ./include/grpc/support/log.h " ,
" ./include/grpc/support/log.h " ,
" ./src/core/lib/channel/channel_stack.cc " ,
" ./src/core/lib/channel/channel_stack.h " ,
" ./src/core/lib/surface/call.h " ,
" ./src/core/lib/surface/call.h " ,
" ./src/core/lib/surface/call_log_batch.cc " ,
" ./src/core/lib/surface/call_log_batch.cc " ,
" ./src/core/util/android/log.cc " ,
" ./src/core/util/android/log.cc " ,
@ -40,11 +52,7 @@ BANNED_EXCEPT = {
] ,
] ,
" gpr_log_severity_string( " : [
" gpr_log_severity_string( " : [
" ./include/grpc/support/log.h " ,
" ./include/grpc/support/log.h " ,
" ./src/core/util/android/log.cc " ,
" ./src/core/util/linux/log.cc " ,
" ./src/core/util/log.cc " ,
" ./src/core/util/log.cc " ,
" ./src/core/util/posix/log.cc " ,
" ./src/core/util/windows/log.cc " ,
] ,
] ,
" gpr_log( " : [
" gpr_log( " : [
" ./include/grpc/support/log.h " ,
" ./include/grpc/support/log.h " ,
@ -92,7 +100,6 @@ BANNED_EXCEPT = {
" ./src/core/handshaker/http_connect/http_connect_handshaker.cc " ,
" ./src/core/handshaker/http_connect/http_connect_handshaker.cc " ,
" ./src/core/handshaker/http_connect/http_proxy_mapper.cc " ,
" ./src/core/handshaker/http_connect/http_proxy_mapper.cc " ,
" ./src/core/handshaker/security/secure_endpoint.cc " ,
" ./src/core/handshaker/security/secure_endpoint.cc " ,
" ./src/core/lib/channel/channel_stack.cc " ,
" ./src/core/lib/event_engine/ares_resolver.h " ,
" ./src/core/lib/event_engine/ares_resolver.h " ,
" ./src/core/lib/event_engine/cf_engine/cf_engine.cc " ,
" ./src/core/lib/event_engine/cf_engine/cf_engine.cc " ,
" ./src/core/lib/event_engine/posix_engine/posix_engine.cc " ,
" ./src/core/lib/event_engine/posix_engine/posix_engine.cc " ,
@ -156,7 +163,6 @@ BANNED_EXCEPT = {
" ./src/core/lib/transport/bdp_estimator.cc " ,
" ./src/core/lib/transport/bdp_estimator.cc " ,
" ./src/core/lib/transport/bdp_estimator.h " ,
" ./src/core/lib/transport/bdp_estimator.h " ,
" ./src/core/lib/transport/call_filters.cc " ,
" ./src/core/lib/transport/call_filters.cc " ,
" ./src/core/lib/transport/call_filters.h " ,
" ./src/core/lib/transport/connectivity_state.cc " ,
" ./src/core/lib/transport/connectivity_state.cc " ,
" ./src/core/lib/transport/transport.h " ,
" ./src/core/lib/transport/transport.h " ,
" ./src/core/load_balancing/grpclb/grpclb.cc " ,
" ./src/core/load_balancing/grpclb/grpclb.cc " ,
@ -236,26 +242,17 @@ BANNED_EXCEPT = {
] ,
] ,
" gpr_log_func_args " : [
" gpr_log_func_args " : [
" ./include/grpc/support/log.h " ,
" ./include/grpc/support/log.h " ,
" ./src/core/util/android/log.cc " ,
" ./src/core/util/linux/log.cc " ,
" ./src/core/util/log.cc " ,
" ./src/core/util/log.cc " ,
" ./src/core/util/posix/log.cc " ,
" ./src/core/util/windows/log.cc " ,
" ./test/core/end2end/tests/no_logging.cc " ,
" ./test/core/end2end/tests/no_logging.cc " ,
" ./test/cpp/interop/stress_test.cc " ,
] ,
] ,
" gpr_set_log_function( " : [
" gpr_set_log_function( " : [
" ./include/grpc/support/log.h " ,
" ./include/grpc/support/log.h " ,
" ./src/core/util/log.cc " ,
" ./src/core/util/log.cc " ,
" ./test/core/end2end/tests/no_logging.cc " ,
" ./test/core/end2end/tests/no_logging.cc " ,
" ./test/cpp/interop/stress_test.cc " ,
] ,
" gpr_assertion_failed( " : [
" ./include/grpc/support/log.h " ,
" ./src/core/util/log.cc " ,
] ,
] ,
" GPR_ASSERT( " : [ ] ,
" gpr_assertion_failed " : [ ] ,
" GPR_DEBUG_ASSERT( " : [ ] ,
" GPR_ASSERT " : [ ] ,
" GPR_DEBUG_ASSERT " : [ ] ,
}
}
errors = 0
errors = 0
@ -272,14 +269,16 @@ for root, dirs, files in os.walk("."):
continue
continue
with open ( path ) as f :
with open ( path ) as f :
text = f . read ( )
text = f . read ( )
for banned , exceptions in list ( BANNED_EXCEPT . items ( ) ) :
for deprecated , allowlist in list (
if path in exceptions :
DEPRECATED_FUNCTION_TEMP_ALLOW_LIST . items ( )
) :
if path in allowlist :
continue
continue
if banned in text :
if deprecat ed in text :
print (
print (
(
(
' Illegal use of " %s " in %s . Use absl functions instead. '
' Illegal use of " %s " in %s . Use absl functions instead. '
% ( bann ed, path )
% ( deprecat ed, path )
)
)
)
)
errors + = 1
errors + = 1