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

build: move .pb.go contents munging from make to protoc-gen-gogoroach #57913

Merged
merged 1 commit into from
Dec 15, 2020

Conversation

rickystewart
Copy link
Collaborator

This worked fine, but it complicated #56067 because the standard Go
protobuf Bazel support

doesn't easily allow us to just inject a random sed command into the
middle of the (.proto -> .pb.go -> compiled Go library) pipeline.

With this logic in the actual protoc plugin proper, we can then safely
use Bazel's built-in stuff without a lot of monkey-patching or code
duplication.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

continue
}

line = strings.Replace(line, "github.com/cockroachdb/cockroach/pkg/etcd", "go.etcd.io/etcd", 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be strings.ReplaceAll instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doesn't really matter since there's only ever one occurrence in each line, so sure.


line = strings.Replace(line, "github.com/cockroachdb/cockroach/pkg/etcd", "go.etcd.io/etcd", 1)
line = strings.Replace(line, "github.com/cockroachdb/cockroach/pkg/errorspb", "github.com/cockroachdb/errors/errorspb", 1)
// TODO(benesch): Remove these after https://github.com/grpc/grpc-go/issues/711.
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the parent issue is now closed, does this still apply?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The replacement is still necessary (introduces bad diffs if I leave it out). I removed the comment.

)

var builtinRegex *regexp.Regexp = regexp.MustCompile("github.com/cockroachdb/cockroach/pkg/(?P<capture>(bytes|context|encoding/binary|errors|fmt|io|math|github\\.com|(google\\.)?golang\\.org)([^a-z]|$$))")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really sure with what was happening originally, but assuming you've cracked it, a comment would be helpful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't fully understand exactly how this works, but I added a comment explaining what I DO know. :)

@@ -14,8 +14,35 @@ import (
"github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
"github.com/gogo/protobuf/vanity"
"github.com/gogo/protobuf/vanity/command"
"regexp"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want these stdlib imports to go above the others.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

gofmt moves the imports back into alphabetical order if I make this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Our linter will fail (I think what you want is to introduce a newline between the two blocks).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the tip about the newline -- I just figured that out myself the hard way :)

…roach`

This worked fine, but it complicated cockroachdb#56067 because [the standard Go
protobuf Bazel support](https://github.com/bazelbuild/rules_go/blob/master/proto/core.rst#go_proto_library)
doesn't easily allow us to just inject a random `sed` command into the
middle of the (`.proto` -> `.pb.go` -> compiled Go library) pipeline.

With this logic in the actual `protoc` plugin proper, we can then safely
use Bazel's built-in stuff without a lot of monkey-patching or code
duplication.

Release note: None
@rickystewart
Copy link
Collaborator Author

bors r+

@craig
Copy link
Contributor

craig bot commented Dec 15, 2020

Build succeeded:

@craig craig bot merged commit 744f66c into cockroachdb:master Dec 15, 2020
rickystewart added a commit to rickystewart/cockroach that referenced this pull request Dec 15, 2020
This moves us closer to generating our protobuf generated code in the
Bazel sandbox (see cockroachdb#56067). Currently all the `.pb.go` files are checked
into tree. We hook into the standard Bazel support for protobufs, adding
a few (very light) utilities along the way. Specifically:

* Add a `go_proto_compiler` definition for `protoc-gen-gogoroach`. After
  cockroachdb#57913, this is trivial.
* Define a couple utilities in `pkg/build/util.bzl` to wrap some common
  functionality. These utilities (`proto_lib`, `go_proto_lib`) are meant
  to be used almost everywhere in the CockroachDB codebase in place of
  the standard `proto_library` and `go_proto_library` rules, and have
  the same API.
* Port one small example (`pkg/jobs/jobspb/schedule.proto`) from using
  the in-tree `.pb.go` file to a version generated in the sandbox to
  demonstrate that everything works as expected.

The intention here is that now that the utilities are in place, the
remainder of cockroachdb#56067 is rote work that can be done in a follow-up.

Release note: None
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.

None yet

3 participants