Hi Mika,
Thanks for bringing this up - comments inline.
I think what you are doing is fairly similar to what I'm doing for a
Makefile.PL and project with multiple message types. In my case, they
all fall under the same package prefix:
Foo::Bar
Foo::Bat
Foo::Baz
So I have a bar.proto, a bat.proto, and a baz.proto. My Makefile.PL
runs protoxs on all of these files and generates Bar.xs, Bat.xs, and
Baz.xs (and .pod and .pm files). Then I have a Foo.xs and
Foo.pm/Foo.pod which I've written by hand. Foo.xs has a BOOT: section
in which I explicitly call the boot_Foo__Bar, boot_Foo__Bat, and
boot_Foo__Baz functions to load up the other modules. Foo.pm just
bootstraps Foo via DynaLoader. In my Perl scripts, I just "use Foo;",
and I actually remove Bar.pm, Bat.pm, and Baz.pm, because I don't use
them at all. Lastly, I have to move Bar.pod, Bat.pod, and Baz.pod
into a Foo/ directory, and I put a Foo.pod in the top level directory
of the project.
In any case, however it is that we lay out the package, my thought was
that we could get protoxs to take direction from custom options in the
.proto files. We (protobuf-perlxs) have been assigned field number
1001 for doing this (I had asked Kenton Varda about this a while back,
and 1001 is the globally accepted protobuf-perlxs extension number for
custom options). So, under "Custom Options" here:
http://code.google.com/apis/protocolbuffers/docs/proto.html#options
we could define a set of perlxs extensions for FileOptions,
MessageOptions, etc, such that protoxs can figure out from the .proto
files exactly what it needs to do in order to generate the right
output for the project. So, for example, in my case above, I would do
something like:
1) in bar.proto (similarly for baz.proto, and bat.proto):
package Foo;
import perlxs.proto;
option
perlxs.file.pm = false; // the default is true
option perlxs.file.poddir = "Foo"; // relative to the output directory
(default is ".")
message Bar {
...
}
2) in foo.proto (a new file that I would create, which would contain
no message descriptions at all):
package Foo;
import perlxs.proto;
option perlxs.file.boot = true; // causes Foo.xs, Foo.pm, and Foo.pod
to be generated
option perlxs.file.makefile_pl = true; // causes a Makefile.PL to be generated
This may be going a little too far, but in any case, I think it should
be possible to use these options to instruct protoxs to generate a
Foo.xs that boots the other message types (which it knows about).
e.g. "protoxs foo.proto bar.proto baz.proto bat.proto" should, in
principle, make it possible to generate a Foo.xs that has all the
right boot_Foo__Blah calls in it. And if we've gone that far, we can
probably even generate a Makefile.PL and who knows what else.
I think this means we would need to distribute a perlxs.proto with
protobuf-perlxs, and have it installed in the right place. The
contents of the file would look something like:
package perlxs;
import "google/protobuf/descriptor.proto"
message PerlXSFileOptions {
optional bool pm = 1; [default=true];
optional string poddir = 2; [default="."];
optional bool boot = 3; [default=false];
optional bool makefile_pl = 4; [default=false];
}
extend google.protobuf.FileOptions {
optional PerlXSFileOptions file;
}
Users would not be required to use perlxs.proto, but if they wanted to
do any of the advanced package management, they'd need to import it
into their .proto files.
> BTW, there are some changes needed in general to cleanly use several
> messages as the custom OutputStream class needs to have a different
> name in the different .xs files or be shared from somewhere else.
I had thought protoxs generated an output stream class definition for
each message type, so if you have Foo::Bar and Foo::Baz, Bar.xs will
have a class Foo_Bar_OutputStream (or similar) and Baz.xs will have
Foo_Baz_OutputStream. It's been a while since I looked at this code,
is my recollection incorrect?
In any case, this also makes me wonder if we should install a
libprotobuf-perlxs.so with the protobuf-perlxs package, and have some
things (such as a common, reusable class PerlXS_OutputStream) moved to
that library, rather than creating multiple essentially identical
classes, one for each top-level message type. I can't think of a lot
of other things that would go in that library right now, though.
-dave
> Regards,
>
> Mika
>
> --
>
> You received this message because you are subscribed to the Google Groups "Protocol Buffers for Perl/XS" group.
> To post to this group, send email to
protobu...@googlegroups.com.
> To unsubscribe from this group, send email to
protobuf-perl...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/protobuf-perlxs?hl=en.
>
>
>