Closure templates and proto file descriptors

119 views
Skip to first unread message

Anton Kovalyov

unread,
Jan 30, 2017, 8:38:51 PM1/30/17
to Closure Templates Discuss
Hi,

We're trying to have Closure Templates compiler understand our protos so that we could specify them as types. I.e. the following example (the gen.model.Post is defined in a protobuf file):

{template .index}
 
{@param post: gen.model.Post}
 
// ...
{/template}

We've updated to the latest versions of closure-templates which recently introduced a new flag --protoFileDescriptors. I wasn't deeply familiar with the Google/Closure ecosystem when I embarked on this project so I initially I thought that proto file descriptors are the .proto files themselves. Now it seems that it's a some kind of a binary format generated by the protoc compiler. I'm able to generate one with this command:

protoc --descriptor_set_out=test.desc --include_imports --proto_path=../src/main/protobuf,lib/proto/model lib/proto/model/**.proto

However, when I try to pass it to closure-templates compiler it fails with a mysterious (to me) error:

INTERNAL SOY ERROR.

Please open an issue at https://github.com/google/closure-templates/issues with this stack trace and repro steps

java
.lang.IllegalArgumentException: ExtensionRegistry.add() must be provided a default instance when adding an embedded message extension.
 at com
.google.protobuf.ExtensionRegistry.add(ExtensionRegistry.java:264)
 at com
.google.template.soy.types.proto.SoyProtoTypeProvider$RegisterExtensionsDescriptorTreeWalker.visitExtensionDescriptor(SoyProtoTypeProvider.java:256)
 at com
.google.template.soy.types.proto.DescriptorTreeWalker.walkGenericDescriptor(DescriptorTreeWalker.java:178)
 at com
.google.template.soy.types.proto.DescriptorTreeWalker.walkGenericDescriptors(DescriptorTreeWalker.java:168)
 at com
.google.template.soy.types.proto.SoyProtoTypeProvider$RegisterExtensionsDescriptorTreeWalker.visitFileDescriptor(SoyProtoTypeProvider.java:246)
 at com
.google.template.soy.types.proto.DescriptorTreeWalker.walkFileDescriptor(DescriptorTreeWalker.java:151)
 at com
.google.template.soy.types.proto.DescriptorTreeWalker.walkFileDescriptorSet(DescriptorTreeWalker.java:146)
 at com
.google.template.soy.types.proto.DescriptorTreeWalker.walkFileDescriptorSetFromByteSource(DescriptorTreeWalker.java:119)
 at com
.google.template.soy.types.proto.SoyProtoTypeProvider$Builder.walkAll(SoyProtoTypeProvider.java:107)
 at com
.google.template.soy.types.proto.SoyProtoTypeProvider$Builder.build(SoyProtoTypeProvider.java:125)
 at com
.google.template.soy.AbstractSoyCompiler.doMain(AbstractSoyCompiler.java:177)
 at com
.google.template.soy.AbstractSoyCompiler.access$000(AbstractSoyCompiler.java:49)
 at com
.google.template.soy.AbstractSoyCompiler$2.main(AbstractSoyCompiler.java:149)
 at com
.google.template.soy.MainClassUtils.runInternal(MainClassUtils.java:255)
 at com
.google.template.soy.AbstractSoyCompiler.run(AbstractSoyCompiler.java:146)
 at com
.google.template.soy.AbstractSoyCompiler.runMain(AbstractSoyCompiler.java:138)
 at com
.google.template.soy.SoyToJsSrcCompiler.main(SoyToJsSrcCompiler.java:192)

My question, however, is more generic: is there a document somewhere describing what proto file descriptors are and how to use them with closure templates?

Thanks,
Anton

Hochhaus, Andy

unread,
Jan 30, 2017, 10:18:45 PM1/30/17
to closure-temp...@googlegroups.com
Hi Anton!

Great to see more usage of soy proto support.

On Mon, Jan 30, 2017 at 1:01 PM, 'Anton Kovalyov' via Closure
Templates Discuss <closure-temp...@googlegroups.com> wrote:
> My question, however, is more generic: is there a document somewhere
> describing what proto file descriptors are and how to use them with closure
> templates?

I only know of minimal docs at
https://developers.google.com/protocol-buffers/docs/techniques.



In case you have not already seen it, the bazel build tool has a
project called rules_closure. I added support to it for using soy
templates with protobufs:

https://github.com/bazelbuild/rules_closure/
https://github.com/bazelbuild/rules_closure/commit/1cae2870f435a78feb45d24f0626e118eda2d217

The goal of rules_closure is to make working with the entire closure
ecosystem trivial so it might be worth checkout out.

Best,
Andy

Hochhaus, Andy

unread,
Jan 30, 2017, 10:33:15 PM1/30/17
to closure-temp...@googlegroups.com
On Mon, Jan 30, 2017 at 7:18 PM, Hochhaus, Andy <ahoc...@samegoal.com> wrote:
> I only know of minimal docs at
> https://developers.google.com/protocol-buffers/docs/techniques.

I intended to link to:

https://developers.google.com/protocol-buffers/docs/techniques#self-description
Reply all
Reply to author
Forward
0 new messages