Skip to content

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

@c4f3a0ce

Description

@c4f3a0ce

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions