| 33 | ) |
| 34 | |
| 35 | func main() { |
| 36 | run := flag.Bool("execute", false, "Write generated files to destination.") |
| 37 | flag.Parse() |
| 38 | |
| 39 | // Set of generated proto packages to forward to v2. |
| 40 | files := []struct { |
| 41 | oldGoPkg string |
| 42 | newGoPkg string |
| 43 | pbDesc protoreflect.FileDescriptor |
| 44 | }{{ |
| 45 | oldGoPkg: "github.com/golang/protobuf/protoc-gen-go/descriptor;descriptor", |
| 46 | newGoPkg: "google.golang.org/protobuf/types/descriptorpb", |
| 47 | pbDesc: descriptorpb.File_google_protobuf_descriptor_proto, |
| 48 | }, { |
| 49 | oldGoPkg: "github.com/golang/protobuf/protoc-gen-go/plugin;plugin_go", |
| 50 | newGoPkg: "google.golang.org/protobuf/types/pluginpb", |
| 51 | pbDesc: pluginpb.File_google_protobuf_compiler_plugin_proto, |
| 52 | }, { |
| 53 | oldGoPkg: "github.com/golang/protobuf/ptypes/any;any", |
| 54 | newGoPkg: "google.golang.org/protobuf/types/known/anypb", |
| 55 | pbDesc: anypb.File_google_protobuf_any_proto, |
| 56 | }, { |
| 57 | oldGoPkg: "github.com/golang/protobuf/ptypes/duration;duration", |
| 58 | newGoPkg: "google.golang.org/protobuf/types/known/durationpb", |
| 59 | pbDesc: durationpb.File_google_protobuf_duration_proto, |
| 60 | }, { |
| 61 | oldGoPkg: "github.com/golang/protobuf/ptypes/timestamp;timestamp", |
| 62 | newGoPkg: "google.golang.org/protobuf/types/known/timestamppb", |
| 63 | pbDesc: timestamppb.File_google_protobuf_timestamp_proto, |
| 64 | }, { |
| 65 | oldGoPkg: "github.com/golang/protobuf/ptypes/wrappers;wrappers", |
| 66 | newGoPkg: "google.golang.org/protobuf/types/known/wrapperspb", |
| 67 | pbDesc: wrapperspb.File_google_protobuf_wrappers_proto, |
| 68 | }, { |
| 69 | oldGoPkg: "github.com/golang/protobuf/ptypes/struct;structpb", |
| 70 | newGoPkg: "google.golang.org/protobuf/types/known/structpb", |
| 71 | pbDesc: structpb.File_google_protobuf_struct_proto, |
| 72 | }, { |
| 73 | oldGoPkg: "github.com/golang/protobuf/ptypes/empty;empty", |
| 74 | newGoPkg: "google.golang.org/protobuf/types/known/emptypb", |
| 75 | pbDesc: emptypb.File_google_protobuf_empty_proto, |
| 76 | }} |
| 77 | |
| 78 | // For each package, construct a proto file that public imports the package. |
| 79 | var req pluginpb.CodeGeneratorRequest |
| 80 | var flags []string |
| 81 | for _, file := range files { |
| 82 | pkgPath := file.oldGoPkg[:strings.IndexByte(file.oldGoPkg, ';')] |
| 83 | fd := &descriptorpb.FileDescriptorProto{ |
| 84 | Name: proto.String(pkgPath + "/" + path.Base(pkgPath) + ".proto"), |
| 85 | Syntax: proto.String(file.pbDesc.Syntax().String()), |
| 86 | Dependency: []string{file.pbDesc.Path()}, |
| 87 | PublicDependency: []int32{0}, |
| 88 | Options: &descriptorpb.FileOptions{GoPackage: proto.String(file.oldGoPkg)}, |
| 89 | } |
| 90 | req.ProtoFile = append(req.ProtoFile, protodesc.ToFileDescriptorProto(file.pbDesc), fd) |
| 91 | req.FileToGenerate = append(req.FileToGenerate, fd.GetName()) |
| 92 | flags = append(flags, "M"+file.pbDesc.Path()+"="+file.newGoPkg) |