하나 이상의 솔루션이 있습니다.
가장 깨끗한 방법은 빌드 할 때 확인을하는 것입니다. 확인하려는 각 파일 (또는 파일 묶음)에 대해 genrule
을 만들고 검증에 성공하면 genrule이 결과를 출력하고 실패하면 규칙은 아무것도 출력하지 않으며 자동으로 빌드를 실패시킵니다.
검증 성공 여부는 파일의 내용에 따라 다르며 동일한 입력이 동일한 출력을 가져야하므로 genrules은 입력 내용에 종속 된 출력 파일을 생성해야합니다. 가장 편리한 방법은 확인이 성공하면 파일의 요약을 출력에 쓰고 확인이 실패하면 출력을 출력하지 않는 것입니다.
Verifier를 다시 사용할 수있게하려면 Skylark macro을 만들어 모든 패키지에 사용할 수 있습니다.
이 모든 것을 함께 쓰려면 다음과 같이 작성하십시오. //tools:py_verify_test.bzl
의
내용 : //tools:build_test.sh
의
def py_verify_test(name, srcs, visibility = None):
rules = {"%s-file%d" % (name, hash(s)): s for s in srcs}
for rulename, src in rules.items():
native.genrule(
name = rulename,
srcs = [s],
outs = ["%s.md5" % rulename],
cmd = "$(location //tools:py_verifier) $< && md5sum $< > [email protected]",
tools = ["//tools:py_verifier"],
visibility = ["//visibility:private"],
)
native.sh_test(
name = name,
srcs = ["//tools:build_test.sh"],
data = rules.keys(),
visibility = visibility,
)
내용 : //tools:BUILD
의
#!/bin/true
# If the test rule's dependencies could be built,
# then all files were successfully verified at
# build time, so this test can merely return true.
내용 : 파일을 확인하고자하는 패키지의
# I just use sh_binary as an example, this could
# be a more complicated rule of course.
sh_binary(
name = "py_verifier",
srcs = ["py_verifier.sh"],
visibility = ["//visibility:public"],
)
내용 :
load("//tools:py_verify_test.bzl", "py_verify_test")
py_verify_test(
name = "verify",
srcs = glob(["**/*.py"]),
)