|
|
@@ -1161,26 +1161,25 @@ func (g *Generator) generateImports() {
|
|
|
continue
|
|
|
}
|
|
|
filename := goFileName(s)
|
|
|
+ // By default, import path is the dirname of the Go filename.
|
|
|
+ importPath := path.Dir(filename)
|
|
|
if substitution, ok := g.ImportMap[s]; ok {
|
|
|
- filename = substitution
|
|
|
- }
|
|
|
- filename = g.ImportPrefix + filename
|
|
|
- if strings.HasSuffix(filename, ".go") {
|
|
|
- filename = filename[0 : len(filename)-3]
|
|
|
+ importPath = substitution
|
|
|
}
|
|
|
+ importPath = g.ImportPrefix + importPath
|
|
|
// Skip weak imports.
|
|
|
if g.weak(int32(i)) {
|
|
|
- g.P("// skipping weak import ", fd.PackageName(), " ", strconv.Quote(filename))
|
|
|
+ g.P("// skipping weak import ", fd.PackageName(), " ", strconv.Quote(importPath))
|
|
|
continue
|
|
|
}
|
|
|
if _, ok := g.usedPackages[fd.PackageName()]; ok {
|
|
|
- g.P("import ", fd.PackageName(), " ", strconv.Quote(filename))
|
|
|
+ g.P("import ", fd.PackageName(), " ", strconv.Quote(importPath))
|
|
|
} else {
|
|
|
// TODO: Re-enable this when we are more feature-complete.
|
|
|
// For instance, some protos use foreign field extensions, which we don't support.
|
|
|
// Until then, this is just annoying spam.
|
|
|
//log.Printf("protoc-gen-go: discarding unused import from %v: %v", *g.file.Name, s)
|
|
|
- g.P("// discarding unused import ", fd.PackageName(), " ", strconv.Quote(filename))
|
|
|
+ g.P("// discarding unused import ", fd.PackageName(), " ", strconv.Quote(importPath))
|
|
|
}
|
|
|
}
|
|
|
g.P()
|