grpckit / omniproto

Omniproto makes generating code from your protorepo easy
MIT License
9 stars 4 forks source link

Adding support for --plugin_opt to make larger builds more manageable #16

Closed coxley closed 1 year ago

coxley commented 1 year ago

Summary

Many plugins — protoc-gen-go included — allow you to pass options via an option flag. For go, this looks like --go_opt. (reference doc)

They can be specified many times. Breaking this out of --go_out is especially useful when overwriting one module, not to mention doing it ten times.

plugins:
  - name: go
    args: paths=source_relative,Mpath/to/proto=github.com/foo/bar/gen/org/path/to/proto,Mpath/to/other/proto=github.com/foo/bar/gen/org/path/to/other/proto

# vs

plugins:
  - name: go
    opts:
      - paths=source_relative
      - Mpath/to/proto=github.com/foo/bar/gen/org/path/to/proto
      - Mpath/to/other/proto=github.com/foo/bar/gen/org/path/to/other/proto

The module rewriting is still a pain but much easier to manage than before. Until we migrate to buf, I have to edit many configs like this. Each can have 5-10 protos, and at least two plugins.

Test Plan

The existing test case was broken, so I fixed and adjusted to work with this change. Tested in a codebase of my own to verify it works with variety of plugins supporting only --plugin_out in conjunction with modern ones.

➜ go test ./...
ok      github.com/grpckit/omniproto    (cached)