-
Notifications
You must be signed in to change notification settings - Fork 810
Drop types declaration option #250
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
Drop types declaration option #250
Conversation
Really cool project. Really cool idea about omitting the generated types. I'll just have to think about this concept a little. Also can't you use the plugins: populate, equal and testgen to generate those tests, that you manually wrote? |
To fix the tests you could rather use gogofast_out is possible? |
@smarterclayton do think this feature will help kubertnetes? |
regenerate: | ||
go install github.com/gogo/protobuf/protoc-gen-gogo | ||
go install github.com/gogo/protobuf/protoc-gen-gofast | ||
protoc --gofast_out=. --proto_path=../../../../../:../../protobuf/:. thetest.proto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. thetest.proto
Add two options, one for messages and one for enums, to drop type declarations. In messages, it also drops getters and setters. In enums, it also drops the generated constants.
20ebf70
to
fed5238
Compare
Fixed and rebased to clean the history |
Travis is not picking up the PR, can you manually start the build? Thank you! |
There are still some gofast_out commands left
or
|
I just restarted the build |
Fixed, thank you! |
Build is passing, let me know if you want me to do a rebase. Thank you! |
gogoproto/helper.go
Outdated
|
||
func HasGoGetters(file *google_protobuf.FileDescriptorProto, message *google_protobuf.DescriptorProto) bool { | ||
return proto.GetBoolExtension(message.Options, E_GoprotoGetters, proto.GetBoolExtension(file.Options, E_GoprotoGettersAll, true)) | ||
return proto.GetBoolExtension(message.Options, E_GoprotoGetters, proto.GetBoolExtension(file.Options, E_GoprotoGettersAll, true)) && !IsDropTypeDeclaration(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
I mean if someone doesn't want gogetters they can turn them off, but otherwise there is a good chance they will still work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is that in protoc-gen-gogo/generator/generator.go
the information needed to create the getters is not worked out unless the struct is created. I can try and refactor that part if you are ok with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think being able to turn the getters on or off will useful.
But its unfortunate that this has to complicate the code.
Please go ahead and refactor this, thank you very much.
g.PrintComments(message.path) | ||
g.P("type ", ccTypeName, " struct {") | ||
g.In() | ||
if !gogoproto.IsDropTypeDeclaration(message.DescriptorProto) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github is really struggling with this diff, I assume you only added this if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If + GoFmt. Check here
|
||
g.P(name, " ", ccTypeName, " = ", e.Number) | ||
g.file.addExport(enum, constOrVarSymbol{name, "const", ccTypeName}) | ||
if !gogoproto.IsEnumDropTypeDeclaration(enum.EnumDescriptorProto) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github is really struggling with this diff, I assume you only added this if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If + GoFmt. Check here
test/drop_type_declaration/Makefile
Outdated
@@ -0,0 +1,4 @@ | |||
regenerate: | |||
go install github.com/gogo/protobuf/protoc-gen-gogo | |||
go install github.com/gogo/protobuf/protoc-gen-gofast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to install gofast anymore
test/drop_type_declaration/models.go
Outdated
return true | ||
} | ||
|
||
func (d *Dropped) GetName() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated getters would probably be fine here
@@ -0,0 +1,27 @@ | |||
syntax = "proto3"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we call this file something else and not thetest.proto as well?
How about drop.proto
Since everything is working I am going to start becoming a little bit more nit picky. |
Great! I keep things in two different commits to ease the review. Thank you! |
I am looking at everything everytime, so don't worry about the professionalism of the commits too much. As long as the end result looks good I'm happy. |
I:
I'm currently refactoring Thank you! |
This commit extract a few variable initializations that was being done at the same time of generating the type for a given message. This allow for the Go Getters option to be independent from the drop type declaration one
I've exrtracted some variable declaration out of the part of the code that generated the type definition for a given message. I think I have extracted the minimal amount of code needed for go getters to be independent from drop type declaration. I think this completes your first review. Thank you! |
} | ||
|
||
for i, field := range message.Field { | ||
// Allocate the getter and the field at the same time so name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this comment deleted?
At src-d, we are using our Go code as source of truth for the rest of the platform. For this, we started writing proteus, a tool that creates proto files from our Go source.
Due to this, we needed to remove type declarations coming from both protobuf messages and enums. These options seem useful for other people and projects (like kubernetes/gengo), so we are opening this PR in case you find this feature helpful.
Thank you!