check_deprecated_grpc++.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 # Copyright 2018 gRPC authors.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 import os
18 import sys
19 
20 os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '../../..'))
21 
22 expected_files = [
23  "include/grpc++/create_channel_posix.h", "include/grpc++/server_builder.h",
24  "include/grpc++/resource_quota.h", "include/grpc++/create_channel.h",
25  "include/grpc++/alarm.h", "include/grpc++/server.h",
26  "include/grpc++/server_context.h", "include/grpc++/client_context.h",
27  "include/grpc++/server_posix.h", "include/grpc++/grpc++.h",
28  "include/grpc++/health_check_service_interface.h",
29  "include/grpc++/completion_queue.h", "include/grpc++/channel.h",
30  "include/grpc++/support/sync_stream.h", "include/grpc++/support/status.h",
31  "include/grpc++/support/config.h",
32  "include/grpc++/support/status_code_enum.h",
33  "include/grpc++/support/byte_buffer.h",
34  "include/grpc++/support/error_details.h",
35  "include/grpc++/support/async_unary_call.h",
36  "include/grpc++/support/channel_arguments.h",
37  "include/grpc++/support/async_stream.h", "include/grpc++/support/slice.h",
38  "include/grpc++/support/stub_options.h",
39  "include/grpc++/support/string_ref.h", "include/grpc++/support/time.h",
40  "include/grpc++/security/auth_metadata_processor.h",
41  "include/grpc++/security/credentials.h",
42  "include/grpc++/security/server_credentials.h",
43  "include/grpc++/security/auth_context.h",
44  "include/grpc++/impl/rpc_method.h",
45  "include/grpc++/impl/server_builder_option.h", "include/grpc++/impl/call.h",
46  "include/grpc++/impl/service_type.h", "include/grpc++/impl/grpc_library.h",
47  "include/grpc++/impl/client_unary_call.h",
48  "include/grpc++/impl/channel_argument_option.h",
49  "include/grpc++/impl/rpc_service_method.h",
50  "include/grpc++/impl/method_handler_impl.h",
51  "include/grpc++/impl/server_builder_plugin.h",
52  "include/grpc++/impl/server_initializer.h",
53  "include/grpc++/impl/serialization_traits.h",
54  "include/grpc++/impl/codegen/sync_stream.h",
55  "include/grpc++/impl/codegen/channel_interface.h",
56  "include/grpc++/impl/codegen/config_protobuf.h",
57  "include/grpc++/impl/codegen/status.h",
58  "include/grpc++/impl/codegen/core_codegen.h",
59  "include/grpc++/impl/codegen/config.h",
60  "include/grpc++/impl/codegen/core_codegen_interface.h",
61  "include/grpc++/impl/codegen/status_code_enum.h",
62  "include/grpc++/impl/codegen/metadata_map.h",
63  "include/grpc++/impl/codegen/rpc_method.h",
64  "include/grpc++/impl/codegen/server_context.h",
65  "include/grpc++/impl/codegen/byte_buffer.h",
66  "include/grpc++/impl/codegen/async_unary_call.h",
67  "include/grpc++/impl/codegen/server_interface.h",
68  "include/grpc++/impl/codegen/call.h",
69  "include/grpc++/impl/codegen/client_context.h",
70  "include/grpc++/impl/codegen/service_type.h",
71  "include/grpc++/impl/codegen/grpc_library.h",
72  "include/grpc++/impl/codegen/async_stream.h",
73  "include/grpc++/impl/codegen/slice.h",
74  "include/grpc++/impl/codegen/client_unary_call.h",
75  "include/grpc++/impl/codegen/proto_utils.h",
76  "include/grpc++/impl/codegen/stub_options.h",
77  "include/grpc++/impl/codegen/rpc_service_method.h",
78  "include/grpc++/impl/codegen/method_handler_impl.h",
79  "include/grpc++/impl/codegen/string_ref.h",
80  "include/grpc++/impl/codegen/completion_queue_tag.h",
81  "include/grpc++/impl/codegen/call_hook.h",
82  "include/grpc++/impl/codegen/completion_queue.h",
83  "include/grpc++/impl/codegen/serialization_traits.h",
84  "include/grpc++/impl/codegen/create_auth_context.h",
85  "include/grpc++/impl/codegen/time.h",
86  "include/grpc++/impl/codegen/security/auth_context.h",
87  "include/grpc++/ext/health_check_service_server_builder_option.h",
88  "include/grpc++/ext/proto_server_reflection_plugin.h",
89  "include/grpc++/generic/async_generic_service.h",
90  "include/grpc++/generic/generic_stub.h",
91  "include/grpc++/test/mock_stream.h",
92  "include/grpc++/test/server_context_test_spouse.h"
93 ]
94 
95 file_template = '''/*
96  *
97  * Copyright 2018 gRPC authors.
98  *
99  * Licensed under the Apache License, Version 2.0 (the "License");
100  * you may not use this file except in compliance with the License.
101  * You may obtain a copy of the License at
102  *
103  * http://www.apache.org/licenses/LICENSE-2.0
104  *
105  * Unless required by applicable law or agreed to in writing, software
106  * distributed under the License is distributed on an "AS IS" BASIS,
107  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
108  * See the License for the specific language governing permissions and
109  * limitations under the License.
110  *
111  */
112 
113 // DEPRECATED: The headers in include/grpc++ are deprecated. Please include the
114 // headers in include/grpcpp instead. This header exists only for backwards
115 // compatibility.
116 
117 #ifndef GRPCXX_FILE_PATH_NAME_UPPER
118 #define GRPCXX_FILE_PATH_NAME_UPPER
119 
120 #include <grpcpp/FILE_PATH_NAME_LOWER>
121 
122 #endif // GRPCXX_FILE_PATH_NAME_UPPER
123 '''
124 
125 errors = 0
126 
127 path_files = []
128 for root, dirs, files in os.walk('include/grpc++'):
129  for filename in files:
130  path_file = os.path.join(root, filename)
131  path_files.append(path_file)
132 
133 if path_files.sort() != expected_files.sort():
134  diff_plus = [file for file in path_files if file not in expected_files]
135  diff_minus = [file for file in expected_files if file not in path_files]
136  for file in diff_minus:
137  print(('- ', file))
138  for file in diff_plus:
139  print(('+ ', file))
140  errors += 1
141 
142 if errors > 0:
143  sys.exit(errors)
144 
145 for path_file in expected_files:
146  relative_path_file = path_file.split('/', 2)[2]
147 
148  replace_lower = relative_path_file.replace('+', 'p')
149 
150  replace_upper = relative_path_file.replace('/', '_')
151  replace_upper = replace_upper.replace('.', '_')
152  replace_upper = replace_upper.upper().replace('+', 'X')
153 
154  expected_content = file_template.replace('FILE_PATH_NAME_LOWER',
155  replace_lower)
156  expected_content = expected_content.replace('FILE_PATH_NAME_UPPER',
157  replace_upper)
158 
159  path_file_expected = path_file + '.expected'
160  with open(path_file_expected, "w") as fo:
161  fo.write(expected_content)
162 
163  if 0 != os.system('diff %s %s' % (path_file_expected, path_file)):
164  print(('Difference found in file:', path_file))
165  errors += 1
166 
167  os.remove(path_file_expected)
168 
169 check_extensions = [".h", ".cc", ".c", ".m"]
170 
171 for root, dirs, files in os.walk('src'):
172  for filename in files:
173  path_file = os.path.join(root, filename)
174  for ext in check_extensions:
175  if path_file.endswith(ext):
176  try:
177  with open(path_file, "r") as fi:
178  content = fi.read()
179  if '#include <grpc++/' in content:
180  print((
181  'Failed: invalid include of deprecated headers in include/grpc++ in %s'
182  % path_file))
183  errors += 1
184  except IOError:
185  pass
186 
187 sys.exit(errors)
open
#define open
Definition: test-fs.c:46


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:53