Skip to content

Commit

Permalink
fix for issue 209: dont import types when its not used
Browse files Browse the repository at this point in the history
  • Loading branch information
awalterschulze committed Oct 5, 2016
1 parent fdc14ac commit 45378b5
Show file tree
Hide file tree
Showing 6 changed files with 2,100 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ regenerate:
make -C test/nopackage regenerate
make -C test/types regenerate
make -C test/proto3extension regenerate
make -C test/stdtypes regenerate
make gofmt

tests:
Expand Down
12 changes: 9 additions & 3 deletions protoc-gen-gogo/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,9 @@ func (g *Generator) GoMapType(d *Descriptor, field *descriptor.FieldDescriptorPr
if !gogoproto.IsNullable(m.ValueAliasField) {
valType = strings.TrimPrefix(valType, "*")
}
g.RecordTypeUse(m.ValueAliasField.GetTypeName())
if !gogoproto.IsStdTime(field) && !gogoproto.IsStdDuration(field) {
g.RecordTypeUse(m.ValueAliasField.GetTypeName())
}
default:
if gogoproto.IsCustomType(m.ValueAliasField) {
if !gogoproto.IsNullable(m.ValueAliasField) {
Expand Down Expand Up @@ -2174,7 +2176,9 @@ func (g *Generator) generateMessage(message *Descriptor) {

g.PrintComments(fmt.Sprintf("%s,%d,%d", message.path, messageFieldPath, i))
g.P(fieldName, "\t", typename, "\t`", tag, "`")
g.RecordTypeUse(field.GetTypeName())
if !gogoproto.IsStdTime(field) && !gogoproto.IsStdDuration(field) {
g.RecordTypeUse(field.GetTypeName())
}
}
if len(message.ExtensionRange) > 0 {
if gogoproto.HasExtensionsMap(g.file.FileDescriptorProto, message.DescriptorProto) {
Expand Down Expand Up @@ -2403,7 +2407,9 @@ func (g *Generator) generateMessage(message *Descriptor) {
_, wiretype := g.GoType(message, field)
tag := "protobuf:" + g.goTag(message, field, wiretype)
g.P("type ", oneofTypeName[field], " struct{ ", fieldNames[field], " ", fieldTypes[field], " `", tag, "` }")
g.RecordTypeUse(field.GetTypeName())
if !gogoproto.IsStdTime(field) && !gogoproto.IsStdDuration(field) {
g.RecordTypeUse(field.GetTypeName())
}
}
g.P()
for _, field := range message.Field {
Expand Down
37 changes: 37 additions & 0 deletions test/stdtypes/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Protocol Buffers for Go with Gadgets
#
# Copyright (c) 2016, The GoGo Authors. All rights reserved.
# http://github.com/gogo/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.
#
# 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.

regenerate:
go install github.com/gogo/protobuf/protoc-min-version
go install github.com/gogo/protobuf/protoc-gen-gogo
protoc-min-version --version="3.0.0" --gogo_out=\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types\
:. \
--proto_path=../../../../../:../../protobuf/:. stdtypes.proto

Loading

0 comments on commit 45378b5

Please sign in to comment.