-
Notifications
You must be signed in to change notification settings - Fork 101
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
descriptor bytes and fully qualified name helpers #397
base: master
Are you sure you want to change the base?
descriptor bytes and fully qualified name helpers #397
Conversation
nerdrew
commented
Jun 10, 2019
- add the descriptor proto bytes for each generated proto file
- add a helper for the fully qualified name of each proto.
This has failing specs for the functional code generation specs. Those specs seem to rely on the generated message from a pretty old version of protoc. The failure output is also pretty hard to read. Thoughts on refactoring the tests? I'd like to remove the bytes comparisons and instead require the generated files and check some of the fields, check encode -> decode roundtrip, check the custom options work as expected. |
a7ccbde
to
e2f173b
Compare
e.g., I'm thinking of tests like this: before(:all) do
require PROTOS_PATH.join('google_unittest.pb')
require PROTOS_PATH.join('map-test.pb')
require PROTOS_PATH.join('google_unittest_custom_options.pb')
end
it "generates code for google's unittest.proto" do
attrs = {
optional_int32: 1,
repeated_string: %w[boom],
optional_nested_message: { bb: 10 },
optional_nested_enum: ::Protobuf_unittest::TestAllTypes::NestedEnum::BAZ,
optional_foreign_message: { c: 12 },
repeated_import_message: [{ d: 13 }],
}
bytes = ::Protobuf_unittest::TestAllTypes.new(attrs).encode
message = ::Protobuf_unittest::TestAllTypes.decode(bytes)
expect(message.to_hash).to eq(attrs)
expect(message.default_int32).to eq(41)
expect(::Protobuf_unittest::TestAllTypes::FULLY_QUALIFIED_NAME).to eq('protobuf_unittest.TestAllTypes')
descriptor_file = ::Protobuf_unittest.descriptor_set.file.first
expect(descriptor_file.name).to eq('protos/google_unittest.proto')
expect(descriptor_file.package).to eq('protobuf_unittest')
end
it "generates code for google's unittest.proto extensions" do
attrs = { optional_import_message_extension: { d: 14 } }
bytes = ::Protobuf_unittest::TestAllExtensions.new(attrs).encode
message = ::Protobuf_unittest::TestAllExtensions.decode(bytes)
expect(message.to_hash).to eq(attrs)
expect(message.default_int64_extension).to eq(42)
end |
cc @embark |
I am completely biased, but I would love to have something like this! Thanks @nerdrew ! |
3b29e47
to
594fb56
Compare
The tests currently pass, but rubocop fails. I can update rubocop if this PR otherwise looks good. Thoughts on dropping support for EOL-ed ruby versions and updating rubocop to a modern version? (Both would be separate PRs). |
594fb56
to
681633d
Compare
task :spec do | ||
proto_path = ::File.expand_path('../spec/support/', __FILE__) | ||
proto_files = Dir[File.join(proto_path, '**', '*.proto')] | ||
cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{proto_files.join(' ')}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to: #345
681633d
to
9899d92
Compare
Any thoughts on this? |
I for one love these changes to include the descriptors and type names! The functional specs I am less help with, but would help if you need. |
- add the descriptor proto bytes for each generated proto file - add a helper for the fully qualified name of each proto.
- add ruby 2.6 to travis, remove EOL-ed rubies - the newer versions of protoc have a --ruby_out that takes precedence, alias the ruby plugin so it works with new versions of protoc - use binary protoc version 3.8.0
9899d92
to
34346ee
Compare
We've been dog fooding this for years now. Any objection to a rebase + merge? cc @film42 |
@nerdrew I'm down to rebase and merge. Y'all have been great with your previous patches. A few questions:
|
I don't think there are any breaking changes. We added constants all over with the fully qualified name for messages, enums, etc.
I.e. why'd we add the proto descriptor bytes after |
I'll rebase and cleanup soon. |
Thanks @nerdrew ! Makes sense about the descriptor being printed. Only nit would be how it's added to the files themselves. Could this be something we add after calling a dsl method like:
where More specifically, the instance variable checking as emitted code doesn't look particularly great for something that's supposed to be a human readable DSL. |