SWI-Prolog / contrib-protobufs

An interface to Google Protocol Buffers (protobuf)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

protoc plugin handling of imports

kamahen opened this issue · comments

Current protoc behavior requires importing all the *_pb files that are used both directly and indirectly. This is inconvenient and should be fixed.

Protoc doesn't process all the imported .proto files, although it does make them available in the data passed to the plugin (via plugin.proto). This means that if you have x.proto importing y.proto, you need to explicitly run protoc on both x.proto and y.proto.

The documentation is less clear about whether code that uses x_pb.pl needs to also mention y_pb.pl. For user convenience, x_pb.pl should reference y_pb.pl. This means we could have duplicate meta-proto facts from y_pb.pl (however, the module loader might prevent this).

The protoc documentation is a bit vague (and I haven't explored fully what the Python (and C++, Java) plugins do. For Python, it appears that for x.proto that imports y.proto, the generated code can handle messages defined in y.proto without the program needing an 'import y_pb2"

One possibility is to use the Request.parameter value to change behavior to process (recursively) all imports. This can be set by the --swipl_out parameter. For example: --swipl_out=all:dir_for_pb_files, which will put "all" in the Reqest.parameter field.

Currently, only the files specified by Request.file_to_generate are processed.

Only top-level _pb file needs to be loaded (commit 6b08d2a)

We might want to add an "all" option in future, but it seems that none of the other plugins do this -- they expect a standard "make" or "bazel" setup, where all dependencies are known and each one is compiled separately.