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

[gogenproto] Support for automatic go package mappings #34

Merged
merged 8 commits into from
Jan 24, 2024

Conversation

bhollis
Copy link
Collaborator

@bhollis bhollis commented Jan 24, 2024

Background

→ When using gogenproto it is currently difficult to import protos from other packages, unless those protos specify the full absolute Go package in go_package. I'd rather have this all be implicit in the directory structure.

Changes

  • For each proto include path (inclusive of the input directory), find all possible proto files that could be imported via that path, and generate a mapping via --go_opt=M between that import path and the full Go package path that the file would be imported from. This means users no longer have to specify go_package in their protos at all, and can import protos from other paths via -include without having to do anything special to make the Go import paths work.
  • Remove OutputDir option as it is annoying to work into this solution and it somewhat undermines the simplicity of "generate code next to these protos".

Testing

  • Tested both locally and in the Stately monorepo

@bhollis bhollis requested a review from drshriveer January 24, 2024 20:17
@@ -88,3 +124,18 @@ func (lw logPipe) Write(p []byte) (n int, err error) {
Logger.Println(toLog)
return len(p), nil
}

func PackageNameFromPath(fileName string) (string, error) {
Copy link
Owner

Choose a reason for hiding this comment

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

mind moving this to gogenproto? It seems pretty useful to have there.

@drshriveer drshriveer merged commit cce4c1a into main Jan 24, 2024
3 checks passed
@drshriveer drshriveer deleted the protoc-relative branch January 24, 2024 21:36
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.

2 participants