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

Optional use of require_relative #240

Open
daBrado opened this issue Dec 17, 2014 · 6 comments
Open

Optional use of require_relative #240

daBrado opened this issue Dec 17, 2014 · 6 comments

Comments

@daBrado
Copy link

daBrado commented Dec 17, 2014

Would it be desirable to optionally have the generated ruby code use require_relative (in place of the default require) to bring in other ruby code generated in a given protoc run?

@localshred
Copy link
Contributor

Can you describe a little more what benefit you feel this would provide?

@onethirtyfive
Copy link
Contributor

👍 on this or an alternative I'll propose.

I have protobufs which I inherit from upstream reverse engineering efforts. My generated code is packaged in a different gem (as a dependency because it changes independently), but I want it to share the same top-level Effigy module at runtime.

The proto files are organized like so:

proto/
├── demo.proto
├── dota_commonmessages.proto
├── dota_modifiers.proto
├── dota_usermessages.proto
├── netmessages.proto
├── networkbasetypes.proto
├── s1
│   ├── s1_dota_usermessages.proto
│   ├── s1_netmessages.proto
│   └── s1_usermessages.proto
└── s2
    ├── s2_base_gcmessages.proto
    ├── s2_dota_gcmessages_common.proto
    ├── s2_dota_match_metadata.proto
    ├── s2_dota_usermessages.proto
    ├── s2_gameevents.proto
    ├── s2_netmessages.proto
    ├── s2_te.proto
    └── s2_usermessages.proto

I organize the output manually after compiling with package effigy.wire;, package effigy.wire.s1;, etc. definitions in the protobuf files:

lib/
├── effigy
│   ├── wire
│   │   ├── demo.pb.rb
│   │   ├── dota_commonmessages.pb.rb
│   │   ├── dota_modifiers.pb.rb
│   │   ├── dota_usermessages.pb.rb
│   │   ├── netmessages.pb.rb
│   │   ├── networkbasetypes.pb.rb
│   │   ├── s1
│   │   │   ├── s1_dota_usermessages.pb.rb
│   │   │   ├── s1_netmessages.pb.rb
│   │   │   └── s1_usermessages.pb.rb
│   │   ├── s1.rb
│   │   ├── s2
│   │   │   ├── s2_base_gcmessages.pb.rb
│   │   │   ├── s2_dota_gcmessages_common.pb.rb
│   │   │   ├── s2_dota_match_metadata.pb.rb
│   │   │   ├── s2_dota_usermessages.pb.rb
│   │   │   ├── s2_gameevents.pb.rb
│   │   │   ├── s2_netmessages.pb.rb
│   │   │   ├── s2_te.pb.rb
│   │   │   └── s2_usermessages.pb.rb
│   │   └── s2.rb
│   └── wire.rb
└── effigy.rb

Works wonderfully until I try to require the files. This is because effigy/wire/s2/s2_te.pb.rb is interested in effigy/wire/networkbasetypes.pb.rb.

Strict adoption of ruby namespacing rules--that is, that module code should be organized hierarchically in folders corresponding to their modules--would make require work in all use cases because it would just be plain-old ruby code. The current (and protobuf-esque) approach of dumping all the (internally namespaced) output into a flat folder and hoping for the best on a require doesn't benefit from Ruby's conventions at all.

And this or similar is probably why @daBrado asked about require_relative. Or not and it's just me. :)

Thoughts?

@onethirtyfive
Copy link
Contributor

onethirtyfive commented Jun 6, 2016

In case any of you is more curious about my use-case, it's here. You can see how I have to torture things to get them to compile in scripts bin--and I'm having to do the require_relative changes in the lib output manually every time.

@tdeo
Copy link
Contributor

tdeo commented Jul 19, 2017

👍 for this as well. It would already be nice to be able to store the .pb.rb files inside lib/protobuf or something instead of just leaving there in lib/.

A PR on this should be quite straightforward, I'm willing to work on this if people are interested

@film42
Copy link
Member

film42 commented Jul 21, 2017

@tdeo Feel free to open a PR that supports both options if you're interested. I'd be happy to take a look. I'm not motivated to make the change but I'd be happy to merge a good solution :)

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

No branches or pull requests

6 participants
@onethirtyfive @localshred @daBrado @film42 @tdeo and others