[erlang-questions] How to use gpb?

Tomas Abrahamsson tomas.abrahamsson@REDACTED
Mon Jul 1 11:33:14 CEST 2013


Hi, you might try the to loop over proto files, like below:

    %% -*- erlang -*-
    {pre_hooks,
     [{compile, "mkdir -p include"}, %% ensure the include exists
      {compile,
       "bash -c 'for f in proto/*.proto; "
       "do "
       "  erl +B -noinput -pa /path/to/gpb/ebin "
       "      -I$(pwd)/proto -o-erl src -o-hrl include "
       "      -s gpb_compile c $(pwd)/$f ; "
       "done'"
      }]}.

    {post_hooks,
     [{clean,
       "bash -c 'for f in proto/*.proto; "
       "do "
       "  rm -f src/$(basename $f .proto).erl; "
       "  rm -f include/$(basename $f .proto).hrl; "
       "done'"
      }]}.

    {erl_opts, [{i, "/path/to/gpb/include"}]}.

It is currently not possible to specify several files using something like
*.proto, but that's obviously a useful idea, I will fix that.

BRs
Tomas


On Mon, Jul 1, 2013 at 5:58 AM, Bin Wang <wbin00@REDACTED> wrote:

> Hi, Tomas
>
> Thanks for answering. But if I put all .proto files in directory
> proto, how do I write the hooks to compile them all? I tried to use
> *.proto instead of x.proto in pre_hooks, but it came with error: init
> terminating in do_boot
>
>
> 2013/6/29 Tomas Abrahamsson <tomas.abrahamsson@REDACTED>:
> > Hi, Rebar by default uses another protobuf compiler for any *.proto
> files it
> > finds in the src subdirectory.
> >
> > One way to use gpb with rebar is to put your *.proto in another
> > subdirectory, and use hooks to compile it. I got it working with the
> > following stuff in rebar.config:
> >
> >     %% -*- erlang -*-
> >     {pre_hooks,
> >      [{compile, "mkdir -p include"}, %% ensure the include dir exists
> >       {compile,
> >        "erl +B -noinput -pa /path/to/gpb/ebin "
> >        "-I`pwd`/proto -o-erl src -o-hrl include "
> >        "-s gpb_compile c `pwd`/proto/x.proto"
> >       }]}.
> >
> >     {post_hooks,
> >      [{clean, "rm -f src/x.erl include/x.hrl"}]}.
> >
> >     {erl_opts, [{i, "/path/to/gpb/include"}]}.
> >
> > and the following initial file/directory layout:
> >
> >     prompt# find .
> >     .
> >     ./proto
> >     ./proto/x.proto
> >     ./src
> >     ./src/g_sup.erl
> >     ./src/g.app.src
> >     ./src/g_app.erl
> >     ./rebar.config
> >
> > BRs
> > Tomas
> >
> >
> > On Fri, Jun 28, 2013 at 11:08 AM, Bin Wang <wbin00@REDACTED> wrote:
> >>
> >> Hi,
> >>
> >> I'm using google protocol buffers. I found an erlang plugin named
> >> gpb(https://github.com/tomas-abrahamsson/gpb). But I don't know how
> >> to use it. When I add it as a dependency of my app using rebar, while
> >> compile, it always comes out this error:
> >>
> >> ERROR: Protobuffs library not present in code path!
> >>
> >> Which I searched in google and only found it in erlang_protobuffs
> >> code. I do use it as a dependency before, but dose it matters?
> >> _______________________________________________
> >> erlang-questions mailing list
> >> erlang-questions@REDACTED
> >> http://erlang.org/mailman/listinfo/erlang-questions
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130701/ebd22f33/attachment.htm>


More information about the erlang-questions mailing list