-
-
Notifications
You must be signed in to change notification settings - Fork 283
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
Should use declared package name #8
Comments
I am concerned about supporting two output modes (and duplicating the tests, and edge cases that this can create), and my preference here would be to stay close to the naming conventions made by the official Java protocol buffer generator. The official Java protocol buffer generator does a similar thing: it wraps the classes generated from each proto file inside a public static class with a name that is derived from the proto file name. So although your messages are technically inside the declared Java package, their fully qualified class name contains the proto file name. I am not completely sure why this is done this way in the Java generator, perhaps for being able to have messages with the same name in two proto files and in the same Java package (which is not necessarily a good thing, but some projects are probably already be in this situation). In ScalaPB, I wanted to avoid the outer class approach since it will force us to have one big Scala class for each protocol buffer. Breaking it to smaller files in sub-packages allows the namespace to look similar to Java, but also enjoy better support for incremental compilation in SBT. It is possible to implement it if really needed, let me know if there's a bug here that makes it hard/impossible to use ScalaPB in certain situations, or it's more of a stylistic preference. |
It has more to do with how The protobuf syntax has package declaration that serves 2 purposes: namespace within They support overriding the package name for Java (through The outer class in Java is required because extensions generate simple values that can't live at top-level in Java. Based on this, I would expect ScalaPB to behave similarly, which is to say that the package declaration within the proto files is respected (either through the ScalaPB can still generate classes in their own file within that package (to get incremental compile goodness). Problems would only happen if someone has created a name collision in 2 separate My situation is that I'd like to move from ScalaBuff to ScalaPB, but it requires that I import One way to support this without breaking the whole ScalaPB world would be to declare an |
Oh - I didn't consider file-level custom options for this (I thought only of setting this through compiler plugin parameters). In this case, overriding the default settings would require the user to add an import for a "scalapb.proto" and adding something that looks like this in all their protos:
Is this something that will be acceptable for your use case? Then maybe the protoc plugin can have a setting to override the settings for projects who do not want to add the custom option to every file. |
Yes, that's what I had in mind. I think ScalaPB could expose several other options to control how it generates Scala case classes as well. So I'd be for using |
Cool! I'll give this a try. Thanks for considering and implementing this! |
You're welcome. This feature has been shipped in v0.4.2 |
For projects that don't care about the Java bindings, it should be possible to get ScalaPB to use the declared package instead of generating a different one.
The text was updated successfully, but these errors were encountered: