-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing "--go_opt=M<src>:<go_pkg>" does not mute "WARNING: Missing 'go_package' option..." #1158
Comments
go_package
in a future release!go_package
to be specified as a --go_opt
.
I recommend giving @neild's comment here a read: #1151 (comment), it's not directly related to your question, but sheds light on the technical complexities involved. Fundamentally,
This is an interesting idea, but a challenge is that |
BTW, the title changed since I started writing my response. The current title of "Allow
|
Yep! I currently use the
message regardless of whether there's an |
go_package
to be specified as a --go_opt
.--go_opt=M...
should remove WARNING: Missing 'go_package' option...
--go_opt=M...
should remove WARNING: Missing 'go_package' option...
The "M" options are here to stay (they are not going away). If properly used, they will suppress the warning you are seeing. The problem at hand is a mismatch between what's specified in your M flag, and what's being processed. Notice, that the M flag is specified with "src/foo/foo.proto", while the warning is complaining about "foo/foo.proto"? In other words, |
Okay I've tried to edit the original post for clarity BTW. Anyway, it looks like the proto source path passed to So that leave me with two thoughts:
|
I also think that for In fact, why is the existing import_prefix option deprecated? I see |
The natural behavior should the user want to specify a module but also leverage source_relative paths output is to consider the module to be the prefix for all import paths written to the generated go code. In a `module example.com/proto/gen`, it's possible to do: $ tree go.mod go.sum src + types + foo.proto + bar.proto + widget + service.proto gen $ protoc $(find src -name "*.proto") --proto_path=src --go_out=gen --go_opt=paths=source_relative,module=example.com/types/gen without specifying the example.com/proto/gen/... module prefix in the acutal proto files. In order to do this with the `M` option, you would have to build the package list manually and pass a dedicated `M` option for each source proto. This gets rather cumbersome. How is this different than the deprecated import_path option? The use case solved here is very specific to a common pattern of generating Go sources from a shared set of proto files into a single root module path while still retaining the source directory/package structure. This use case is simple enough and useful enough that it makes sense to support it specifically without reverting to trying to support a fully generalized import_path type of option that likely caused more confusion than desired. It also makes sense of a previously incompatible option set which is an aesthetically welcome reduciton in error output. Related discussion: golang/protobuf#1158
The natural behavior should the user want to specify a module but also leverage source_relative paths output is to consider the module to be the prefix for all import paths written to the generated go code. In a `module example.com/proto/gen`, it's possible to do: $ tree go.mod go.sum src + types + foo.proto + bar.proto + widget + service.proto gen $ protoc $(find src -name "*.proto") --proto_path=src --go_out=gen --go_opt=paths=source_relative,module=example.com/types/gen without specifying the example.com/proto/gen/... module prefix in the acutal proto files. In order to do this with the `M` option, you would have to build the package list manually and pass a dedicated `M` option for each source proto. This gets rather cumbersome. How is this different than the deprecated import_path option? The use case solved here is very specific to a common pattern of generating Go sources from a shared set of proto files into a single root module path while still retaining the source directory/package structure. This use case is simple enough and useful enough that it makes sense to support it specifically without reverting to trying to support a fully generalized import_path type of option that likely caused more confusion than desired. It also makes sense of a previously incompatible option set which is an aesthetically welcome reduciton in error output. Related discussion: golang/protobuf#1158
The natural behavior should the user want to specify a module but also leverage source_relative paths output is to consider the module to be the prefix for all import paths written to the generated go code. In a `module example.com/proto/gen`, it's possible to do: $ tree go.mod go.sum src + types + foo.proto + bar.proto + widget + service.proto gen $ protoc $(find src -name "*.proto") --proto_path=src --go_out=gen --go_opt=paths=source_relative,module=example.com/types/gen $ tree gen gen + types + foo.pb.go + bar.pb.go + widget + service.pb.go without specifying the example.com/proto/gen/... module prefix in the acutal proto files. In order to do this with the `M` option, you would have to build the package list manually and pass a dedicated `M` option for each source proto. This gets rather cumbersome. How is this different than the deprecated import_path option? The use case solved here is very specific to a common pattern of generating Go sources from a shared set of proto files into a single root module path while still retaining the source directory/package structure. This use case is simple enough and useful enough that it makes sense to support it specifically without reverting to trying to support a fully generalized import_path type of option that likely caused more confusion than desired. It also makes sense of a previously incompatible option set which is an aesthetically welcome reduciton in error output. Related discussion: golang/protobuf#1158
The natural behavior should the user want to specify a module but also leverage source_relative paths output is to consider the module to be the prefix for all import paths written to the generated go code. In a `module example.com/proto/gen`, it's possible to do: $ tree go.mod go.sum src + types + foo.proto + bar.proto + widget + service.proto gen $ protoc $(find src -name "*.proto") --proto_path=src --go_out=gen --go_opt=paths=source_relative,module=example.com/proto/gen $ tree gen gen + types + foo.pb.go + bar.pb.go + widget + service.pb.go without specifying the example.com/proto/gen/... module prefix in the acutal proto files. In order to do this with the `M` option, you would have to build the package list manually and pass a dedicated `M` option for each source proto. This gets rather cumbersome. How is this different than the deprecated import_path option? The use case solved here is very specific to a common pattern of generating Go sources from a shared set of proto files into a single root module path while still retaining the source directory/package structure. This use case is simple enough and useful enough that it makes sense to support it specifically without reverting to trying to support a fully generalized import_path type of option that likely caused more confusion than desired. It also makes sense of a previously incompatible option set which is an aesthetically welcome reduciton in error output. Related discussion: golang/protobuf#1158
The natural behavior should the user want to specify a module but also leverage source_relative paths output is to consider the module to be the prefix for all import paths written to the generated go code. In a `module example.com/proto/gen`, it's possible to do: $ tree go.mod go.sum src + types + foo.proto + bar.proto + widget + service.proto gen $ protoc $(find src -name "*.proto") --proto_path=src --go_out=gen --go_opt=paths=source_relative,module=example.com/proto/gen $ tree gen gen + types + foo.pb.go + bar.pb.go + widget + service.pb.go without specifying the `"example.com/proto/gen/..."` module prefix in the acutal proto files. In order to do this with the `M` option, you would have to build the package list manually and pass a dedicated `M` option for each source proto. This gets rather cumbersome. How is this different than the deprecated import_path option? The use case solved here is very specific to a common pattern of generating Go sources from a shared set of proto files into a single root module path while still retaining the source directory/package structure. This use case is simple enough and useful enough that it makes sense to support it specifically without reverting to trying to support a fully generalized import_path type of option that likely caused more confusion than desired. It also makes sense of a previously incompatible option set which is an aesthetically welcome reduciton in error output. Related discussion: golang/protobuf#1158
The natural behavior should the user want to specify a module but also leverage source_relative paths output is to consider the module to be the prefix for all import paths written to the generated go code. In a `module example.com/proto/gen`, it's possible to do: $ tree go.mod go.sum src + types + foo.proto + bar.proto + widget + service.proto gen $ protoc $(find src -name "*.proto") --proto_path=src --go_out=gen --go_opt=paths=source_relative,module=example.com/proto/gen $ tree gen gen + types + foo.pb.go + bar.pb.go + widget + service.pb.go without specifying the `"example.com/proto/gen/..."` module prefix in the acutal proto files. In order to do this with the `M` option, you would have to build the package list manually and pass a dedicated `M` option for each source proto. This gets rather cumbersome. How is this different than the deprecated import_path option? The use case solved here is very specific to a common pattern of generating Go sources from a shared set of proto files into a single root module path while still retaining the source directory/package structure. This use case is simple enough and useful enough that it makes sense to support it specifically without reverting to trying to support a fully generalized import_path type of option that likely caused more confusion than desired. It also makes sense of a previously incompatible option set which is an aesthetically welcome reduciton in error output. Related discussion: golang/protobuf#1158
I took a stab at making it happen: https://go-review.googlesource.com/c/protobuf/+/240238. Regardless of whether you ultimately want to allow this or not, hopefully it spurs further discussion (: |
I seriously thought we had these documented somewhere, but I can't seem to find them. I filed #1161 to address this.
Thanks for implementing your proposed flags. There seems to be overlap between with your proposed changes at that of #992. Are you okay with closing this issue and continuing discussion over there? I think there's improvement that can be made for cases where the |
Closing this as we can continue any discussion on #992. There's improvement for users who do not use the |
edit for clarity
I'm confused about the intended remediation for:
I've been generating protobufs by specifying the go package on the command line when compiling the protobufs using the
M
option (like--go_out=M<src.proto>:<go_package>,out
. This is advantageous for many reasons some of which are highlighted below. However, when upgrading my tooling recently and moving over to the new packages, I've started seeing the warning above. Looking around, I no longer see theM
option referenced in the README. And a little bit of digging around the issue tracker uncovers comments like below.original prose
From #791:
While it may be generally true that some prefix is required, why must
go_package
be specified in the protobuf source file, and not manually (or automatically by reading the go.mod) when the ultimate source is generated?I can understand how it might get a little hairy for public packages if someone were to include a package that also included its own generation of types off the same set of proto files (so you'd end up with duplicate types derived from identical proto sources), but this is hardly the common and only use case for protobufs, no?
For example: we find it very handy to be able to generate protobufs in a package of our choosing on the server so we can decorate the types such that they support interfaces required to double as database models whilst generating them more simply on the client in their own way. With a fixed go_package, the client would need to import the server (and all of its transitive dependencies and whatnot) to be able to use the generated code.
Forcing a go_package option to live in the proto source file generally prevents compile-time code generation and thus prevents builds from being structured in a way that treats generated source files as build artifacts. Java's gradle protobuf plugin does exactly this, and everything seems to work just fine for that implementation. Why must go projects depend on checked-in code-gen?
It also strikes me as a little backwards that a source proto file should ever even lay rightful claim to being required let alone able able to assert anything about the ultimate generated source packaging structure. The only invariant that need be maintained, as #791 points out, is that the golang proto compiler plugin knows how to generate source such that the go compiler can make sense of import paths. Why does it matter if two packages want to generate the source files in slightly different packages or using different build strategies if, at the end of the day, the types and service definitions remain compatible?
I totally understand the need to require a go_package option to be specified, even manually, at some point. I don't understand why it has to live in the source proto file.
summary
Maybe I'm just swept up in the whole transition and have a few signals crossed? But it would be really nice to know what the intended end state looks like for projects using the protobuf-go tooling.
The text was updated successfully, but these errors were encountered: