Skip to content
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

[proto] Add extra_outputs to go_proto_compile #3631

Closed

Conversation

tingilee
Copy link
Contributor

What type of PR is this?

Feature

What does this PR do? Why is it needed?

Which issues(s) does this PR fix?

Fixes #3630

Other notes for review

Copy link
Member

@fmeum fmeum left a comment

Choose a reason for hiding this comment

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

Tests in tests/core/go_proto_library would be highly appreciated. There are already a number of tests there that you can use as a reference, let me know if you need further support.

@@ -55,13 +55,14 @@ to structs produced by other compilers will set this to False.""",
},
)

def go_proto_compile(go, compiler, protos, imports, importpath):
def go_proto_compile(go, compiler, protos, extra_outputs, imports, importpath):
Copy link
Member

Choose a reason for hiding this comment

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

Adding this as a positional argument is a breaking change. Could you make it an optional keyword argument instead, e.g. like this:

Suggested change
def go_proto_compile(go, compiler, protos, extra_outputs, imports, importpath):
def go_proto_compile(go, compiler, protos, imports, importpath, *, extra_outputs = {}):

Comment on lines +77 to +78
for _, v in extra_outputs.items():
if not v.endswith("pb.go"):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for _, v in extra_outputs.items():
if not v.endswith("pb.go"):
if any([not v.endswith(".pb.go") for v in extra_outputs.values()]):

Checking for .pb.go seems more appropriate than pb.go, also .values() directly gives you the right list.

"""Invokes protoc to generate Go sources for a given set of protos

Args:
go: the go object, returned by go_context.
compiler: a GoProtoCompiler provider.
protos: list of ProtoInfo providers for protos to compile.
extra_outputs: dict of additional output files to be compiled.
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a description of what the keys and values are in this dict?

file_name_without_suffix = v[:-len(".pb.go")]
out = go.declare_file(
go,
path = importpath + "/" + file_name_without_suffix,
Copy link
Member

Choose a reason for hiding this comment

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

Is it clear that this is always the correct importpath or would we have to provide a way for users to override this?

@@ -93,6 +98,17 @@ def go_proto_compile(go, compiler, protos, imports, importpath):
ext = compiler.internal.suffix,
)
go_srcs.append(out)

if extra_outputs.get(src.basename):
Copy link
Member

Choose a reason for hiding this comment

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

You can assign this to a variable so that you don't need to get it again in the next line.

@@ -165,6 +166,9 @@ go_proto_library = rule(
providers = [GoLibrary],
aspects = [_go_proto_aspect],
),
"extra_outputs": attr.string_dict(
doc = "Extra output files to be included in the expected generated output",
Copy link
Member

Choose a reason for hiding this comment

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

Same as for the other doc, please explain the role of keys and values.

@tingilee
Copy link
Contributor Author

Abandoning this in favor of #3650

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow extra_outputs on go_proto_compile
2 participants