我们有 3 个相互依赖的 proto 文件,它们位于//protocol/proto
包中。基本上:
//protocol/
|__ proto/
|__ `A.proto` # depends on: `B.proto`, `C.proto`
|__ `B.proto` # depends on: `C.proto`
|__ `C.proto`
在里面A.proto
,我们声明了,imports B.proto
和,没有文件名imports C.proto
的前缀。protocol/path
对于 Java 代码编译(in //protocol/BUILD
),我们使用imports
如下,并且该规则完美运行。
java_proto_compile(
name = "client-java-proto",
protos = glob(["proto/*.proto"]),
imports = ["protocol/proto"],
with_grpc = True,
)
但是,当我尝试对 Python 代码编译(也在 中//protocol/BUILD
)执行相同操作时,它不起作用:
py_proto_compile(
name = "client-python-proto",
protos = glob(["proto/*.proto"]),
imports = ["protocol/proto/"],
with_grpc = True,
)
bazel build //protocol:client-python-proto
返回以下错误:
ERROR: ~/protocol/BUILD:31:1: output 'protocol/proto/A_pb2.py' was not created
ERROR: ~/protocol/BUILD:31:1: output 'protocol/proto/A_pb2_grpc.py' was not created
ERROR: ~/protocol/BUILD:31:1: output 'protocol/proto/B.py' was not created
ERROR: ~/protocol/BUILD:31:1: output 'protocol/proto/B_pb2_grpc.py' was not created
ERROR: ~protocol/BUILD:31:1: output 'protocol/proto/C_pb2.py' was not created
ERROR: ~/protocol/BUILD:31:1: output 'protocol/proto/C_pb2_grpc.py' was not created
ERROR: ~/protocol/BUILD:31:1: not all outputs were created or valid
Target //protocol:client-python-proto failed to build
导入导入的 proto 文件的完整路径(例如import protocol/proto/A.proto
)可以解决这个问题,但对我们来说重要的是我们不添加完整路径作为前缀。因此,我们试图使imports
论点起作用。
您知道可能是什么原因以及我们如何解决这个问题吗?