Skip to content

Commit

Permalink
Merge pull request #341 from meling/master
Browse files Browse the repository at this point in the history
Fix to avoid printing import aliases when not needed
  • Loading branch information
awalterschulze authored Nov 9, 2017
2 parents 3813b83 + ff2773e commit 616a82e
Show file tree
Hide file tree
Showing 134 changed files with 19,999 additions and 18,899 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ regenerate:
make -C test/issue42order regenerate
make -C proto generate-test-pbs
make -C test/importdedup regenerate
make -C test/importduplicate regenerate
make -C test/custombytesnonstruct regenerate
make -C test/required regenerate
make -C test/casttype regenerate
Expand Down
7 changes: 3 additions & 4 deletions protoc-gen-gogo/descriptor/descriptor_gostring.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions protoc-gen-gogo/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,12 @@ var pkgNamesInUse = make(map[string][]*FileDescriptor)
// Pkg is the candidate name. If f is nil, it's a builtin package like "proto" and
// has no file descriptor.
func RegisterUniquePackageName(pkg string, f *FileDescriptor) string {
if f == nil {
// For builtin and standard lib packages, try to use only
// the last component of the package path.
pkg = pkg[strings.LastIndex(pkg, "/")+1:]
}

// Convert dots to underscores before finding a unique alias.
pkg = strings.Map(badToUnderscore, pkg)

Expand Down
11 changes: 5 additions & 6 deletions protoc-gen-gogo/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ package grpc

import (
"fmt"
"path"
"strconv"
"strings"

Expand Down Expand Up @@ -129,11 +128,11 @@ func (g *grpc) GenerateImports(file *generator.FileDescriptor) {
if len(file.FileDescriptorProto.Service) == 0 {
return
}
g.P("import (")
g.P(contextPkg, " ", strconv.Quote(path.Join(g.gen.ImportPrefix, contextPkgPath)))
g.P(grpcPkg, " ", strconv.Quote(path.Join(g.gen.ImportPrefix, grpcPkgPath)))
g.P(")")
g.P()
imports := generator.NewPluginImports(g.gen)
for _, i := range []string{contextPkgPath, grpcPkgPath} {
imports.NewImport(i).Use()
}
imports.GenerateImports(file)
}

// reservedClientName records whether a client name is reserved on the client side.
Expand Down
49 changes: 24 additions & 25 deletions test/asymetric-issue125/asympb_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 616a82e

Please sign in to comment.