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