Skip to content

Commit

Permalink
protoc-gen-go: revert some API changes (#577)
Browse files Browse the repository at this point in the history
Introducing the GoImportPath and GoPackageName types to distingish between
these values changed the exported API of the generator package in a few
small ways. While the API of this package comes with no stability
guarantee, the benefit to the exported part of the change is small.
Revert the exported changes to avoid gratuitous breakage.

Specific changes:
  Generator.ImportPrefix reverts to type string
  Generator.ImportMap reverts to type map[string]string

(There are other externally-visible changes to the package API which
are worth making and will not be reverted, most notably the removal of the
PackageName method from FileDescriptor.)
  • Loading branch information
neild authored Mar 30, 2018
1 parent 91cccdb commit 06c268a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions protoc-gen-go/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,10 @@ type Generator struct {
Request *plugin.CodeGeneratorRequest // The input.
Response *plugin.CodeGeneratorResponse // The output.

Param map[string]string // Command-line parameters.
PackageImportPath string // Go import path of the package we're generating code for
ImportPrefix GoImportPath // String to prefix to imported package file names.
ImportMap map[string]GoImportPath // Mapping from .proto file name to import path
Param map[string]string // Command-line parameters.
PackageImportPath string // Go import path of the package we're generating code for
ImportPrefix string // String to prefix to imported package file names.
ImportMap map[string]string // Mapping from .proto file name to import path

Pkg map[string]string // The names under which we import support packages

Expand Down Expand Up @@ -629,12 +629,12 @@ func (g *Generator) CommandLineParameters(parameter string) {
}
}

g.ImportMap = make(map[string]GoImportPath)
g.ImportMap = make(map[string]string)
pluginList := "none" // Default list of plugin names to enable (empty means all).
for k, v := range g.Param {
switch k {
case "import_prefix":
g.ImportPrefix = GoImportPath(v)
g.ImportPrefix = v
case "import_path":
g.PackageImportPath = v
case "paths":
Expand All @@ -654,7 +654,7 @@ func (g *Generator) CommandLineParameters(parameter string) {
}
default:
if len(k) > 0 && k[0] == 'M' {
g.ImportMap[k[1:]] = GoImportPath(v)
g.ImportMap[k[1:]] = v
}
}
}
Expand Down Expand Up @@ -807,7 +807,7 @@ func (g *Generator) WrapTypes() {
proto3: fileIsProto3(f),
}
if substitution, ok := g.ImportMap[f.GetName()]; ok {
fd.importPath = substitution
fd.importPath = GoImportPath(substitution)
} else if p, _, _ := fd.goPackageOption(); p != "" {
fd.importPath = p
} else {
Expand Down Expand Up @@ -1340,7 +1340,7 @@ func (g *Generator) generateHeader() {
if importPath == "" {
g.P("package ", name)
} else {
g.P("package ", name, " // import ", g.ImportPrefix+importPath)
g.P("package ", name, " // import ", GoImportPath(g.ImportPrefix)+importPath)
}
g.P()

Expand Down Expand Up @@ -1400,7 +1400,7 @@ func (g *Generator) generateImports() {
// We almost always need a proto import. Rather than computing when we
// do, which is tricky when there's a plugin, just import it and
// reference it later. The same argument applies to the fmt and math packages.
g.P("import "+g.Pkg["proto"]+" ", g.ImportPrefix+"github.com/golang/protobuf/proto")
g.P("import "+g.Pkg["proto"]+" ", GoImportPath(g.ImportPrefix)+"github.com/golang/protobuf/proto")
g.P("import " + g.Pkg["fmt"] + ` "fmt"`)
g.P("import " + g.Pkg["math"] + ` "math"`)
var (
Expand All @@ -1427,7 +1427,7 @@ func (g *Generator) generateImports() {
for i := range importPaths {
importPath := GoImportPath(importPaths[i])
packageName := g.GoPackageName(importPath)
fullPath := g.ImportPrefix + importPath
fullPath := GoImportPath(g.ImportPrefix) + importPath
// Skip weak imports.
if !strongImports[importPath] {
g.P("// skipping weak import ", packageName, " ", fullPath)
Expand Down

0 comments on commit 06c268a

Please sign in to comment.