Skip to content

Conversation

Serabe
Copy link
Contributor

@Serabe Serabe commented Jan 10, 2017

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!

@awalterschulze
Copy link
Member

Really cool project.
I am wondering if I understand one of your future ideas correctly.
But is it possible to generate the gogoprotobuf.proto file from the gotypes, like kubernetes has done, but has not exposed as a separate project?
Would it be possible then to translate thrift definitions to proto definitions, by generated the go code from thrift and then generated the proto file from the gotypes?

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?

@awalterschulze
Copy link
Member

To fix the tests you could rather use gogofast_out is possible?

@awalterschulze
Copy link
Member

@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
Copy link
Member

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.
@Serabe Serabe force-pushed the feature/drop_type_declaration branch from 20ebf70 to fed5238 Compare January 18, 2017 08:26
@Serabe
Copy link
Contributor Author

Serabe commented Jan 18, 2017

Fixed and rebased to clean the history

@Serabe
Copy link
Contributor Author

Serabe commented Jan 18, 2017

Travis is not picking up the PR, can you manually start the build? Thank you!

@awalterschulze
Copy link
Member

There are still some gofast_out commands left
They need to be replaced with

protoc-min-version --version="3.0.0" --gogo_out=. ...

or

protoc-min-version --version="3.0.0" --gogofast_out=. ...

@awalterschulze
Copy link
Member

I just restarted the build

@Serabe
Copy link
Contributor Author

Serabe commented Jan 18, 2017

Fixed, thank you!

@Serabe
Copy link
Contributor Author

Serabe commented Jan 18, 2017

Build is passing, let me know if you want me to do a rebase.

Thank you!


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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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) {
Copy link
Member

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

Copy link
Contributor Author

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) {
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If + GoFmt. Check here

@@ -0,0 +1,4 @@
regenerate:
go install github.com/gogo/protobuf/protoc-gen-gogo
go install github.com/gogo/protobuf/protoc-gen-gofast
Copy link
Member

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

return true
}

func (d *Dropped) GetName() string {
Copy link
Member

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";
Copy link
Member

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

@awalterschulze
Copy link
Member

Since everything is working I am going to start becoming a little bit more nit picky.

@Serabe
Copy link
Contributor Author

Serabe commented Jan 18, 2017

Great! I keep things in two different commits to ease the review.

Thank you!

@awalterschulze
Copy link
Member

awalterschulze commented Jan 18, 2017

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.

@Serabe
Copy link
Contributor Author

Serabe commented Jan 18, 2017

I:

  • Renamed thetest.proto to drop.proto and enumdrop.proto. Generated files were removed and regenerated.
  • Remove gofast install instruction from Makefiles.
  • Provided a gist with the patch for protoc-gen-gogo/generator/generator.go.

I'm currently refactoring generator.go so drop options and getters are fully independent.

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
@Serabe
Copy link
Contributor Author

Serabe commented Jan 19, 2017

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
Copy link
Member

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?

Copy link
Contributor Author