protoc-gen-validate
protoc-gen-validate copied to clipboard
Running under Bazel creates colliding imports
I have a protobuf library with many types like:
path/to/type/v1 path/to/type/v2 path/to/another_type/v1
These have non-conflicting importpaths in go, and we're using go_package options to give them unique package names as well, i.e. github.com/gauntletwizard/foo/proto/path/to/type/v1;type github.com/gauntletwizard/foo/proto/path/to/another_type/v1;another_type
Generation of the proto libraries works fine from our Makefile which simply references everything with --proto_path=./proto. However, when using the bazel proto, we get issues with conflicting import names - Both packages are imported as v1:
import (
...
v1 "github.com/gauntletwizard/foo/proto/path/to/type/v1"
v1 "github.com/gauntletwizard/foo/proto/path/to/another_type/v1"
)
This stems from the way that bazel passes in imports; Rather than importing one directory containing all source .proto files, bazel passes each .proto in an import statement:
-import 'protobuf/path/to/type/v1/types.proto=github.com/gauntletwizard/foo/path/to/type/v1'
This causes the package's path to be overridden: https://github.com/lyft/protoc-gen-star/blob/master/lang/go/package.go#L57
Preferably, packages would be disambiguated before generating code, with colliding packages using more of their path (or hashes of their full path, or whatever). My short term fix was simply to disable that code, and it might be a quick-fix to add a compilation option to disable it as well.
Thanks for the report!
Appears that the disambiguation needs to happen here. We're handling the deduplication, but need to work out how to get the package name aliases to be treated uniquely (and properly propagated to where they're used).