示例#1
0
文件: migrate.py 项目: ejona86/envoy
 def visit_message(self, msg_proto, type_context, nested_msgs, nested_enums):
     upgraded_proto = copy.deepcopy(msg_proto)
     if upgraded_proto.options.deprecated and not self._envoy_internal_shadow:
         options.add_hide_option(upgraded_proto.options)
     options.set_versioning_annotation(upgraded_proto.options, type_context.name)
     # Mark deprecated fields as ready for deletion by protoxform.
     for f in upgraded_proto.field:
         if f.options.deprecated:
             self._deprecate(upgraded_proto, f)
             if self._envoy_internal_shadow:
                 # When shadowing, we use the upgraded version of types (which should
                 # themselves also be shadowed), to allow us to avoid unnecessary
                 # references to the previous version (and complexities around
                 # upgrading during API boosting).
                 f.type_name = self._upgraded_type(f.type_name)
             else:
                 # Make sure the type name is erased so it isn't picked up by protoxform
                 # when computing deps.
                 f.type_name = ""
         else:
             f.type_name = self._upgraded_type(f.type_name)
         if f.options.HasExtension(migrate_pb2.field_migrate):
             field_migrate = f.options.Extensions[migrate_pb2.field_migrate]
             self._rename(f, field_migrate)
             self._oneof_promotion(upgraded_proto, f, field_migrate)
     # Upgrade nested messages.
     del upgraded_proto.nested_type[:]
     upgraded_proto.nested_type.extend(nested_msgs)
     # Upgrade enums.
     del upgraded_proto.enum_type[:]
     upgraded_proto.enum_type.extend(nested_enums)
     return upgraded_proto
示例#2
0
文件: migrate.py 项目: ejona86/envoy
    def _deprecate(self, proto, field_or_value):
        """Deprecate a field or value in a message/enum proto.

        Args:
            proto: DescriptorProto or EnumDescriptorProto message.
            field_or_value: field or value inside proto.
        """
        if self._envoy_internal_shadow:
            field_or_value.name = 'hidden_envoy_deprecated_' + field_or_value.name
        else:
            reserved = proto.reserved_range.add()
            reserved.start = field_or_value.number
            reserved.end = field_or_value.number + 1
            proto.reserved_name.append(field_or_value.name)
            options.add_hide_option(field_or_value.options)
示例#3
0
文件: migrate.py 项目: ejona86/envoy
 def visit_enum(self, enum_proto, type_context):
     upgraded_proto = copy.deepcopy(enum_proto)
     if upgraded_proto.options.deprecated and not self._envoy_internal_shadow:
         options.add_hide_option(upgraded_proto.options)
     for v in upgraded_proto.value:
         if v.options.deprecated:
             # We need special handling for the zero field, as proto3 needs some value
             # here.
             if v.number == 0 and not self._envoy_internal_shadow:
                 v.name = 'DEPRECATED_AND_UNAVAILABLE_DO_NOT_USE'
             else:
                 # Mark deprecated enum values as ready for deletion by protoxform.
                 self._deprecate(upgraded_proto, v)
         elif v.options.HasExtension(migrate_pb2.enum_value_migrate):
             self._rename(v, v.options.Extensions[migrate_pb2.enum_value_migrate])
     return upgraded_proto