How to get all dependency .proto files of a given .proto file hierarchically?

2,717 views
Skip to first unread message

Yuri Vic

unread,
Dec 1, 2019, 12:32:23 PM12/1/19
to Protocol Buffers
There is a large directory of .proto files.

I only need to pick the ones that can be reached from a particular file in the set.

What is the easiest way to build a list of .proto files reachable from a given .proto file?

Marc Gravell

unread,
Dec 1, 2019, 2:53:01 PM12/1/19
to Yuri Vic, Protocol Buffers
Untested, but can't you just use protoc with the descriptor-set mode to build a FileDescriptorSet (IIRC) which will be the processed output of protoc's efforts? Then parse it using the details from descriptor.proto, and see what descriptors are in the FileDescriptorSet?


Yuri Vic

unread,
Dec 2, 2019, 10:30:17 PM12/2/19
to Protocol Buffers
On Sunday, December 1, 2019 at 11:53:01 AM UTC-8, Marc Gravell wrote:
Untested, but can't you just use protoc with the descriptor-set mode to build a FileDescriptorSet (IIRC) which will be the processed output of protoc's efforts? Then parse it using the details from descriptor.proto, and see what descriptors are in the FileDescriptorSet? 

 
Doesn't this require building another app just to parse the FileDescriptorSet file?

Nadav Samet

unread,
Dec 2, 2019, 10:49:50 PM12/2/19
to Yuri Vic, Protocol Buffers
Hi Yuri,

Try this:

protoc --include_imports --descriptor_set_out=/dev/stdout file1.proto fie2.proto ...  | protoc --decode=google.protobuf.FileDescriptorSet google/protobuf/descriptor.proto | grep "^  name: "


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/08957a5c-7821-47ba-8db7-d7b39a7c0ea0%40googlegroups.com.


--
-Nadav

John Krzemien

unread,
Dec 3, 2019, 1:35:29 PM12/3/19
to Protocol Buffers
Won't this only give the 1st level of dependencies? He'll likely need the transitive closure if he's trying to generate and build.

On Monday, December 2, 2019 at 7:49:50 PM UTC-8, Nadav Samet wrote:
Hi Yuri,

Try this:

protoc --include_imports --descriptor_set_out=/dev/stdout file1.proto fie2.proto ...  | protoc --decode=google.protobuf.FileDescriptorSet google/protobuf/descriptor.proto | grep "^  name: "


On Mon, Dec 2, 2019 at 7:30 PM Yuri Vic <yuri...@gmail.com> wrote:
On Sunday, December 1, 2019 at 11:53:01 AM UTC-8, Marc Gravell wrote:
Untested, but can't you just use protoc with the descriptor-set mode to build a FileDescriptorSet (IIRC) which will be the processed output of protoc's efforts? Then parse it using the details from descriptor.proto, and see what descriptors are in the FileDescriptorSet? 

 
Doesn't this require building another app just to parse the FileDescriptorSet file?

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prot...@googlegroups.com.


--
-Nadav

Nadav Samet

unread,
Dec 3, 2019, 1:52:33 PM12/3/19
to John Krzemien, Protocol Buffers
--include_imports should make protoc provide the full transitive closure.

To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/46aefe6b-d56b-493e-ab22-efaf6f95c1ee%40googlegroups.com.


--
-Nadav

John Krzemien

unread,
Dec 3, 2019, 1:53:43 PM12/3/19
to Protocol Buffers
Just tried it out. Seems to grab everything!

Yuri Vic

unread,
Dec 4, 2019, 11:38:15 AM12/4/19
to Protocol Buffers
This worked, thanks Nadav!


On Monday, December 2, 2019 at 7:49:50 PM UTC-8, Nadav Samet wrote:
Hi Yuri,

Try this:

protoc --include_imports --descriptor_set_out=/dev/stdout file1.proto fie2.proto ...  | protoc --decode=google.protobuf.FileDescriptorSet google/protobuf/descriptor.proto | grep "^  name: "


On Mon, Dec 2, 2019 at 7:30 PM Yuri Vic <yuri...@gmail.com> wrote:
On Sunday, December 1, 2019 at 11:53:01 AM UTC-8, Marc Gravell wrote:
Untested, but can't you just use protoc with the descriptor-set mode to build a FileDescriptorSet (IIRC) which will be the processed output of protoc's efforts? Then parse it using the details from descriptor.proto, and see what descriptors are in the FileDescriptorSet? 

 
Doesn't this require building another app just to parse the FileDescriptorSet file?

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prot...@googlegroups.com.


--
-Nadav
Reply all
Reply to author
Forward
0 new messages