[英]How to have bazel genrule depend on test passing?
I have the following genrule
which generates a new buf
image file:我有以下生成一个新的
buf
图像文件的genrule
:
genrule(
name = "build_buf_image",
srcs = [":proto_srcs"],
outs = ["go/src/grail.com/examples/microservice-grpc/server/apimodels/grpc/buf-image.json"],
cmd = "$(location //third_party/buf:generate-image) $(OUTS) $(SRCS)",
tools = [
"//third_party/buf:generate-image",
"@buf",
"@jq",
],
)
But before that's executed, I would like the following test to be run:但在执行之前,我希望运行以下测试:
buf_proto_breaking_test(
name = "proto_breaking_check",
against_input = "buf-image.json",
protos = [
":proto_lib",
],
)
How can this be done?如何才能做到这一点? Is there a way for the
genrule
to depend on the test?有没有办法让
genrule
依赖于测试?
It is not possible for a non- testonly
rule to depend on a testonly
rule.非
testonly
规则不可能依赖于testonly
规则。 From https://docs.bazel.build/versions/main/be/common-definitions.html :从https://docs.bazel.build/versions/main/be/common-definitions.html :
If True, only testonly targets (such as tests) can depend on this target.
Equivalently, a rule that is not testonly is not allowed to depend on any rule that is testonly.
Tests (*_test rules) and test suites (test_suite rules) are testonly by default.
This attribute is intended to mean that the target should not be contained in binaries that are released to production.
Because testonly is enforced at build time, not run time, and propagates virally through the dependency tree, it should be applied judiciously. For example, stubs and fakes that are useful for unit tests may also be useful for integration tests involving the same binaries that will be released to production, and therefore should probably not be marked testonly. Conversely, rules that are dangerous to even link in, perhaps because they unconditionally override normal behavior, should definitely be marked testonly.
It should be possible to create a custom rule that will call the functionality of the test, though.不过,应该可以创建一个自定义规则来调用测试的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.