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 CLI flag --schemas_out to turn descriptor set back to .protos #4021

Closed

Conversation

djudd-stripe
Copy link

This is a proposed feature, on which I'm looking for comment. I haven't implemented tests yet, but will if folks like the idea.

The main use case I have is generating .proto schemas from another, canonical schema definition. Rather than writing out .proto strings myself, it seems safer/nicer to build a descriptor set object using standard setters and then use google/protobuf C++ code to turn that into .proto strings, and I'm not working in C++ so would like to be able to shell out to protoc.

Evidence that I'm not the only person who has wanted this feature: https://stackoverflow.com/questions/19418655/restoring-proto-file-from-descriptor-string-possible

I should be covered by the Stripe CLA, although the bot doesn't always seem to recognize that.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

1 similar comment
@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Dec 8, 2017

From what I can tell, this is not a common use case of protoc. The interaction between existing protoc command line flags are already complicated and I'm concerned about adding more.

Can you instead just use the DescriptorPool API in your schema generator? The implementation should be pretty straightforward as shown by Kenton on the stackoverflow question.

@djudd-stripe
Copy link
Author

I suspect it's not a common use case, true. It seems fitting as an inverse to the existing --descriptor_set_out flag, but if you want to minimize the interface, I understand.

I'm not sure how the DescriptorPool API alone would help with my use case. I use essentially Kenton's implementation in this PR, and it seems to require the C++-only DebugString method as well. Can I produce actual .proto schemas by that means without C++?

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Dec 8, 2017

Converting descriptors to proto syntax is only supported in C++ API. If you are using some other language, it should still be easy enough to write a dedicated C++ binary for this purpose.

Also I think you can consider using the descriptor set directly without generating intermediate .proto files since protoc (and proto runtime) can make use of the descriptor set without relying on actual .proto files.

@djudd-stripe
Copy link
Author

I have, in fact, written a dedicated C++ binary, but I thought it might be useful to others to have it in protoc. If not, ok.

@xfxyjwf xfxyjwf self-assigned this Jun 23, 2018
@xfxyjwf
Copy link
Contributor

xfxyjwf commented Jun 23, 2018

We are moving protobuf to its own organization (see #4796) and after that we should be able to use a separate repo to build a more feature-rich command line tool instead of stretching protoc.

@xfxyjwf xfxyjwf closed this Jun 23, 2018
@ruanspies ruanspies mentioned this pull request Apr 12, 2022
@ruanspies
Copy link

I have, in fact, written a dedicated C++ binary, but I thought it might be useful to others to have it in protoc. If not, ok.

Hey @djudd-stripe. It has been a while since this post but was wondering if you could perhaps provide the code for the C++ binary that you built? Even though I would have appreciated the functionality you suggested in this PR, providing the code can at least help people like me to find alternatives.

@djudd-stripe
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants