Hello,
When I protoc a proto with multiple proto in the same package, the generated file import its own package. E.g.,
package ranking2
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "ranking2"
import ranking22 "ranking2"
import ranking23 "ranking2"
import ranking24 "ranking2"
import ranking25 "ranking2"
import ranking26 "ranking2"
https://github.com/golang/protobuf/blob/master/protoc-gen-go/generator/generator.go#L1328 seems to be for preventing this.
Is this a bug? Or how can I avoid this?
I found that this happens when I import other proto which defines MessageOptions.
Please provide more steps to reproduce this issue. (Actual .proto files and the commands used to build them would be ideal.)
Sure.
Here it is: https://github.com/jhahn21/test
Output is: https://github.com/jhahn21/test/blob/master/aa/a.pb.go
Ok. I think you're invoking it wrong?
You need to pass all of the .proto files for a given package to protoc at once:
protoc --go_out=. -I . aa/*.proto
not
protoc --go_out=. -I . aa/a.proto
If you do them one at a time, the protocol compiler assumes it's generating a separate package for each file. (Not every build system for Go uses the same layout as the standard go tool, so protoc can't just assume that all of the files in a directory are intended to be in the same package.)
We use goprotowrap to automatically call protoc with one Go-package of files at a time.