diff --git a/protoc-gen-go/generator/generator.go b/protoc-gen-go/generator/generator.go index be382f97bc..e0aba85f31 100644 --- a/protoc-gen-go/generator/generator.go +++ b/protoc-gen-go/generator/generator.go @@ -43,6 +43,7 @@ import ( "crypto/sha256" "encoding/hex" "fmt" + "go/build" "go/parser" "go/printer" "go/token" @@ -345,8 +346,7 @@ type symbol interface { type messageSymbol struct { sym string hasExtensions, isMessageSet bool - hasOneof bool - getters []getterSymbol + oneofTypes []string } type getterSymbol struct { @@ -357,146 +357,10 @@ type getterSymbol struct { } func (ms *messageSymbol) GenerateAlias(g *Generator, pkg GoPackageName) { - remoteSym := string(pkg) + "." + ms.sym - - g.P("type ", ms.sym, " ", remoteSym) - g.P("func (m *", ms.sym, ") Reset() { (*", remoteSym, ")(m).Reset() }") - g.P("func (m *", ms.sym, ") String() string { return (*", remoteSym, ")(m).String() }") - g.P("func (*", ms.sym, ") ProtoMessage() {}") - g.P("func (m *", ms.sym, ") XXX_Unmarshal(buf []byte) error ", - "{ return (*", remoteSym, ")(m).XXX_Unmarshal(buf) }") - g.P("func (m *", ms.sym, ") XXX_Marshal(b []byte, deterministic bool) ([]byte, error) ", - "{ return (*", remoteSym, ")(m).XXX_Marshal(b, deterministic) }") - g.P("func (m *", ms.sym, ") XXX_Size() int ", - "{ return (*", remoteSym, ")(m).XXX_Size() }") - g.P("func (m *", ms.sym, ") XXX_DiscardUnknown() ", - "{ (*", remoteSym, ")(m).XXX_DiscardUnknown() }") - if ms.hasExtensions { - g.P("func (*", ms.sym, ") ExtensionRangeArray() []", g.Pkg["proto"], ".ExtensionRange ", - "{ return (*", remoteSym, ")(nil).ExtensionRangeArray() }") - } - if ms.hasOneof { - // Oneofs and public imports do not mix well. - // We can make them work okay for the binary format, - // but they're going to break weirdly for text/JSON. - enc := "_" + ms.sym + "_OneofMarshaler" - dec := "_" + ms.sym + "_OneofUnmarshaler" - size := "_" + ms.sym + "_OneofSizer" - encSig := "(msg " + g.Pkg["proto"] + ".Message, b *" + g.Pkg["proto"] + ".Buffer) error" - decSig := "(msg " + g.Pkg["proto"] + ".Message, tag, wire int, b *" + g.Pkg["proto"] + ".Buffer) (bool, error)" - sizeSig := "(msg " + g.Pkg["proto"] + ".Message) int" - g.P("func (m *", ms.sym, ") XXX_OneofFuncs() (func", encSig, ", func", decSig, ", func", sizeSig, ", []interface{}) {") - g.P("_, _, _, x := (*", remoteSym, ")(nil).XXX_OneofFuncs()") - g.P("return ", enc, ", ", dec, ", ", size, ", x") - g.P("}") - - g.P("func ", enc, encSig, " {") - g.P("m := msg.(*", ms.sym, ")") - g.P("m0 := (*", remoteSym, ")(m)") - g.P("enc, _, _, _ := m0.XXX_OneofFuncs()") - g.P("return enc(m0, b)") - g.P("}") - - g.P("func ", dec, decSig, " {") - g.P("m := msg.(*", ms.sym, ")") - g.P("m0 := (*", remoteSym, ")(m)") - g.P("_, dec, _, _ := m0.XXX_OneofFuncs()") - g.P("return dec(m0, tag, wire, b)") - g.P("}") - - g.P("func ", size, sizeSig, " {") - g.P("m := msg.(*", ms.sym, ")") - g.P("m0 := (*", remoteSym, ")(m)") - g.P("_, _, size, _ := m0.XXX_OneofFuncs()") - g.P("return size(m0)") - g.P("}") - } - for _, get := range ms.getters { - - if get.typeName != "" { - g.RecordTypeUse(get.typeName) - } - typ := get.typ - val := "(*" + remoteSym + ")(m)." + get.name + "()" - if get.genType { - // typ will be "*pkg.T" (message/group) or "pkg.T" (enum) - // or "map[t]*pkg.T" (map to message/enum). - // The first two of those might have a "[]" prefix if it is repeated. - // Drop any package qualifier since we have hoisted the type into this package. - rep := strings.HasPrefix(typ, "[]") - if rep { - typ = typ[2:] - } - isMap := strings.HasPrefix(typ, "map[") - star := typ[0] == '*' - if !isMap { // map types handled lower down - typ = typ[strings.Index(typ, ".")+1:] - } - if star { - typ = "*" + typ - } - if rep { - // Go does not permit conversion between slice types where both - // element types are named. That means we need to generate a bit - // of code in this situation. - // typ is the element type. - // val is the expression to get the slice from the imported type. - - ctyp := typ // conversion type expression; "Foo" or "(*Foo)" - if star { - ctyp = "(" + typ + ")" - } - - g.P("func (m *", ms.sym, ") ", get.name, "() []", typ, " {") - g.In() - g.P("o := ", val) - g.P("if o == nil {") - g.In() - g.P("return nil") - g.Out() - g.P("}") - g.P("s := make([]", typ, ", len(o))") - g.P("for i, x := range o {") - g.In() - g.P("s[i] = ", ctyp, "(x)") - g.Out() - g.P("}") - g.P("return s") - g.Out() - g.P("}") - continue - } - if isMap { - // Split map[keyTyp]valTyp. - bra, ket := strings.Index(typ, "["), strings.Index(typ, "]") - keyTyp, valTyp := typ[bra+1:ket], typ[ket+1:] - // Drop any package qualifier. - // Only the value type may be foreign. - star := valTyp[0] == '*' - valTyp = valTyp[strings.Index(valTyp, ".")+1:] - if star { - valTyp = "*" + valTyp - } - - typ := "map[" + keyTyp + "]" + valTyp - g.P("func (m *", ms.sym, ") ", get.name, "() ", typ, " {") - g.P("o := ", val) - g.P("if o == nil { return nil }") - g.P("s := make(", typ, ", len(o))") - g.P("for k, v := range o {") - g.P("s[k] = (", valTyp, ")(v)") - g.P("}") - g.P("return s") - g.P("}") - continue - } - // Convert imported type into the forwarding type. - val = "(" + typ + ")(" + val + ")" - } - - g.P("func (m *", ms.sym, ") ", get.name, "() ", typ, " { return ", val, " }") + g.P("type ", ms.sym, " = ", pkg, ".", ms.sym) + for _, name := range ms.oneofTypes { + g.P("type ", name, " = ", pkg, ".", name) } - } type enumSymbol struct { @@ -506,14 +370,9 @@ type enumSymbol struct { func (es enumSymbol) GenerateAlias(g *Generator, pkg GoPackageName) { s := es.name - g.P("type ", s, " ", pkg, ".", s) + g.P("type ", s, " = ", pkg, ".", s) g.P("var ", s, "_name = ", pkg, ".", s, "_name") g.P("var ", s, "_value = ", pkg, ".", s, "_value") - g.P("func (x ", s, ") String() string { return (", pkg, ".", s, ")(x).String() }") - if !es.proto3 { - g.P("func (x ", s, ") Enum() *", s, "{ return (*", s, ")((", pkg, ".", s, ")(x).Enum()) }") - g.P("func (x *", s, ") UnmarshalJSON(data []byte) error { return (*", pkg, ".", s, ")(x).UnmarshalJSON(data) }") - } } type constOrVarSymbol struct { @@ -1486,20 +1345,18 @@ func (g *Generator) generateImports() { } func (g *Generator) generateImported(id *ImportedDescriptor) { - // Don't generate public import symbols for files that we are generating - // code for, since those symbols will already be in this package. - // We can't simply avoid creating the ImportedDescriptor objects, - // because g.genFiles isn't populated at that stage. tn := id.TypeName() sn := tn[len(tn)-1] df := id.o.File() filename := *df.Name - for _, fd := range g.genFiles { - if *fd.Name == filename { - g.P("// Ignoring public import of ", sn, " from ", filename) - g.P() - return - } + if df.importPath == g.file.importPath { + // Don't generate type aliases for files in the same Go package as this one. + g.P("// Ignoring public import of ", sn, " from ", filename) + g.P() + return + } + if !supportTypeAliases { + g.Fail(fmt.Sprintf("%s: public imports require at least go1.9", filename)) } g.P("// ", sn, " from public import ", filename) g.usedPackages[df.importPath] = true @@ -2232,6 +2089,7 @@ func (g *Generator) generateMessage(message *Descriptor) { g.P("}") } g.P() + var oneofTypes []string for i, field := range message.Field { if field.OneofIndex == nil { continue @@ -2241,6 +2099,7 @@ func (g *Generator) generateMessage(message *Descriptor) { fieldFullPath := fmt.Sprintf("%s,%d,%d", message.path, messageFieldPath, i) g.P("type ", Annotate(message.file, fieldFullPath, oneofTypeName[field]), " struct{ ", Annotate(message.file, fieldFullPath, fieldNames[field]), " ", fieldTypes[field], " `", tag, "` }") g.RecordTypeUse(field.GetTypeName()) + oneofTypes = append(oneofTypes, oneofTypeName[field]) } g.P() for _, field := range message.Field { @@ -2261,7 +2120,6 @@ func (g *Generator) generateMessage(message *Descriptor) { g.P() // Field getters - var getters []getterSymbol for i, field := range message.Field { oneof := field.OneofIndex != nil @@ -2278,42 +2136,6 @@ func (g *Generator) generateMessage(message *Descriptor) { } fieldFullPath := fmt.Sprintf("%s,%d,%d", message.path, messageFieldPath, i) - // Only export getter symbols for basic types, - // and for messages and enums in the same package. - // Groups are not exported. - // Foreign types can't be hoisted through a public import because - // the importer may not already be importing the defining .proto. - // As an example, imagine we have an import tree like this: - // A.proto -> B.proto -> C.proto - // If A publicly imports B, we need to generate the getters from B in A's output, - // but if one such getter returns something from C then we cannot do that - // because A is not importing C already. - var getter, genType bool - switch *field.Type { - case descriptor.FieldDescriptorProto_TYPE_GROUP: - getter = false - case descriptor.FieldDescriptorProto_TYPE_MESSAGE, descriptor.FieldDescriptorProto_TYPE_ENUM: - // Only export getter if its return type is in the same file. - // - // This should be the same package, not the same file. - // However, code elsewhere assumes that there's a 1-1 relationship - // between packages and files, so that's not safe. - // - // TODO: Tear out all of this complexity and just use type aliases. - getter = g.ObjectNamed(field.GetTypeName()).File() == message.File() - genType = true - default: - getter = true - } - if getter { - getters = append(getters, getterSymbol{ - name: mname, - typ: typename, - typeName: field.GetTypeName(), - genType: genType, - }) - } - if field.GetOptions().GetDeprecated() { g.P(deprecationComment) } @@ -2416,8 +2238,7 @@ func (g *Generator) generateMessage(message *Descriptor) { sym: ccTypeName, hasExtensions: hasExtensions, isMessageSet: isMessageSet, - hasOneof: len(message.OneofDecl) > 0, - getters: getters, + oneofTypes: oneofTypes, } g.file.addExport(message, ms) } @@ -3094,3 +2915,14 @@ const ( // tag numbers in EnumDescriptorProto enumValuePath = 2 // value ) + +var supportTypeAliases bool + +func init() { + for _, tag := range build.Default.ReleaseTags { + if tag == "go1.9" { + supportTypeAliases = true + return + } + } +} diff --git a/protoc-gen-go/golden_test.go b/protoc-gen-go/golden_test.go index 70f3971246..30d2799908 100644 --- a/protoc-gen-go/golden_test.go +++ b/protoc-gen-go/golden_test.go @@ -4,6 +4,7 @@ import ( "bytes" "flag" "fmt" + "go/build" "go/parser" "go/token" "io/ioutil" @@ -38,8 +39,13 @@ func TestGolden(t *testing.T) { // Find all the proto files we need to compile. We assume that each directory // contains the files for a single package. + supportTypeAliases := hasReleaseTag("1.9") packages := map[string][]string{} err = filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error { + if filepath.Base(path) == "import_public" && !supportTypeAliases { + // Public imports require type alias support. + return filepath.SkipDir + } if !strings.HasSuffix(path, ".proto") { return nil } @@ -405,3 +411,12 @@ func protoc(t *testing.T, args []string) { t.Fatalf("protoc: %v", err) } } + +func hasReleaseTag(want string) bool { + for _, tag := range build.Default.ReleaseTags { + if tag == want { + return true + } + } + return false +} diff --git a/protoc-gen-go/testdata/imp/imp.pb.go b/protoc-gen-go/testdata/imp/imp.pb.go deleted file mode 100644 index e4b0a5b001..0000000000 --- a/protoc-gen-go/testdata/imp/imp.pb.go +++ /dev/null @@ -1,416 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: imp/imp.proto - -package imp // import "github.com/golang/protobuf/protoc-gen-go/testdata/imp" - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import imp2 "github.com/golang/protobuf/protoc-gen-go/testdata/imp/imp2" -import imp3 "github.com/golang/protobuf/protoc-gen-go/testdata/imp/imp3" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -// PubliclyImportedMessage from public import imp/imp2/imp2.proto -type PubliclyImportedMessage imp2.PubliclyImportedMessage - -func (m *PubliclyImportedMessage) Reset() { (*imp2.PubliclyImportedMessage)(m).Reset() } -func (m *PubliclyImportedMessage) String() string { return (*imp2.PubliclyImportedMessage)(m).String() } -func (*PubliclyImportedMessage) ProtoMessage() {} -func (m *PubliclyImportedMessage) XXX_Unmarshal(buf []byte) error { - return (*imp2.PubliclyImportedMessage)(m).XXX_Unmarshal(buf) -} -func (m *PubliclyImportedMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return (*imp2.PubliclyImportedMessage)(m).XXX_Marshal(b, deterministic) -} -func (m *PubliclyImportedMessage) XXX_Size() int { return (*imp2.PubliclyImportedMessage)(m).XXX_Size() } -func (m *PubliclyImportedMessage) XXX_DiscardUnknown() { - (*imp2.PubliclyImportedMessage)(m).XXX_DiscardUnknown() -} -func (m *PubliclyImportedMessage) GetField() int64 { - return (*imp2.PubliclyImportedMessage)(m).GetField() -} - -// PubliclyImportedMessage2 from public import imp/imp2/imp2.proto -type PubliclyImportedMessage2 imp2.PubliclyImportedMessage2 - -func (m *PubliclyImportedMessage2) Reset() { (*imp2.PubliclyImportedMessage2)(m).Reset() } -func (m *PubliclyImportedMessage2) String() string { - return (*imp2.PubliclyImportedMessage2)(m).String() -} -func (*PubliclyImportedMessage2) ProtoMessage() {} -func (m *PubliclyImportedMessage2) XXX_Unmarshal(buf []byte) error { - return (*imp2.PubliclyImportedMessage2)(m).XXX_Unmarshal(buf) -} -func (m *PubliclyImportedMessage2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return (*imp2.PubliclyImportedMessage2)(m).XXX_Marshal(b, deterministic) -} -func (m *PubliclyImportedMessage2) XXX_Size() int { - return (*imp2.PubliclyImportedMessage2)(m).XXX_Size() -} -func (m *PubliclyImportedMessage2) XXX_DiscardUnknown() { - (*imp2.PubliclyImportedMessage2)(m).XXX_DiscardUnknown() -} -func (m *PubliclyImportedMessage2) GetField() *PubliclyImportedMessage { - return (*PubliclyImportedMessage)((*imp2.PubliclyImportedMessage2)(m).GetField()) -} - -// PubliclyImportedEnum from public import imp/imp2/imp2.proto -type PubliclyImportedEnum imp2.PubliclyImportedEnum - -var PubliclyImportedEnum_name = imp2.PubliclyImportedEnum_name -var PubliclyImportedEnum_value = imp2.PubliclyImportedEnum_value - -func (x PubliclyImportedEnum) String() string { return (imp2.PubliclyImportedEnum)(x).String() } -func (x PubliclyImportedEnum) Enum() *PubliclyImportedEnum { - return (*PubliclyImportedEnum)((imp2.PubliclyImportedEnum)(x).Enum()) -} -func (x *PubliclyImportedEnum) UnmarshalJSON(data []byte) error { - return (*imp2.PubliclyImportedEnum)(x).UnmarshalJSON(data) -} - -const PubliclyImportedEnum_GLASSES = PubliclyImportedEnum(imp2.PubliclyImportedEnum_GLASSES) -const PubliclyImportedEnum_HAIR = PubliclyImportedEnum(imp2.PubliclyImportedEnum_HAIR) - -type ImportedMessage_Owner int32 - -const ( - ImportedMessage_DAVE ImportedMessage_Owner = 1 - ImportedMessage_MIKE ImportedMessage_Owner = 2 -) - -var ImportedMessage_Owner_name = map[int32]string{ - 1: "DAVE", - 2: "MIKE", -} -var ImportedMessage_Owner_value = map[string]int32{ - "DAVE": 1, - "MIKE": 2, -} - -func (x ImportedMessage_Owner) Enum() *ImportedMessage_Owner { - p := new(ImportedMessage_Owner) - *p = x - return p -} -func (x ImportedMessage_Owner) String() string { - return proto.EnumName(ImportedMessage_Owner_name, int32(x)) -} -func (x *ImportedMessage_Owner) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(ImportedMessage_Owner_value, data, "ImportedMessage_Owner") - if err != nil { - return err - } - *x = ImportedMessage_Owner(value) - return nil -} -func (ImportedMessage_Owner) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_imp_6424de66809c2ae5, []int{0, 0} -} - -type ImportedMessage struct { - Field *int64 `protobuf:"varint,1,req,name=field" json:"field,omitempty"` - // The forwarded getters for these fields are fiddly to get right. - LocalMsg *ImportedMessage2 `protobuf:"bytes,2,opt,name=local_msg,json=localMsg" json:"local_msg,omitempty"` - ForeignMsg *imp3.ForeignImportedMessage `protobuf:"bytes,3,opt,name=foreign_msg,json=foreignMsg" json:"foreign_msg,omitempty"` - EnumField *ImportedMessage_Owner `protobuf:"varint,4,opt,name=enum_field,json=enumField,enum=imp.ImportedMessage_Owner" json:"enum_field,omitempty"` - // Types that are valid to be assigned to Union: - // *ImportedMessage_State - Union isImportedMessage_Union `protobuf_oneof:"union"` - Name []string `protobuf:"bytes,5,rep,name=name" json:"name,omitempty"` - Boss []ImportedMessage_Owner `protobuf:"varint,6,rep,name=boss,enum=imp.ImportedMessage_Owner" json:"boss,omitempty"` - Memo []*ImportedMessage2 `protobuf:"bytes,7,rep,name=memo" json:"memo,omitempty"` - MsgMap map[string]*ImportedMessage2 `protobuf:"bytes,8,rep,name=msg_map,json=msgMap" json:"msg_map,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - proto.XXX_InternalExtensions `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ImportedMessage) Reset() { *m = ImportedMessage{} } -func (m *ImportedMessage) String() string { return proto.CompactTextString(m) } -func (*ImportedMessage) ProtoMessage() {} -func (*ImportedMessage) Descriptor() ([]byte, []int) { - return fileDescriptor_imp_6424de66809c2ae5, []int{0} -} - -var extRange_ImportedMessage = []proto.ExtensionRange{ - {Start: 90, End: 100}, -} - -func (*ImportedMessage) ExtensionRangeArray() []proto.ExtensionRange { - return extRange_ImportedMessage -} -func (m *ImportedMessage) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ImportedMessage.Unmarshal(m, b) -} -func (m *ImportedMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ImportedMessage.Marshal(b, m, deterministic) -} -func (dst *ImportedMessage) XXX_Merge(src proto.Message) { - xxx_messageInfo_ImportedMessage.Merge(dst, src) -} -func (m *ImportedMessage) XXX_Size() int { - return xxx_messageInfo_ImportedMessage.Size(m) -} -func (m *ImportedMessage) XXX_DiscardUnknown() { - xxx_messageInfo_ImportedMessage.DiscardUnknown(m) -} - -var xxx_messageInfo_ImportedMessage proto.InternalMessageInfo - -type isImportedMessage_Union interface { - isImportedMessage_Union() -} - -type ImportedMessage_State struct { - State int32 `protobuf:"varint,9,opt,name=state,oneof"` -} - -func (*ImportedMessage_State) isImportedMessage_Union() {} - -func (m *ImportedMessage) GetUnion() isImportedMessage_Union { - if m != nil { - return m.Union - } - return nil -} - -func (m *ImportedMessage) GetField() int64 { - if m != nil && m.Field != nil { - return *m.Field - } - return 0 -} - -func (m *ImportedMessage) GetLocalMsg() *ImportedMessage2 { - if m != nil { - return m.LocalMsg - } - return nil -} - -func (m *ImportedMessage) GetForeignMsg() *imp3.ForeignImportedMessage { - if m != nil { - return m.ForeignMsg - } - return nil -} - -func (m *ImportedMessage) GetEnumField() ImportedMessage_Owner { - if m != nil && m.EnumField != nil { - return *m.EnumField - } - return ImportedMessage_DAVE -} - -func (m *ImportedMessage) GetState() int32 { - if x, ok := m.GetUnion().(*ImportedMessage_State); ok { - return x.State - } - return 0 -} - -func (m *ImportedMessage) GetName() []string { - if m != nil { - return m.Name - } - return nil -} - -func (m *ImportedMessage) GetBoss() []ImportedMessage_Owner { - if m != nil { - return m.Boss - } - return nil -} - -func (m *ImportedMessage) GetMemo() []*ImportedMessage2 { - if m != nil { - return m.Memo - } - return nil -} - -func (m *ImportedMessage) GetMsgMap() map[string]*ImportedMessage2 { - if m != nil { - return m.MsgMap - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*ImportedMessage) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _ImportedMessage_OneofMarshaler, _ImportedMessage_OneofUnmarshaler, _ImportedMessage_OneofSizer, []interface{}{ - (*ImportedMessage_State)(nil), - } -} - -func _ImportedMessage_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*ImportedMessage) - // union - switch x := m.Union.(type) { - case *ImportedMessage_State: - b.EncodeVarint(9<<3 | proto.WireVarint) - b.EncodeVarint(uint64(x.State)) - case nil: - default: - return fmt.Errorf("ImportedMessage.Union has unexpected type %T", x) - } - return nil -} - -func _ImportedMessage_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*ImportedMessage) - switch tag { - case 9: // union.state - if wire != proto.WireVarint { - return true, proto.ErrInternalBadWireType - } - x, err := b.DecodeVarint() - m.Union = &ImportedMessage_State{int32(x)} - return true, err - default: - return false, nil - } -} - -func _ImportedMessage_OneofSizer(msg proto.Message) (n int) { - m := msg.(*ImportedMessage) - // union - switch x := m.Union.(type) { - case *ImportedMessage_State: - n += 1 // tag and wire - n += proto.SizeVarint(uint64(x.State)) - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - -type ImportedMessage2 struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ImportedMessage2) Reset() { *m = ImportedMessage2{} } -func (m *ImportedMessage2) String() string { return proto.CompactTextString(m) } -func (*ImportedMessage2) ProtoMessage() {} -func (*ImportedMessage2) Descriptor() ([]byte, []int) { - return fileDescriptor_imp_6424de66809c2ae5, []int{1} -} -func (m *ImportedMessage2) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ImportedMessage2.Unmarshal(m, b) -} -func (m *ImportedMessage2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ImportedMessage2.Marshal(b, m, deterministic) -} -func (dst *ImportedMessage2) XXX_Merge(src proto.Message) { - xxx_messageInfo_ImportedMessage2.Merge(dst, src) -} -func (m *ImportedMessage2) XXX_Size() int { - return xxx_messageInfo_ImportedMessage2.Size(m) -} -func (m *ImportedMessage2) XXX_DiscardUnknown() { - xxx_messageInfo_ImportedMessage2.DiscardUnknown(m) -} - -var xxx_messageInfo_ImportedMessage2 proto.InternalMessageInfo - -type ImportedExtendable struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - proto.XXX_InternalExtensions `protobuf_messageset:"1" json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ImportedExtendable) Reset() { *m = ImportedExtendable{} } -func (m *ImportedExtendable) String() string { return proto.CompactTextString(m) } -func (*ImportedExtendable) ProtoMessage() {} -func (*ImportedExtendable) Descriptor() ([]byte, []int) { - return fileDescriptor_imp_6424de66809c2ae5, []int{2} -} - -func (m *ImportedExtendable) MarshalJSON() ([]byte, error) { - return proto.MarshalMessageSetJSON(&m.XXX_InternalExtensions) -} -func (m *ImportedExtendable) UnmarshalJSON(buf []byte) error { - return proto.UnmarshalMessageSetJSON(buf, &m.XXX_InternalExtensions) -} - -var extRange_ImportedExtendable = []proto.ExtensionRange{ - {Start: 100, End: 2147483646}, -} - -func (*ImportedExtendable) ExtensionRangeArray() []proto.ExtensionRange { - return extRange_ImportedExtendable -} -func (m *ImportedExtendable) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ImportedExtendable.Unmarshal(m, b) -} -func (m *ImportedExtendable) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ImportedExtendable.Marshal(b, m, deterministic) -} -func (dst *ImportedExtendable) XXX_Merge(src proto.Message) { - xxx_messageInfo_ImportedExtendable.Merge(dst, src) -} -func (m *ImportedExtendable) XXX_Size() int { - return xxx_messageInfo_ImportedExtendable.Size(m) -} -func (m *ImportedExtendable) XXX_DiscardUnknown() { - xxx_messageInfo_ImportedExtendable.DiscardUnknown(m) -} - -var xxx_messageInfo_ImportedExtendable proto.InternalMessageInfo - -func init() { - proto.RegisterType((*ImportedMessage)(nil), "imp.ImportedMessage") - proto.RegisterMapType((map[string]*ImportedMessage2)(nil), "imp.ImportedMessage.MsgMapEntry") - proto.RegisterType((*ImportedMessage2)(nil), "imp.ImportedMessage2") - proto.RegisterType((*ImportedExtendable)(nil), "imp.ImportedExtendable") - proto.RegisterEnum("imp.ImportedMessage_Owner", ImportedMessage_Owner_name, ImportedMessage_Owner_value) -} - -func init() { proto.RegisterFile("imp/imp.proto", fileDescriptor_imp_6424de66809c2ae5) } - -var fileDescriptor_imp_6424de66809c2ae5 = []byte{ - // 427 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0x4d, 0x6f, 0xd4, 0x30, - 0x10, 0xad, 0xf3, 0xd1, 0x4d, 0x66, 0x05, 0x44, 0xe6, 0x43, 0xd1, 0xf6, 0x62, 0xe5, 0x14, 0x8a, - 0x9a, 0x95, 0x82, 0x10, 0xb4, 0xe2, 0x42, 0xc5, 0x56, 0x54, 0x28, 0xa2, 0xca, 0x81, 0x43, 0x2f, - 0x2b, 0xef, 0xc6, 0x6b, 0x22, 0x62, 0x3b, 0x8a, 0x1d, 0xa0, 0xff, 0x83, 0xff, 0x1b, 0x14, 0xa7, - 0x20, 0xb4, 0x2a, 0xf4, 0x32, 0x7a, 0xf3, 0xfc, 0xde, 0xcc, 0xd8, 0x1e, 0x78, 0x50, 0x8b, 0x76, - 0x59, 0x8b, 0x36, 0x6b, 0x3b, 0x65, 0x14, 0x76, 0x6b, 0xd1, 0x2e, 0x1e, 0xdf, 0x72, 0xb9, 0x0d, - 0xd3, 0xc9, 0x1f, 0xf2, 0xa5, 0x0d, 0x13, 0x99, 0xfc, 0xf4, 0xe0, 0xd1, 0xa5, 0x68, 0x55, 0x67, - 0x58, 0x55, 0x30, 0xad, 0x29, 0x67, 0xf8, 0x09, 0xf8, 0xbb, 0x9a, 0x35, 0x55, 0x8c, 0x88, 0x93, - 0xba, 0xe5, 0x94, 0xe0, 0x1c, 0xc2, 0x46, 0x6d, 0x69, 0xb3, 0x16, 0x9a, 0xc7, 0x0e, 0x41, 0xe9, - 0x3c, 0x7f, 0x9a, 0x8d, 0x7d, 0xf7, 0xec, 0x79, 0x19, 0x58, 0x5d, 0xa1, 0x39, 0x7e, 0x0b, 0xf3, - 0x9d, 0xea, 0x58, 0xcd, 0xa5, 0x75, 0xb9, 0xd6, 0x75, 0x64, 0x5d, 0x17, 0x13, 0xbf, 0x67, 0x2e, - 0xe1, 0x56, 0x3f, 0xba, 0x4f, 0x01, 0x98, 0xec, 0xc5, 0x7a, 0x1a, 0xc6, 0x23, 0x28, 0x7d, 0x98, - 0x2f, 0xee, 0x6a, 0x99, 0x7d, 0xfa, 0x2e, 0x59, 0x57, 0x86, 0xa3, 0xfa, 0xc2, 0x0e, 0xfb, 0x0c, - 0x7c, 0x6d, 0xa8, 0x61, 0x71, 0x48, 0x50, 0xea, 0x7f, 0x38, 0x28, 0xa7, 0x14, 0x63, 0xf0, 0x24, - 0x15, 0x2c, 0xf6, 0x89, 0x9b, 0x86, 0xa5, 0xc5, 0x38, 0x03, 0x6f, 0xa3, 0xb4, 0x8e, 0x0f, 0x89, - 0x7b, 0x4f, 0x03, 0xab, 0xc3, 0xcf, 0xc1, 0x13, 0x4c, 0xa8, 0x78, 0x46, 0xdc, 0x7f, 0xbf, 0x81, - 0x95, 0xe0, 0x53, 0x98, 0x09, 0xcd, 0xd7, 0x82, 0xb6, 0x71, 0x60, 0xd5, 0xe4, 0xce, 0xea, 0x85, - 0xe6, 0x05, 0x6d, 0x57, 0xd2, 0x74, 0x37, 0xe5, 0xa1, 0xb0, 0xc9, 0xe2, 0x0a, 0xe6, 0x7f, 0xd1, - 0x38, 0x02, 0xf7, 0x2b, 0xbb, 0x89, 0x11, 0x41, 0x69, 0x58, 0x8e, 0x10, 0xbf, 0x00, 0xff, 0x1b, - 0x6d, 0x7a, 0xf6, 0xff, 0xbf, 0x98, 0x34, 0x67, 0xce, 0x1b, 0x94, 0x1c, 0x81, 0x6f, 0xaf, 0x81, - 0x03, 0xf0, 0xde, 0xbf, 0xfb, 0xbc, 0x8a, 0xd0, 0x88, 0x8a, 0xcb, 0x8f, 0xab, 0xc8, 0x39, 0xf6, - 0x82, 0xeb, 0x88, 0x9d, 0xcf, 0xc0, 0xef, 0x65, 0xad, 0x64, 0x82, 0x21, 0xda, 0x2f, 0x95, 0x24, - 0x80, 0x7f, 0x73, 0xab, 0x1f, 0x86, 0xc9, 0x8a, 0x6e, 0x1a, 0x76, 0x1c, 0x04, 0x55, 0x34, 0x0c, - 0xc3, 0x30, 0x3b, 0x73, 0x02, 0x74, 0xfe, 0xfa, 0xfa, 0x15, 0xaf, 0xcd, 0x97, 0x7e, 0x93, 0x6d, - 0x95, 0x58, 0x72, 0xd5, 0x50, 0xc9, 0x97, 0x76, 0xd3, 0x36, 0xfd, 0x6e, 0x02, 0xdb, 0x13, 0xce, - 0xe4, 0x09, 0x57, 0x4b, 0xc3, 0xb4, 0xa9, 0xa8, 0xa1, 0xe3, 0x3a, 0x5e, 0x1d, 0xfc, 0x0a, 0x00, - 0x00, 0xff, 0xff, 0xe7, 0x7a, 0x0f, 0x3a, 0xc8, 0x02, 0x00, 0x00, -} diff --git a/protoc-gen-go/testdata/imp/imp.proto b/protoc-gen-go/testdata/imp/imp.proto deleted file mode 100644 index 43f88baced..0000000000 --- a/protoc-gen-go/testdata/imp/imp.proto +++ /dev/null @@ -1,72 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2010 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto2"; - -package imp; - -option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/imp"; - -import public "imp/imp2/imp2.proto"; -import "imp/imp3/imp3.proto"; - -message ImportedMessage { - required int64 field = 1; - - // The forwarded getters for these fields are fiddly to get right. - optional ImportedMessage2 local_msg = 2; - optional ForeignImportedMessage foreign_msg = 3; // in imp3.proto - optional Owner enum_field = 4; - oneof union { - int32 state = 9; - } - - repeated string name = 5; - repeated Owner boss = 6; - repeated ImportedMessage2 memo = 7; - - map msg_map = 8; - - enum Owner { - DAVE = 1; - MIKE = 2; - } - - extensions 90 to 100; -} - -message ImportedMessage2 { -} - -message ImportedExtendable { - option message_set_wire_format = true; - extensions 100 to max; -} diff --git a/protoc-gen-go/testdata/imp/imp2/imp2-enum.pb.go b/protoc-gen-go/testdata/imp/imp2/imp2-enum.pb.go deleted file mode 100644 index 65f53bb508..0000000000 --- a/protoc-gen-go/testdata/imp/imp2/imp2-enum.pb.go +++ /dev/null @@ -1,102 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: imp/imp2/imp2-enum.proto - -package imp2 // import "github.com/golang/protobuf/protoc-gen-go/testdata/imp/imp2" - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type EnumPB_Type int32 - -const ( - EnumPB_TYPE_1 EnumPB_Type = 0 -) - -var EnumPB_Type_name = map[int32]string{ - 0: "TYPE_1", -} -var EnumPB_Type_value = map[string]int32{ - "TYPE_1": 0, -} - -func (x EnumPB_Type) Enum() *EnumPB_Type { - p := new(EnumPB_Type) - *p = x - return p -} -func (x EnumPB_Type) String() string { - return proto.EnumName(EnumPB_Type_name, int32(x)) -} -func (x *EnumPB_Type) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(EnumPB_Type_value, data, "EnumPB_Type") - if err != nil { - return err - } - *x = EnumPB_Type(value) - return nil -} -func (EnumPB_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_imp2_enum_1cca8279ac3cbb94, []int{0, 0} -} - -type EnumPB struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *EnumPB) Reset() { *m = EnumPB{} } -func (m *EnumPB) String() string { return proto.CompactTextString(m) } -func (*EnumPB) ProtoMessage() {} -func (*EnumPB) Descriptor() ([]byte, []int) { - return fileDescriptor_imp2_enum_1cca8279ac3cbb94, []int{0} -} -func (m *EnumPB) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_EnumPB.Unmarshal(m, b) -} -func (m *EnumPB) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_EnumPB.Marshal(b, m, deterministic) -} -func (dst *EnumPB) XXX_Merge(src proto.Message) { - xxx_messageInfo_EnumPB.Merge(dst, src) -} -func (m *EnumPB) XXX_Size() int { - return xxx_messageInfo_EnumPB.Size(m) -} -func (m *EnumPB) XXX_DiscardUnknown() { - xxx_messageInfo_EnumPB.DiscardUnknown(m) -} - -var xxx_messageInfo_EnumPB proto.InternalMessageInfo - -func init() { - proto.RegisterType((*EnumPB)(nil), "imp.EnumPB") - proto.RegisterEnum("imp.EnumPB_Type", EnumPB_Type_name, EnumPB_Type_value) -} - -func init() { proto.RegisterFile("imp/imp2/imp2-enum.proto", fileDescriptor_imp2_enum_1cca8279ac3cbb94) } - -var fileDescriptor_imp2_enum_1cca8279ac3cbb94 = []byte{ - // 131 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xc8, 0xcc, 0x2d, 0xd0, - 0xcf, 0xcc, 0x2d, 0x30, 0x02, 0x13, 0xba, 0xa9, 0x79, 0xa5, 0xb9, 0x7a, 0x05, 0x45, 0xf9, 0x25, - 0xf9, 0x42, 0xcc, 0x99, 0xb9, 0x05, 0x4a, 0x32, 0x5c, 0x6c, 0xae, 0x79, 0xa5, 0xb9, 0x01, 0x4e, - 0x4a, 0x42, 0x5c, 0x2c, 0x21, 0x95, 0x05, 0xa9, 0x42, 0x5c, 0x5c, 0x6c, 0x21, 0x91, 0x01, 0xae, - 0xf1, 0x86, 0x02, 0x0c, 0x4e, 0x36, 0x51, 0x56, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, - 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0x39, 0x89, 0x79, 0xe9, 0xfa, 0x60, 0xdd, 0x49, 0xa5, 0x69, 0x10, - 0x46, 0xb2, 0x6e, 0x7a, 0x6a, 0x9e, 0x6e, 0x7a, 0xbe, 0x7e, 0x49, 0x6a, 0x71, 0x49, 0x4a, 0x62, - 0x49, 0xa2, 0x3e, 0xcc, 0x42, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc6, 0x64, 0x9c, 0xa4, 0x7b, - 0x00, 0x00, 0x00, -} diff --git a/protoc-gen-go/testdata/imp/imp2/imp2.pb.go b/protoc-gen-go/testdata/imp/imp2/imp2.pb.go deleted file mode 100644 index ecdcf6d597..0000000000 --- a/protoc-gen-go/testdata/imp/imp2/imp2.pb.go +++ /dev/null @@ -1,167 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: imp/imp2/imp2.proto - -package imp2 // import "github.com/golang/protobuf/protoc-gen-go/testdata/imp/imp2" - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type PubliclyImportedEnum int32 - -const ( - PubliclyImportedEnum_GLASSES PubliclyImportedEnum = 1 - PubliclyImportedEnum_HAIR PubliclyImportedEnum = 2 -) - -var PubliclyImportedEnum_name = map[int32]string{ - 1: "GLASSES", - 2: "HAIR", -} -var PubliclyImportedEnum_value = map[string]int32{ - "GLASSES": 1, - "HAIR": 2, -} - -func (x PubliclyImportedEnum) Enum() *PubliclyImportedEnum { - p := new(PubliclyImportedEnum) - *p = x - return p -} -func (x PubliclyImportedEnum) String() string { - return proto.EnumName(PubliclyImportedEnum_name, int32(x)) -} -func (x *PubliclyImportedEnum) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(PubliclyImportedEnum_value, data, "PubliclyImportedEnum") - if err != nil { - return err - } - *x = PubliclyImportedEnum(value) - return nil -} -func (PubliclyImportedEnum) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_imp2_8c527bbde1f96503, []int{0} -} - -type PubliclyImportedMessage struct { - Field *int64 `protobuf:"varint,1,opt,name=field" json:"field,omitempty"` - // Field using a type in the same Go package, but a different source file. - Field2 *EnumPB_Type `protobuf:"varint,2,opt,name=field2,enum=imp.EnumPB_Type" json:"field2,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *PubliclyImportedMessage) Reset() { *m = PubliclyImportedMessage{} } -func (m *PubliclyImportedMessage) String() string { return proto.CompactTextString(m) } -func (*PubliclyImportedMessage) ProtoMessage() {} -func (*PubliclyImportedMessage) Descriptor() ([]byte, []int) { - return fileDescriptor_imp2_8c527bbde1f96503, []int{0} -} -func (m *PubliclyImportedMessage) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_PubliclyImportedMessage.Unmarshal(m, b) -} -func (m *PubliclyImportedMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_PubliclyImportedMessage.Marshal(b, m, deterministic) -} -func (dst *PubliclyImportedMessage) XXX_Merge(src proto.Message) { - xxx_messageInfo_PubliclyImportedMessage.Merge(dst, src) -} -func (m *PubliclyImportedMessage) XXX_Size() int { - return xxx_messageInfo_PubliclyImportedMessage.Size(m) -} -func (m *PubliclyImportedMessage) XXX_DiscardUnknown() { - xxx_messageInfo_PubliclyImportedMessage.DiscardUnknown(m) -} - -var xxx_messageInfo_PubliclyImportedMessage proto.InternalMessageInfo - -func (m *PubliclyImportedMessage) GetField() int64 { - if m != nil && m.Field != nil { - return *m.Field - } - return 0 -} - -func (m *PubliclyImportedMessage) GetField2() EnumPB_Type { - if m != nil && m.Field2 != nil { - return *m.Field2 - } - return EnumPB_TYPE_1 -} - -type PubliclyImportedMessage2 struct { - Field *PubliclyImportedMessage `protobuf:"bytes,1,opt,name=field" json:"field,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *PubliclyImportedMessage2) Reset() { *m = PubliclyImportedMessage2{} } -func (m *PubliclyImportedMessage2) String() string { return proto.CompactTextString(m) } -func (*PubliclyImportedMessage2) ProtoMessage() {} -func (*PubliclyImportedMessage2) Descriptor() ([]byte, []int) { - return fileDescriptor_imp2_8c527bbde1f96503, []int{1} -} -func (m *PubliclyImportedMessage2) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_PubliclyImportedMessage2.Unmarshal(m, b) -} -func (m *PubliclyImportedMessage2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_PubliclyImportedMessage2.Marshal(b, m, deterministic) -} -func (dst *PubliclyImportedMessage2) XXX_Merge(src proto.Message) { - xxx_messageInfo_PubliclyImportedMessage2.Merge(dst, src) -} -func (m *PubliclyImportedMessage2) XXX_Size() int { - return xxx_messageInfo_PubliclyImportedMessage2.Size(m) -} -func (m *PubliclyImportedMessage2) XXX_DiscardUnknown() { - xxx_messageInfo_PubliclyImportedMessage2.DiscardUnknown(m) -} - -var xxx_messageInfo_PubliclyImportedMessage2 proto.InternalMessageInfo - -func (m *PubliclyImportedMessage2) GetField() *PubliclyImportedMessage { - if m != nil { - return m.Field - } - return nil -} - -func init() { - proto.RegisterType((*PubliclyImportedMessage)(nil), "imp.PubliclyImportedMessage") - proto.RegisterType((*PubliclyImportedMessage2)(nil), "imp.PubliclyImportedMessage2") - proto.RegisterEnum("imp.PubliclyImportedEnum", PubliclyImportedEnum_name, PubliclyImportedEnum_value) -} - -func init() { proto.RegisterFile("imp/imp2/imp2.proto", fileDescriptor_imp2_8c527bbde1f96503) } - -var fileDescriptor_imp2_8c527bbde1f96503 = []byte{ - // 238 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xce, 0xcc, 0x2d, 0xd0, - 0xcf, 0xcc, 0x2d, 0x30, 0x02, 0x13, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xcc, 0x99, 0xb9, - 0x05, 0x52, 0x12, 0x28, 0x32, 0xba, 0xa9, 0x79, 0xa5, 0xb9, 0x10, 0x69, 0xa5, 0x48, 0x2e, 0xf1, - 0x80, 0xd2, 0xa4, 0x9c, 0xcc, 0xe4, 0x9c, 0x4a, 0xcf, 0xdc, 0x82, 0xfc, 0xa2, 0x92, 0xd4, 0x14, - 0xdf, 0xd4, 0xe2, 0xe2, 0xc4, 0xf4, 0x54, 0x21, 0x11, 0x2e, 0xd6, 0xb4, 0xcc, 0xd4, 0x9c, 0x14, - 0x09, 0x46, 0x05, 0x46, 0x0d, 0xe6, 0x20, 0x08, 0x47, 0x48, 0x83, 0x8b, 0x0d, 0xcc, 0x30, 0x92, - 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x33, 0x12, 0xd0, 0xcb, 0xcc, 0x2d, 0xd0, 0x73, 0xcd, 0x2b, 0xcd, - 0x0d, 0x70, 0xd2, 0x0b, 0xa9, 0x2c, 0x48, 0x0d, 0x82, 0xca, 0x2b, 0xf9, 0x71, 0x49, 0xe0, 0x30, - 0xda, 0x48, 0xc8, 0x08, 0xd9, 0x6c, 0x6e, 0x23, 0x19, 0xb0, 0x21, 0x38, 0x54, 0x43, 0x6d, 0xd6, - 0xd2, 0xe5, 0x12, 0x41, 0x57, 0x01, 0xb2, 0x56, 0x88, 0x9b, 0x8b, 0xdd, 0xdd, 0xc7, 0x31, 0x38, - 0xd8, 0x35, 0x58, 0x80, 0x51, 0x88, 0x83, 0x8b, 0xc5, 0xc3, 0xd1, 0x33, 0x48, 0x80, 0xc9, 0xc9, - 0x26, 0xca, 0x2a, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0x3d, 0x3f, - 0x27, 0x31, 0x2f, 0x5d, 0x1f, 0xec, 0xe9, 0xa4, 0xd2, 0x34, 0x08, 0x23, 0x59, 0x37, 0x3d, 0x35, - 0x4f, 0x37, 0x3d, 0x5f, 0xbf, 0x24, 0xb5, 0xb8, 0x24, 0x25, 0xb1, 0x24, 0x51, 0x1f, 0x16, 0x4e, - 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xdf, 0xf8, 0xc4, 0xf4, 0x4c, 0x01, 0x00, 0x00, -} diff --git a/protoc-gen-go/testdata/imp/imp3/imp3.pb.go b/protoc-gen-go/testdata/imp/imp3/imp3.pb.go deleted file mode 100644 index 1d2833939f..0000000000 --- a/protoc-gen-go/testdata/imp/imp3/imp3.pb.go +++ /dev/null @@ -1,76 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: imp/imp3/imp3.proto - -package imp3 // import "github.com/golang/protobuf/protoc-gen-go/testdata/imp/imp3" - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type ForeignImportedMessage struct { - Tuber *string `protobuf:"bytes,1,opt,name=tuber" json:"tuber,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ForeignImportedMessage) Reset() { *m = ForeignImportedMessage{} } -func (m *ForeignImportedMessage) String() string { return proto.CompactTextString(m) } -func (*ForeignImportedMessage) ProtoMessage() {} -func (*ForeignImportedMessage) Descriptor() ([]byte, []int) { - return fileDescriptor_imp3_4aae87d6f1c23d12, []int{0} -} -func (m *ForeignImportedMessage) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ForeignImportedMessage.Unmarshal(m, b) -} -func (m *ForeignImportedMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ForeignImportedMessage.Marshal(b, m, deterministic) -} -func (dst *ForeignImportedMessage) XXX_Merge(src proto.Message) { - xxx_messageInfo_ForeignImportedMessage.Merge(dst, src) -} -func (m *ForeignImportedMessage) XXX_Size() int { - return xxx_messageInfo_ForeignImportedMessage.Size(m) -} -func (m *ForeignImportedMessage) XXX_DiscardUnknown() { - xxx_messageInfo_ForeignImportedMessage.DiscardUnknown(m) -} - -var xxx_messageInfo_ForeignImportedMessage proto.InternalMessageInfo - -func (m *ForeignImportedMessage) GetTuber() string { - if m != nil && m.Tuber != nil { - return *m.Tuber - } - return "" -} - -func init() { - proto.RegisterType((*ForeignImportedMessage)(nil), "imp.ForeignImportedMessage") -} - -func init() { proto.RegisterFile("imp/imp3/imp3.proto", fileDescriptor_imp3_4aae87d6f1c23d12) } - -var fileDescriptor_imp3_4aae87d6f1c23d12 = []byte{ - // 139 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xce, 0xcc, 0x2d, 0xd0, - 0xcf, 0xcc, 0x2d, 0x30, 0x06, 0x13, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xcc, 0x99, 0xb9, - 0x05, 0x4a, 0x7a, 0x5c, 0x62, 0x6e, 0xf9, 0x45, 0xa9, 0x99, 0xe9, 0x79, 0x9e, 0xb9, 0x05, 0xf9, - 0x45, 0x25, 0xa9, 0x29, 0xbe, 0xa9, 0xc5, 0xc5, 0x89, 0xe9, 0xa9, 0x42, 0x22, 0x5c, 0xac, 0x25, - 0xa5, 0x49, 0xa9, 0x45, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x10, 0x8e, 0x93, 0x4d, 0x94, - 0x55, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x7a, 0x7e, 0x4e, 0x62, - 0x5e, 0xba, 0x3e, 0xd8, 0xbc, 0xa4, 0xd2, 0x34, 0x08, 0x23, 0x59, 0x37, 0x3d, 0x35, 0x4f, 0x37, - 0x3d, 0x5f, 0xbf, 0x24, 0xb5, 0xb8, 0x24, 0x25, 0xb1, 0x24, 0x51, 0x1f, 0x66, 0x3b, 0x20, 0x00, - 0x00, 0xff, 0xff, 0xda, 0xb9, 0x43, 0xe2, 0x88, 0x00, 0x00, 0x00, -} diff --git a/protoc-gen-go/testdata/import_public/a.pb.go b/protoc-gen-go/testdata/import_public/a.pb.go new file mode 100644 index 0000000000..5b780fd5cf --- /dev/null +++ b/protoc-gen-go/testdata/import_public/a.pb.go @@ -0,0 +1,110 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: import_public/a.proto + +package import_public // import "github.com/golang/protobuf/protoc-gen-go/testdata/import_public" + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" +import sub "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +// M from public import import_public/sub/a.proto +type M = sub.M + +// E from public import import_public/sub/a.proto +type E = sub.E + +var E_name = sub.E_name +var E_value = sub.E_value + +const E_ZERO = E(sub.E_ZERO) + +// Ignoring public import of Local from import_public/b.proto + +type Public struct { + M *sub.M `protobuf:"bytes,1,opt,name=m" json:"m,omitempty"` + E sub.E `protobuf:"varint,2,opt,name=e,enum=goproto.test.import_public.sub.E" json:"e,omitempty"` + Local *Local `protobuf:"bytes,3,opt,name=local" json:"local,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Public) Reset() { *m = Public{} } +func (m *Public) String() string { return proto.CompactTextString(m) } +func (*Public) ProtoMessage() {} +func (*Public) Descriptor() ([]byte, []int) { + return fileDescriptor_a_c0314c022b7c17d8, []int{0} +} +func (m *Public) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Public.Unmarshal(m, b) +} +func (m *Public) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Public.Marshal(b, m, deterministic) +} +func (dst *Public) XXX_Merge(src proto.Message) { + xxx_messageInfo_Public.Merge(dst, src) +} +func (m *Public) XXX_Size() int { + return xxx_messageInfo_Public.Size(m) +} +func (m *Public) XXX_DiscardUnknown() { + xxx_messageInfo_Public.DiscardUnknown(m) +} + +var xxx_messageInfo_Public proto.InternalMessageInfo + +func (m *Public) GetM() *sub.M { + if m != nil { + return m.M + } + return nil +} + +func (m *Public) GetE() sub.E { + if m != nil { + return m.E + } + return sub.E_ZERO +} + +func (m *Public) GetLocal() *Local { + if m != nil { + return m.Local + } + return nil +} + +func init() { + proto.RegisterType((*Public)(nil), "goproto.test.import_public.Public") +} + +func init() { proto.RegisterFile("import_public/a.proto", fileDescriptor_a_c0314c022b7c17d8) } + +var fileDescriptor_a_c0314c022b7c17d8 = []byte{ + // 200 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcd, 0xcc, 0x2d, 0xc8, + 0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x4f, 0xd4, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x92, 0x4a, 0xcf, 0x07, 0x33, 0xf4, 0x4a, 0x52, 0x8b, 0x4b, 0xf4, 0x50, 0xd4, 0x48, + 0x49, 0xa2, 0x6a, 0x29, 0x2e, 0x4d, 0x82, 0x69, 0x93, 0x42, 0x33, 0x2d, 0x09, 0x22, 0xac, 0xb4, + 0x98, 0x91, 0x8b, 0x2d, 0x00, 0x2c, 0x24, 0xa4, 0xcf, 0xc5, 0x98, 0x2b, 0xc1, 0xa8, 0xc0, 0xa8, + 0xc1, 0x6d, 0xa4, 0xa8, 0x87, 0xdb, 0x12, 0xbd, 0xe2, 0xd2, 0x24, 0x3d, 0xdf, 0x20, 0xc6, 0x5c, + 0x90, 0x86, 0x54, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x3e, 0xc2, 0x1a, 0x5c, 0x83, 0x18, 0x53, 0x85, + 0xcc, 0xb9, 0x58, 0x73, 0xf2, 0x93, 0x13, 0x73, 0x24, 0x98, 0x09, 0xdb, 0xe2, 0x03, 0x52, 0x18, + 0x04, 0x51, 0xef, 0xe4, 0x18, 0x65, 0x9f, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, + 0xab, 0x9f, 0x9e, 0x9f, 0x93, 0x98, 0x97, 0xae, 0x0f, 0xd6, 0x9a, 0x54, 0x9a, 0x06, 0x61, 0x24, + 0xeb, 0xa6, 0xa7, 0xe6, 0xe9, 0xa6, 0xe7, 0xeb, 0x83, 0xcc, 0x4a, 0x49, 0x2c, 0x49, 0xd4, 0x47, + 0x31, 0x2f, 0x80, 0x21, 0x80, 0x31, 0x89, 0x0d, 0xac, 0xd2, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, + 0x70, 0xc5, 0xc3, 0x79, 0x5a, 0x01, 0x00, 0x00, +} diff --git a/protoc-gen-go/testdata/imp/imp2/imp2.proto b/protoc-gen-go/testdata/import_public/a.proto similarity index 78% rename from protoc-gen-go/testdata/imp/imp2/imp2.proto rename to protoc-gen-go/testdata/import_public/a.proto index 6e709f516c..957ad89711 100644 --- a/protoc-gen-go/testdata/imp/imp2/imp2.proto +++ b/protoc-gen-go/testdata/import_public/a.proto @@ -1,6 +1,6 @@ // Go support for Protocol Buffers - Google's data interchange format // -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2018 The Go Authors. All rights reserved. // https://github.com/golang/protobuf // // Redistribution and use in source and binary forms, with or without @@ -29,26 +29,17 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -syntax = "proto2"; +syntax = "proto3"; -package imp; +package goproto.test.import_public; -option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/imp/imp2"; +option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_public"; -import "imp/imp2/imp2-enum.proto"; +import public "import_public/sub/a.proto"; // Different Go package. +import public "import_public/b.proto"; // Same Go package. -message PubliclyImportedMessage { - optional int64 field = 1; - - // Field using a type in the same Go package, but a different source file. - optional imp.EnumPB.Type field2 = 2; -} - -message PubliclyImportedMessage2 { - optional PubliclyImportedMessage field = 1; -} - -enum PubliclyImportedEnum { - GLASSES = 1; - HAIR = 2; +message Public { + goproto.test.import_public.sub.M m = 1; + goproto.test.import_public.sub.E e = 2; + Local local = 3; } diff --git a/protoc-gen-go/testdata/import_public/b.pb.go b/protoc-gen-go/testdata/import_public/b.pb.go new file mode 100644 index 0000000000..427aa4f32d --- /dev/null +++ b/protoc-gen-go/testdata/import_public/b.pb.go @@ -0,0 +1,87 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: import_public/b.proto + +package import_public // import "github.com/golang/protobuf/protoc-gen-go/testdata/import_public" + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" +import sub "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type Local struct { + M *sub.M `protobuf:"bytes,1,opt,name=m" json:"m,omitempty"` + E sub.E `protobuf:"varint,2,opt,name=e,enum=goproto.test.import_public.sub.E" json:"e,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Local) Reset() { *m = Local{} } +func (m *Local) String() string { return proto.CompactTextString(m) } +func (*Local) ProtoMessage() {} +func (*Local) Descriptor() ([]byte, []int) { + return fileDescriptor_b_7f20a805fad67bd0, []int{0} +} +func (m *Local) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Local.Unmarshal(m, b) +} +func (m *Local) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Local.Marshal(b, m, deterministic) +} +func (dst *Local) XXX_Merge(src proto.Message) { + xxx_messageInfo_Local.Merge(dst, src) +} +func (m *Local) XXX_Size() int { + return xxx_messageInfo_Local.Size(m) +} +func (m *Local) XXX_DiscardUnknown() { + xxx_messageInfo_Local.DiscardUnknown(m) +} + +var xxx_messageInfo_Local proto.InternalMessageInfo + +func (m *Local) GetM() *sub.M { + if m != nil { + return m.M + } + return nil +} + +func (m *Local) GetE() sub.E { + if m != nil { + return m.E + } + return sub.E_ZERO +} + +func init() { + proto.RegisterType((*Local)(nil), "goproto.test.import_public.Local") +} + +func init() { proto.RegisterFile("import_public/b.proto", fileDescriptor_b_7f20a805fad67bd0) } + +var fileDescriptor_b_7f20a805fad67bd0 = []byte{ + // 174 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcd, 0xcc, 0x2d, 0xc8, + 0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x4f, 0xd2, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x92, 0x4a, 0xcf, 0x07, 0x33, 0xf4, 0x4a, 0x52, 0x8b, 0x4b, 0xf4, 0x50, 0xd4, 0x48, + 0x49, 0xa2, 0x6a, 0x29, 0x2e, 0x4d, 0xd2, 0x4f, 0x84, 0x68, 0x53, 0xca, 0xe4, 0x62, 0xf5, 0xc9, + 0x4f, 0x4e, 0xcc, 0x11, 0xd2, 0xe7, 0x62, 0xcc, 0x95, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x52, + 0xd4, 0xc3, 0x6d, 0x96, 0x5e, 0x71, 0x69, 0x92, 0x9e, 0x6f, 0x10, 0x63, 0x2e, 0x48, 0x43, 0xaa, + 0x04, 0x93, 0x02, 0xa3, 0x06, 0x1f, 0x61, 0x0d, 0xae, 0x41, 0x8c, 0xa9, 0x4e, 0x8e, 0x51, 0xf6, + 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0x39, 0x89, 0x79, + 0xe9, 0xfa, 0x60, 0x6d, 0x49, 0xa5, 0x69, 0x10, 0x46, 0xb2, 0x6e, 0x7a, 0x6a, 0x9e, 0x6e, 0x7a, + 0xbe, 0x3e, 0xc8, 0x9c, 0x94, 0xc4, 0x92, 0x44, 0x7d, 0x14, 0xb3, 0x92, 0xd8, 0xc0, 0xaa, 0x8c, + 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xd6, 0x2b, 0x5f, 0x8e, 0x04, 0x01, 0x00, 0x00, +} diff --git a/protoc-gen-go/testdata/imp/imp3/imp3.proto b/protoc-gen-go/testdata/import_public/b.proto similarity index 86% rename from protoc-gen-go/testdata/imp/imp3/imp3.proto rename to protoc-gen-go/testdata/import_public/b.proto index a322a74ee3..1dbca3e496 100644 --- a/protoc-gen-go/testdata/imp/imp3/imp3.proto +++ b/protoc-gen-go/testdata/import_public/b.proto @@ -1,6 +1,6 @@ // Go support for Protocol Buffers - Google's data interchange format // -// Copyright 2012 The Go Authors. All rights reserved. +// Copyright 2018 The Go Authors. All rights reserved. // https://github.com/golang/protobuf // // Redistribution and use in source and binary forms, with or without @@ -29,12 +29,15 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -syntax = "proto2"; +syntax = "proto3"; -package imp; +package goproto.test.import_public; -option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/imp/imp3"; +option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_public"; -message ForeignImportedMessage { - optional string tuber = 1; +import "import_public/sub/a.proto"; + +message Local { + goproto.test.import_public.sub.M m = 1; + goproto.test.import_public.sub.E e = 2; } diff --git a/protoc-gen-go/testdata/import_public/sub/a.pb.go b/protoc-gen-go/testdata/import_public/sub/a.pb.go new file mode 100644 index 0000000000..4f8f6d2439 --- /dev/null +++ b/protoc-gen-go/testdata/import_public/sub/a.pb.go @@ -0,0 +1,100 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: import_public/sub/a.proto + +package sub // import "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub" + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type E int32 + +const ( + E_ZERO E = 0 +) + +var E_name = map[int32]string{ + 0: "ZERO", +} +var E_value = map[string]int32{ + "ZERO": 0, +} + +func (x E) String() string { + return proto.EnumName(E_name, int32(x)) +} +func (E) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_a_91ca0264a534463a, []int{0} +} + +type M struct { + // Field using a type in the same Go package, but a different source file. + M2 *M2 `protobuf:"bytes,1,opt,name=m2" json:"m2,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *M) Reset() { *m = M{} } +func (m *M) String() string { return proto.CompactTextString(m) } +func (*M) ProtoMessage() {} +func (*M) Descriptor() ([]byte, []int) { + return fileDescriptor_a_91ca0264a534463a, []int{0} +} +func (m *M) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_M.Unmarshal(m, b) +} +func (m *M) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_M.Marshal(b, m, deterministic) +} +func (dst *M) XXX_Merge(src proto.Message) { + xxx_messageInfo_M.Merge(dst, src) +} +func (m *M) XXX_Size() int { + return xxx_messageInfo_M.Size(m) +} +func (m *M) XXX_DiscardUnknown() { + xxx_messageInfo_M.DiscardUnknown(m) +} + +var xxx_messageInfo_M proto.InternalMessageInfo + +func (m *M) GetM2() *M2 { + if m != nil { + return m.M2 + } + return nil +} + +func init() { + proto.RegisterType((*M)(nil), "goproto.test.import_public.sub.M") + proto.RegisterEnum("goproto.test.import_public.sub.E", E_name, E_value) +} + +func init() { proto.RegisterFile("import_public/sub/a.proto", fileDescriptor_a_91ca0264a534463a) } + +var fileDescriptor_a_91ca0264a534463a = []byte{ + // 172 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0xcc, 0x2d, 0xc8, + 0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x2f, 0x2e, 0x4d, 0xd2, 0x4f, 0xd4, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4b, 0xcf, 0x07, 0x33, 0xf4, 0x4a, 0x52, 0x8b, 0x4b, + 0xf4, 0x50, 0xd4, 0xe9, 0x15, 0x97, 0x26, 0x49, 0x61, 0xd1, 0x9a, 0x04, 0xd1, 0xaa, 0x64, 0xce, + 0xc5, 0xe8, 0x2b, 0x64, 0xc4, 0xc5, 0x94, 0x6b, 0x24, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0xa4, + 0xa4, 0x87, 0xdf, 0x30, 0x3d, 0x5f, 0xa3, 0x20, 0xa6, 0x5c, 0x23, 0x2d, 0x5e, 0x2e, 0x46, 0x57, + 0x21, 0x0e, 0x2e, 0x96, 0x28, 0xd7, 0x20, 0x7f, 0x01, 0x06, 0x27, 0xd7, 0x28, 0xe7, 0xf4, 0xcc, + 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xf4, 0xfc, 0x9c, 0xc4, 0xbc, 0x74, 0x7d, + 0xb0, 0x39, 0x49, 0xa5, 0x69, 0x10, 0x46, 0xb2, 0x6e, 0x7a, 0x6a, 0x9e, 0x6e, 0x7a, 0xbe, 0x3e, + 0xc8, 0xe0, 0x94, 0xc4, 0x92, 0x44, 0x7d, 0x0c, 0x67, 0x25, 0xb1, 0x81, 0x55, 0x1a, 0x03, 0x02, + 0x00, 0x00, 0xff, 0xff, 0x81, 0xcc, 0x07, 0x7d, 0xed, 0x00, 0x00, 0x00, +} diff --git a/protoc-gen-go/testdata/imp/imp2/imp2-enum.proto b/protoc-gen-go/testdata/import_public/sub/a.proto similarity index 84% rename from protoc-gen-go/testdata/imp/imp2/imp2-enum.proto rename to protoc-gen-go/testdata/import_public/sub/a.proto index b31a4f74f1..4494c818a6 100644 --- a/protoc-gen-go/testdata/imp/imp2/imp2-enum.proto +++ b/protoc-gen-go/testdata/import_public/sub/a.proto @@ -1,6 +1,6 @@ // Go support for Protocol Buffers - Google's data interchange format // -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2018 The Go Authors. All rights reserved. // https://github.com/golang/protobuf // // Redistribution and use in source and binary forms, with or without @@ -29,14 +29,19 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -syntax = "proto2"; +syntax = "proto3"; -package imp; +package goproto.test.import_public.sub; -option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/imp/imp2"; +option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub"; -message EnumPB { - enum Type { - TYPE_1 = 0; - } +import "import_public/sub/b.proto"; + +message M { + // Field using a type in the same Go package, but a different source file. + M2 m2 = 1; +} + +enum E { + ZERO = 0; } diff --git a/protoc-gen-go/testdata/import_public/sub/b.pb.go b/protoc-gen-go/testdata/import_public/sub/b.pb.go new file mode 100644 index 0000000000..d57a3bb9aa --- /dev/null +++ b/protoc-gen-go/testdata/import_public/sub/b.pb.go @@ -0,0 +1,67 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: import_public/sub/b.proto + +package sub // import "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub" + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type M2 struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *M2) Reset() { *m = M2{} } +func (m *M2) String() string { return proto.CompactTextString(m) } +func (*M2) ProtoMessage() {} +func (*M2) Descriptor() ([]byte, []int) { + return fileDescriptor_b_eba25180453d86b4, []int{0} +} +func (m *M2) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_M2.Unmarshal(m, b) +} +func (m *M2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_M2.Marshal(b, m, deterministic) +} +func (dst *M2) XXX_Merge(src proto.Message) { + xxx_messageInfo_M2.Merge(dst, src) +} +func (m *M2) XXX_Size() int { + return xxx_messageInfo_M2.Size(m) +} +func (m *M2) XXX_DiscardUnknown() { + xxx_messageInfo_M2.DiscardUnknown(m) +} + +var xxx_messageInfo_M2 proto.InternalMessageInfo + +func init() { + proto.RegisterType((*M2)(nil), "goproto.test.import_public.sub.M2") +} + +func init() { proto.RegisterFile("import_public/sub/b.proto", fileDescriptor_b_eba25180453d86b4) } + +var fileDescriptor_b_eba25180453d86b4 = []byte{ + // 127 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0xcc, 0x2d, 0xc8, + 0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x2f, 0x2e, 0x4d, 0xd2, 0x4f, 0xd2, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4b, 0xcf, 0x07, 0x33, 0xf4, 0x4a, 0x52, 0x8b, 0x4b, + 0xf4, 0x50, 0xd4, 0xe9, 0x15, 0x97, 0x26, 0x29, 0xb1, 0x70, 0x31, 0xf9, 0x1a, 0x39, 0xb9, 0x46, + 0x39, 0xa7, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xa7, 0xe7, 0xe7, 0x24, + 0xe6, 0xa5, 0xeb, 0x83, 0xf5, 0x25, 0x95, 0xa6, 0x41, 0x18, 0xc9, 0xba, 0xe9, 0xa9, 0x79, 0xba, + 0xe9, 0xf9, 0xfa, 0x20, 0x83, 0x52, 0x12, 0x4b, 0x12, 0xf5, 0x31, 0x2c, 0x4d, 0x62, 0x03, 0xab, + 0x34, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x64, 0x42, 0xe4, 0xa8, 0x90, 0x00, 0x00, 0x00, +} diff --git a/protoc-gen-go/testdata/imports/test_import_public.proto b/protoc-gen-go/testdata/import_public/sub/b.proto similarity index 93% rename from protoc-gen-go/testdata/imports/test_import_public.proto rename to protoc-gen-go/testdata/import_public/sub/b.proto index 7130cd8ea7..c7299e0f29 100644 --- a/protoc-gen-go/testdata/imports/test_import_public.proto +++ b/protoc-gen-go/testdata/import_public/sub/b.proto @@ -31,13 +31,9 @@ syntax = "proto3"; -package test; +package goproto.test.import_public.sub; -option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/imports"; +option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub"; -import public "imports/test_a_1/m1.proto"; - -message Public { - test.a.M1 m1 = 1; - test.a.E1 e1 = 2; +message M2 { } diff --git a/protoc-gen-go/testdata/import_public_test.go b/protoc-gen-go/testdata/import_public_test.go new file mode 100644 index 0000000000..7ef776bf78 --- /dev/null +++ b/protoc-gen-go/testdata/import_public_test.go @@ -0,0 +1,66 @@ +// Go support for Protocol Buffers - Google's data interchange format +// +// Copyright 2010 The Go Authors. All rights reserved. +// https://github.com/golang/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// +build go1.9 + +package testdata + +import ( + "testing" + + mainpb "github.com/golang/protobuf/protoc-gen-go/testdata/import_public" + subpb "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub" +) + +func TestImportPublicLink(t *testing.T) { + // mainpb.[ME] should be interchangable with subpb.[ME]. + var _ mainpb.M = subpb.M{} + var _ mainpb.E = subpb.E(0) + _ = &mainpb.Public{ + M: &mainpb.M{}, + E: mainpb.E_ZERO, + Local: &mainpb.Local{ + M: &mainpb.M{}, + E: mainpb.E_ZERO, + }, + } + _ = &mainpb.Public{ + M: &subpb.M{}, + E: subpb.E_ZERO, + Local: &mainpb.Local{ + M: &subpb.M{}, + E: subpb.E_ZERO, + }, + } + _ = &mainpb.M{ + M2: &subpb.M2{}, + } +} diff --git a/protoc-gen-go/testdata/imports/test_import_public.pb.go b/protoc-gen-go/testdata/imports/test_import_public.pb.go deleted file mode 100644 index 3725e05030..0000000000 --- a/protoc-gen-go/testdata/imports/test_import_public.pb.go +++ /dev/null @@ -1,126 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: imports/test_import_public.proto - -package imports // import "github.com/golang/protobuf/protoc-gen-go/testdata/imports" - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import test_a_1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_a_1" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -// M1 from public import imports/test_a_1/m1.proto -type M1 test_a_1.M1 - -func (m *M1) Reset() { (*test_a_1.M1)(m).Reset() } -func (m *M1) String() string { return (*test_a_1.M1)(m).String() } -func (*M1) ProtoMessage() {} -func (m *M1) XXX_Unmarshal(buf []byte) error { return (*test_a_1.M1)(m).XXX_Unmarshal(buf) } -func (m *M1) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return (*test_a_1.M1)(m).XXX_Marshal(b, deterministic) -} -func (m *M1) XXX_Size() int { return (*test_a_1.M1)(m).XXX_Size() } -func (m *M1) XXX_DiscardUnknown() { (*test_a_1.M1)(m).XXX_DiscardUnknown() } - -// M1_1 from public import imports/test_a_1/m1.proto -type M1_1 test_a_1.M1_1 - -func (m *M1_1) Reset() { (*test_a_1.M1_1)(m).Reset() } -func (m *M1_1) String() string { return (*test_a_1.M1_1)(m).String() } -func (*M1_1) ProtoMessage() {} -func (m *M1_1) XXX_Unmarshal(buf []byte) error { return (*test_a_1.M1_1)(m).XXX_Unmarshal(buf) } -func (m *M1_1) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return (*test_a_1.M1_1)(m).XXX_Marshal(b, deterministic) -} -func (m *M1_1) XXX_Size() int { return (*test_a_1.M1_1)(m).XXX_Size() } -func (m *M1_1) XXX_DiscardUnknown() { (*test_a_1.M1_1)(m).XXX_DiscardUnknown() } -func (m *M1_1) GetM1() *M1 { return (*M1)((*test_a_1.M1_1)(m).GetM1()) } - -// E1 from public import imports/test_a_1/m1.proto -type E1 test_a_1.E1 - -var E1_name = test_a_1.E1_name -var E1_value = test_a_1.E1_value - -func (x E1) String() string { return (test_a_1.E1)(x).String() } - -const E1_E1_ZERO = E1(test_a_1.E1_E1_ZERO) - -type Public struct { - M1 *test_a_1.M1 `protobuf:"bytes,1,opt,name=m1" json:"m1,omitempty"` - E1 test_a_1.E1 `protobuf:"varint,2,opt,name=e1,enum=test.a.E1" json:"e1,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Public) Reset() { *m = Public{} } -func (m *Public) String() string { return proto.CompactTextString(m) } -func (*Public) ProtoMessage() {} -func (*Public) Descriptor() ([]byte, []int) { - return fileDescriptor_test_import_public_b5b1d653c96016f3, []int{0} -} -func (m *Public) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Public.Unmarshal(m, b) -} -func (m *Public) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Public.Marshal(b, m, deterministic) -} -func (dst *Public) XXX_Merge(src proto.Message) { - xxx_messageInfo_Public.Merge(dst, src) -} -func (m *Public) XXX_Size() int { - return xxx_messageInfo_Public.Size(m) -} -func (m *Public) XXX_DiscardUnknown() { - xxx_messageInfo_Public.DiscardUnknown(m) -} - -var xxx_messageInfo_Public proto.InternalMessageInfo - -func (m *Public) GetM1() *test_a_1.M1 { - if m != nil { - return m.M1 - } - return nil -} - -func (m *Public) GetE1() test_a_1.E1 { - if m != nil { - return m.E1 - } - return test_a_1.E1_E1_ZERO -} - -func init() { - proto.RegisterType((*Public)(nil), "test.Public") -} - -func init() { - proto.RegisterFile("imports/test_import_public.proto", fileDescriptor_test_import_public_b5b1d653c96016f3) -} - -var fileDescriptor_test_import_public_b5b1d653c96016f3 = []byte{ - // 174 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc8, 0xcc, 0x2d, 0xc8, - 0x2f, 0x2a, 0x29, 0xd6, 0x2f, 0x49, 0x2d, 0x2e, 0x89, 0x87, 0x70, 0xe2, 0x0b, 0x4a, 0x93, 0x72, - 0x32, 0x93, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x58, 0x40, 0x32, 0x52, 0x92, 0x28, 0xea, - 0x12, 0xe3, 0x0d, 0xf5, 0x73, 0x0d, 0x21, 0x0a, 0x94, 0x1c, 0xb8, 0xd8, 0x02, 0xc0, 0x1a, 0x84, - 0xa4, 0xb8, 0x98, 0x72, 0x0d, 0x25, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0xb8, 0xf4, 0x40, 0x2a, - 0xf5, 0x12, 0xf5, 0x7c, 0x0d, 0x83, 0x98, 0x72, 0x0d, 0x41, 0x72, 0xa9, 0x86, 0x12, 0x4c, 0x0a, - 0x8c, 0x1a, 0x7c, 0x08, 0x39, 0x57, 0xc3, 0x20, 0xa6, 0x54, 0x43, 0x27, 0xeb, 0x28, 0xcb, 0xf4, - 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xf4, 0xfc, 0x9c, 0xc4, 0xbc, 0x74, - 0x7d, 0xb0, 0xe1, 0x49, 0xa5, 0x69, 0x10, 0x46, 0xb2, 0x6e, 0x7a, 0x6a, 0x9e, 0x6e, 0x7a, 0x3e, - 0xd8, 0xfe, 0x94, 0xc4, 0x92, 0x44, 0x7d, 0xa8, 0x83, 0x02, 0x18, 0x92, 0xd8, 0xc0, 0x2a, 0x8c, - 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x65, 0x95, 0x6f, 0xe5, 0xcc, 0x00, 0x00, 0x00, -} diff --git a/protoc-gen-go/testdata/main_test.go b/protoc-gen-go/testdata/main_test.go index 87ee1681cd..7ec1f2dbaa 100644 --- a/protoc-gen-go/testdata/main_test.go +++ b/protoc-gen-go/testdata/main_test.go @@ -36,7 +36,6 @@ package testdata import ( "testing" - imppb "github.com/golang/protobuf/protoc-gen-go/testdata/imp" importspb "github.com/golang/protobuf/protoc-gen-go/testdata/imports" multipb "github.com/golang/protobuf/protoc-gen-go/testdata/multi" mytestpb "github.com/golang/protobuf/protoc-gen-go/testdata/my_test" @@ -46,5 +45,4 @@ func TestLink(t *testing.T) { _ = &multipb.Multi1{} _ = &mytestpb.Request{} _ = &importspb.All{} - _ = &imppb.ImportedMessage{} } diff --git a/regenerate.sh b/regenerate.sh index a1976be3db..dc7e2d1f61 100755 --- a/regenerate.sh +++ b/regenerate.sh @@ -9,6 +9,12 @@ mkdir -p $tmpdir/bin PATH=$tmpdir/bin:$PATH GOBIN=$tmpdir/bin go install ./protoc-gen-go +# Public imports require at least Go 1.9. +supportTypeAliases="" +if go list -f '{{context.ReleaseTags}}' runtime | grep -q go1.9; then + supportTypeAliases=1 +fi + # Generate various test protos. PROTO_DIRS=( conformance/internal/conformance_proto @@ -18,6 +24,10 @@ PROTO_DIRS=( ) for dir in ${PROTO_DIRS[@]}; do for p in `find $dir -name "*.proto"`; do + if [[ $p == */import_public/* && ! $supportTypeAliases ]]; then + echo "# $p (skipped)" + continue; + fi echo "# $p" protoc -I$dir --go_out=plugins=grpc,paths=source_relative:$dir $p done