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

Discrepancy between readProtoFiles2 and protoc behavior in handling well-known types #94

Open
c4f3a0ce opened this issue Sep 9, 2023 · 2 comments

Comments

@c4f3a0ce
Copy link

c4f3a0ce commented Sep 9, 2023

According to readProtoFiles2 cos:

     ‘readProtoFiles2’ is different from ‘readProtoFiles’ to be
     consistent with the behavior of ‘protoc’ command line tool in
     being explicit about the search path for proto import statements.

However, I believe that its behavior is not fully compatible. When I use protoc default search path, including google/protobuf is included. For example if I have a following structure:

.
└── proto
    └── foo
        └── bar
            ├── bar.proto
            └── foo.proto

with foo.proto

syntax = 'proto3';

package foo.bar;

import "google/protobuf/any.proto";
import "foo/bar/bar.proto";

message Foo {
  google.protobuf.Any baz = 1;
  Bar bar = 2;
}

and bar.proto

syntax = 'proto3';

package foo.bar;

message Bar {
}

I can protoc --cpp_out=./gen -I ./proto proto/foo/bar/*

In contrast, if I use the following:

RProtoBuf::readProtoFiles2(dir= dir("proto"), protoPath = c("proto"), recursive=TRUE)

I get

google/protobuf/any.proto:0:1:File not found.
foo/bar/foo.proto:5:1:Import "google/protobuf/any.proto" was not found or had errors.
foo/bar/foo.proto:9:3:"google.protobuf.Any" is not defined.
Error: Could not load proto file 'foo/bar/foo.proto'

and I have to explicitly provide path to include dir with google/protobuf/any.proto

RProtoBuf::readProtoFiles2(dir= dir("proto"), protoPath = c("proto", "/path/to/include/"), recursive=TRUE)

to make things work.

Is it the intended behavior?

@eddelbuettel
Copy link
Owner

Is it the intended behavior?

I think you have to ask upstream. This project provides the glue to access the protocol buffers library and tools as shipped by Google. We neither set, nor modify, the spec. Of course, if something is different between 'us' and upstream it is likely a bug but methinks you have a pure upstream question here.

@eddelbuettel
Copy link
Owner

and I have to explicitly provide path

That part could be us, and I think we made some very early design choices in the package about where some default path for "default for the package" .proto files are sourced. But as such it is pretty much established behavior and unlikely to change.

So maybe just need to update the documentation and state this.

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

2 participants