grpc_client icon indicating copy to clipboard operation
grpc_client copied to clipboard

Client generation with "o" or "module_name_prefix" options fails

Open galaxie opened this issue 7 years ago • 0 comments

I was trying to generate ETCD3 client using the following specification https://github.com/kragniz/python-etcd3/tree/master/etcd3/proto and Erlang/OTP 20 on MacOS High Sierra.

Seems like some code generation options don't work as expected.

Protobuff specification resides in ./proto dir and desirable generated code path is ./compiled_client:

.
├── compiled_client
├── proto
│   ├── auth.proto
│   ├── kv.proto
│   └── rpc.proto
├── src
    ├── ...
├── Makefile
├── ...

I used the following code for generation, where PROJECT_ROOT is a string with an absolute path to the project. I tried output dir option and module prefix option. Both end up with an exception.

% example 1
ProtoDir = "PROJECT_ROOT/proto".
OutputDir = "PROJECT_ROOT/compiled_client".
grpc_client:compile(
        filename:join(ProtoDir, "rpc.proto"),
        [
            {i, ProtoDir},
            {o, OutputDir},
            {use_packages, true}
        ]
    ).

** exception error: no match of right hand side value error
     in function  grpc_lib_compile:compile_pb/2 (src/grpc_lib_compile.erl, line 46)
     in call from grpc_lib_compile:file/2 (src/grpc_lib_compile.erl, line 30)
% file "PROJECT_ROOT/proto/rpc.erl" was generated
% example 2
ProtoDir = "PROJECT_ROOT/proto".
OutputDir = "PROJECT_ROOT/compiled_client".
grpc_client:compile(
        filename:join(ProtoDir, "rpc.proto"),
        [
            {i, ProtoDir},
            {module_name_prefix, test},
            {use_packages, true}
        ]
    ).
** exception error: no match of right hand side value error
     in function  grpc_lib_compile:compile_pb/2 (src/grpc_lib_compile.erl, line 46)
     in call from grpc_lib_compile:file/2 (src/grpc_lib_compile.erl, line 30)

%  file "PROJECT_ROOT/proto/testrpc.erl was generated

I guess the problem is caused by this function here https://github.com/Bluehouse-Technology/grpc_lib/blob/master/src/grpc_lib_compile.erl#L42 which doesn't respect possible generated file path or/and name change.

galaxie avatar Jun 11 '18 09:06 galaxie