如何在单个命令中编译多个原型文件?

2022-09-02 00:20:20

我在单个目录中有两个原型文件,我正在寻找一种在单个命令中从这些文件生成类的方法。这似乎可以通过论证来实现。根据文档:--proto_path

必须提供一个或多个 .proto 文件作为输入。可以一次指定多个 .proto 文件。尽管这些文件是相对于当前目录命名的,但每个文件都必须驻留在 [由 --proto_path 参数指定] 的IMPORT_PATHs之一中,以便编译器可以确定其规范名称。

C:\shekhar\proto_trial>dir
 Volume in drive C is C

 Directory of C:\shekhar\proto_trial

07/25/2014  12:16 PM    <DIR>          .
07/25/2014  12:16 PM    <DIR>          ..
07/25/2014  12:16 PM    <DIR>          java_op
07/25/2014  12:16 PM               230 map.proto
07/23/2014  04:24 PM               161 message.proto
07/25/2014  12:17 PM             1,228 response.proto
               3 File(s)          1,619 bytes
               3 Dir(s)  50,259,398,656 bytes free

我使用了如下所示的参数--proto_path

C:\shekhar\proto_trial>protoc 
                       --proto_path=C:\shekhar\proto_trial 
                       --java_out=C:\shekhar\proto_trial\java_op 
                       *.proto

但我得到以下错误

message.proto: File does not reside within any path specified using --proto_path (or -I). 
You must specify a --proto_path which encompasses this file. 
Note that the proto_path must be an exact prefix of the .proto file names -- protoc is unable to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).

请建议一些方法,将所有原型文件一起编译在一起。


答案 1

问题在于,您指定的是绝对路径,但原型文件是相对路径。您可以删除该参数(无论如何,它默认为当前目录),也可以执行以下操作:--proto_path--proto_path

protoc --proto_path=C:\shekhar\proto_trial
       --java_out=C:\shekhar\proto_trial\java_op
       C:\shekhar\proto_trial\*.proto

答案 2

这是使用“查找”的选项

protoc --js_out=js \
        -Iproto/ \
        $(find proto/google -iname "*.proto")

推荐