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