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

Add same_package option to protoc-gen-connect-go #803

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

bufdev
Copy link
Member

@bufdev bufdev commented Dec 18, 2024

This adds an option same_package to protoc-gen-connect-go. If specified, the connect-go types will be generated to the same package as the base types.

Per #310 (reply in thread), I'm not 100% confident in this design - I'd be open to other naming patterns for this option, including making it "enum style".

@bufdev bufdev requested review from jhump and emcfarlane December 18, 2024 21:11
Copy link
Member

@jhump jhump left a comment

Choose a reason for hiding this comment

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

I'd be open to other naming patterns for this option, including making it "enum style".

I'm not sure an enum makes sense. But maybe a "suffix" string that defaults to "connect" -- then allows users to customize the location (like in case a "connect" sub-package were somehow a conflict) and then setting it to empty string would put it in the same package.

But, TBH, I think the simple bool is actually fine.

}
generatedFile := plugin.NewGeneratedFile(
file.GeneratedFilenamePrefix+generatedFilenameExtension,
goImportPath,
)
generatedFile.Import(file.GoImportPath)
Copy link
Member

Choose a reason for hiding this comment

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

Don't we only want to do this when !samePackage?

I think we need to come up with a testing strategy. I need to look at the repo a little more to see how existing tests work. Hopefully there's an easy way to plugin a test for this new option.

Copy link
Contributor

@emcfarlane emcfarlane Dec 19, 2024

Choose a reason for hiding this comment

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

Put up a testing strategy that runs the protoc-gen-connect-go binary by re-compiling the main.go file. Wanted to bounce this off before extending. Currently it will assert that the expected files in the output but not the contents. We could add a testdata/ directory of .pb.go files to check contents match if we wanted better testing of contents.

Copy link
Member

Choose a reason for hiding this comment

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

We definitely need to test contents, though I don't think "golden files" are sufficient since they are verified by human eyes. We actually need to compile them to make sure we are generating valid code: this option changes references, packages, and imports, which is a high risk of a compiler error if not done correctly.

To get as much coverage as possible with this option, we may even want to generate all test files that we're currently using to test protoc-gen-connect-go, to a different package with this option and make sure it all compiles.

Copy link
Contributor

Choose a reason for hiding this comment

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

Updated the testdata directory to a set of module proto files which is generated as part of make generate. I found having the golden files output in testdata nice to be able to browse the output. The test code imports these, which asserts that it is compilable and valid code, and then uses it for comparisons when running the different options.

@bufdev bufdev mentioned this pull request Dec 19, 2024
emcfarlane pushed a commit that referenced this pull request Dec 20, 2024
This is the alternative option `package_suffix` re:
#803 (review).
I'm not sure which one I like more - I don't like the name
`same_package` that much, and this gives more flexibility, but I don't
know if we want to offer that flexibility. Looking for opinions.

Regardless of if we choose this or #803 as-is, we should make sure the
README.md documents the option.

Signed-off-by: bufdev <[email protected]>
This is the alternative option `package_suffix` re:
#803 (review).
I'm not sure which one I like more - I don't like the name
`same_package` that much, and this gives more flexibility, but I don't
know if we want to offer that flexibility. Looking for opinions.

Regardless of if we choose this or #803 as-is, we should make sure the
README.md documents the option.

Signed-off-by: bufdev <[email protected]>
Signed-off-by: Edward McFarlane <[email protected]>
Signed-off-by: Edward McFarlane <[email protected]>
Signed-off-by: Edward McFarlane <[email protected]>
Signed-off-by: Edward McFarlane <[email protected]>
@emcfarlane emcfarlane requested a review from jhump December 23, 2024 20:53
Signed-off-by: Edward McFarlane <[email protected]>
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.

3 participants