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 editions support to protoprint #600

Merged
merged 4 commits into from
Apr 4, 2024
Merged

Conversation

mkruskal-google
Copy link
Contributor

No description provided.

Copy link
Owner

@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.

Brilliant! Thanks for opening this. Just a couple of minor comments. Otherwise, looking good.

desc/protoprint/print.go Outdated Show resolved Hide resolved
Comment on lines +534 to +537
if syn == "editions" {
_, _ = fmt.Fprintf(w, "edition = %q;", strings.TrimPrefix(fdp.GetEdition().String(), "EDITION_"))
return
}
Copy link
Owner

Choose a reason for hiding this comment

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

I think this is supposed to go below line 538, right? Otherwise, syn is not yet defined here.

BTW, you can verify everything in a local checkout by running make ci.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doh, I had to copy this by hand and got the lines mixed up :P. Thanks for the test command :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like you might be on an older version of go-protobuf too, IsClosed doesn't work :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah this will likely have to wait for a new release

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the commit we have if you have another idea: protocolbuffers/protobuf-go@3039476

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Figured that out, now I'm hitting protocompile's error:
print_test.go:268: Unexpected error: test.proto:2:11: editions are not yet supported; use syntax proto2 or proto3 instead

Copy link
Owner

Choose a reason for hiding this comment

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

For protocompile, you can do:

go get google.golang.org/protobuf/proto@3039476726e4 && \
    go get github.com/golang/protobuf@v1.5.4 && \
    go mod tidy

As for the protocompile issues, I was hoping to cut a release this week with editions support. The last thing I have in progress is a branch to add validation of feature usage, and then it should be okay. (Though I haven't done anything with the just-added FeatureSupport stuff. That is, unfortunately, not yet available in the protobuf-go descriptorpb package.) Right now, all of its editions support is test-only (behind an internal flag that only tests can flip on).

Until then, I think you could add the example file to internal/testprotos and then update internal/testprotos/make_protos.sh to generate a descriptor set with protoc. The test could then read that descriptor set and use protodesc.NewFiles to turn the descriptor set into protoreflect.FileDescriptor instances, which you can then wrap and print.

Sorry that's a bit convoluted. If that's a bit much, I'm happy to handle all of that. Just let me know if you want me to poke at that list of steps or if you will try to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm looks like this might need protoparse updates too to handle the reserved grammar changes in editions :)

I think I got all this working but the AST test tries to parse the new editions file and dies in convertASTReserved

Copy link
Owner

Choose a reason for hiding this comment

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

might need protoparse updates too to handle the reserved grammar changes in editions

Not exactly. The protoparse package uses protocompile under its hood, and protocompile is almost done with editions changes, and includes support for reserved identifiers. See the most recent pull request, which is the last thing to add to protocompile for editions support (well... the last thing before the new FeatureSupport stuff landed this week): bufbuild/protocompile#264.

The problem is that protocompile rejects editions files right now -- the support for it is only enabled in tests (with the idea being that we enable it outside of tests, for users, once the work is done).

For now, we need to just conditionally turn off the verification using protoparse for this particular test file. And we can instead rely on the desc/protoprint/testfiles/check-protos.sh script to verify the golden outputs are valid. That script will need to be updated to use the --experimental_editions flag in its protoc invocation so it doesn't fail on that file.

Copy link
Owner

@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.

This LGTM. I mentioned in another comment about updates to the desc/protoprint/testfiles/check-protos.sh script, but I can do that in another PR. What's here looks good. Thanks for the pull request!

@jhump jhump merged commit 0935deb into jhump:main Apr 4, 2024
jhump added a commit that referenced this pull request Apr 4, 2024
@mkruskal-google mkruskal-google deleted the editions-print branch April 4, 2024 15:58
jhump added a commit that referenced this pull request Apr 6, 2024
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

2 participants