check_deprecated_grpc++.py 7.5 KB

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