Esempio n. 1
0
def main(data=None):
    utils.load_protos()

    plugin.plugin([
        plugin.direct_output_descriptor(
            '.proto', ProtoFormatVisitor, want_params=True)
    ],
                  traverser=ProtoprintTraverser().traverse_file)
Esempio n. 2
0
def main():
    utils.load_protos()

    plugin.plugin([
        plugin.direct_output_descriptor('.active_or_frozen.proto',
                                        functools.partial(
                                            ProtoFormatVisitor, True),
                                        want_params=True),
    ])
Esempio n. 3
0
def main():
    utils.load_protos(PROTO_PACKAGES)

    plugin.plugin([
        plugin.direct_output_descriptor('.active_or_frozen.proto',
                                        functools.partial(
                                            ProtoFormatVisitor, True),
                                        want_params=True),
        plugin.OutputDescriptor('.next_major_version_candidate.proto',
                                functools.partial(ProtoFormatVisitor, False),
                                functools.partial(
                                    migrate.version_upgrade_xform, 2, False),
                                want_params=True),
        plugin.OutputDescriptor(
            '.next_major_version_candidate.envoy_internal.proto',
            functools.partial(ProtoFormatVisitor, False),
            functools.partial(migrate.version_upgrade_xform, 2, True),
            want_params=True)
    ])
Esempio n. 4
0
            formatted_msgs, reserved_fields, fields)

    def visit_file(self, file_proto, type_context, services, msgs, enums):
        empty_file = len(services) == 0 and len(enums) == 0 and len(msgs) == 0
        header = format_header_from_file(
            type_context.source_code_info, file_proto, empty_file,
            self._requires_deprecation_annotation_import)
        formatted_services = format_block('\n'.join(services))
        formatted_enums = format_block('\n'.join(enums))
        formatted_msgs = format_block('\n'.join(msgs))
        return clang_format(header + formatted_services + formatted_enums + formatted_msgs)


if __name__ == '__main__':
    proto_desc_path = sys.argv[1]

    utils.load_protos(PROTO_PACKAGES)

    file_proto = descriptor_pb2.FileDescriptorProto()
    input_text = pathlib.Path(proto_desc_path).read_text()
    if not input_text:
        sys.exit(0)
    text_format.Merge(input_text, file_proto)
    dst_path = pathlib.Path(sys.argv[2])
    utils.load_type_db(sys.argv[3])
    api_version_file_path = pathlib.Path(sys.argv[4])
    frozen_proto = file_proto.options.Extensions[
        status_pb2.file_status].package_version_status == status_pb2.FROZEN
    dst_path.write_bytes(
        traverse.traverse_file(file_proto, ProtoFormatVisitor(api_version_file_path, frozen_proto)))
Esempio n. 5
0
    def visit_file(self, file_proto, type_context, services, msgs, enums):
        empty_file = len(services) == 0 and len(enums) == 0 and len(msgs) == 0
        header = format_header_from_file(
            type_context.source_code_info, file_proto, empty_file,
            self._requires_deprecation_annotation_import)
        formatted_services = format_block('\n'.join(services))
        formatted_enums = format_block('\n'.join(enums))
        formatted_msgs = format_block('\n'.join(msgs))
        return clang_format(header + formatted_services + formatted_enums +
                            formatted_msgs)


if __name__ == '__main__':
    proto_desc_path = sys.argv[1]

    utils.load_protos()

    file_proto = descriptor_pb2.FileDescriptorProto()
    input_text = pathlib.Path(proto_desc_path).read_text()
    if not input_text:
        sys.exit(0)
    text_format.Merge(input_text, file_proto)
    dst_path = pathlib.Path(sys.argv[2])
    utils.load_type_db(sys.argv[3])
    api_version_file_path = pathlib.Path(sys.argv[4])
    frozen_proto = file_proto.options.Extensions[
        status_pb2.file_status].package_version_status == status_pb2.FROZEN
    dst_path.write_bytes(
        traverse.traverse_file(
            file_proto, ProtoFormatVisitor(api_version_file_path,
                                           frozen_proto)))
        target_proto = merge_active_shadow.merge_active_shadow_file(
            active_proto, shadow_proto)
        self.assertEqual(target_proto.message_type[0].name, 'foo')

    def testmerge_active_shadow_file_no_shadow_message(self):
        """merge_active_shadow_file doesn't require a shadow message for new active messages."""
        active_proto = descriptor_pb2.FileDescriptorProto()
        shadow_proto = descriptor_pb2.FileDescriptorProto()
        active_proto.message_type.add().name = 'foo'
        target_proto = descriptor_pb2.DescriptorProto()
        target_proto = merge_active_shadow.merge_active_shadow_file(
            active_proto, shadow_proto)
        self.assertEqual(target_proto.message_type[0].name, 'foo')

    def testmerge_active_shadow_file_no_shadow_enum(self):
        """merge_active_shadow_file doesn't require a shadow enum for new active enums."""
        active_proto = descriptor_pb2.FileDescriptorProto()
        shadow_proto = descriptor_pb2.FileDescriptorProto()
        active_proto.enum_type.add().name = 'foo'
        target_proto = descriptor_pb2.DescriptorProto()
        target_proto = merge_active_shadow.merge_active_shadow_file(
            active_proto, shadow_proto)
        self.assertEqual(target_proto.enum_type[0].name, 'foo')


# TODO(htuch): add some test for recursion.

if __name__ == '__main__':
    utils.load_protos(merge_active_shadow.PROTO_PACKAGES)
    unittest.main()