Skip to content

Option ruby_package causes inconsistent code generation #5584

Closed
@jbolinger

Description

@jbolinger

What version of protobuf and what language are you using?
Version: 3.6.1
Language: Ruby

What operating system (Linux, Windows, ...) and version?
MacOS 10.14

What runtime / compiler are you using (e.g., python version or gcc version)
Ruby 2.4.1

What did you do?
Steps to reproduce the behavior:

  1. Compile the following proto: protoc --proto_path=. --ruby_out=. example.proto
syntax = "proto3";

package google.example;

option java_multiple_files = true;
//option ruby_package = "Google::Example";

service HelloService {
     rpc HiThere (HiRequest) returns (HiResponse);
}

message HiRequest {
    string query = 1;
}

message HiResponse {
    string result = 1;
}
  1. Repeat step 1 after uncommenting the ruby_package line.

What did you expect to see
The generated Ruby code should be the same.

What did you see instead?
When the ruby_package options is specified the generated code is:

module Google::Example
  HiRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.example.HiRequest").msgclass
  HiResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.example.HiResponse").msgclass
end

Without the ruby_package option it is:

module Google
  module Example
    HiRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.example.HiRequest").msgclass
    HiResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.example.HiResponse").msgclass
  end
end

This inconsistency causes issues because the module must already be defined if the ruby_package option is used (example: googleapis/google-cloud-ruby#2782).

Anything else we should know about your project / environment

Activity

TeBoring

TeBoring commented on Jan 22, 2019

@TeBoring
Contributor

Does the title of this issue correctly reflect the problem?
It seems to me the inconsistency is expected. The real issue is if the outer module is not defined. Is that correct?

self-assigned this
on Jan 22, 2019
jbolinger

jbolinger commented on Jan 22, 2019

@jbolinger
ContributorAuthor

Why is the inconsistency expected?

The module not being defined is what can cause problems at runtime, but it's not clear to me why it should be different.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Option ruby_package causes inconsistent code generation · Issue #5584 · protocolbuffers/protobuf