bazel: fix hashes rule to generate outputs

So I figured out how to generate the outputs in the correct way so
that we don't need an artificial name; we must construct the outputs
field in the rule using a helper function.
This commit is contained in:
Justin SB 2019-10-01 11:29:40 -04:00
parent b2e03d6b17
commit 958c1a0771
No known key found for this signature in database
GPG Key ID: 8DEC5C8217494E37
2 changed files with 13 additions and 10 deletions

View File

@ -792,10 +792,10 @@ push-node-authorizer:
.PHONY: bazel-protokube-export
bazel-protokube-export:
mkdir -p ${BAZELIMAGES}
bazel build --action_env=PROTOKUBE_TAG=${PROTOKUBE_TAG} --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //images:protokube.tar.gz //images:protokube.tar.gz.hashes
bazel build --action_env=PROTOKUBE_TAG=${PROTOKUBE_TAG} --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //images:protokube.tar.gz //images:protokube.tar.gz.sha1 //images:protokube.tar.gz.sha256
cp -fp bazel-bin/images/bazel-out/k8-fastbuild/bin/images/protokube.tar.gz ${BAZELIMAGES}/protokube.tar.gz
cp -fp bazel-bin/images/protokube.tar.gz.hashes.sha1 ${BAZELIMAGES}/protokube.tar.gz.sha1
cp -fp bazel-bin/images/protokube.tar.gz.hashes.sha256 ${BAZELIMAGES}/protokube.tar.gz.sha256
cp -fp bazel-bin/images/protokube.tar.gz.sha1 ${BAZELIMAGES}/protokube.tar.gz.sha1
cp -fp bazel-bin/images/protokube.tar.gz.sha256 ${BAZELIMAGES}/protokube.tar.gz.sha256
.PHONY: bazel-kops-controller-export
bazel-kops-controller-export:

View File

@ -1,7 +1,7 @@
def _impl(ctx):
in_file = ctx.file.src
basename = ctx.attr.name
basename = ctx.attr.src.label.name
out_sha1 = ctx.actions.declare_file("%s.sha1" % basename)
ctx.actions.run(
executable = ctx.executable._cmd_sha1,
@ -22,6 +22,12 @@ def _impl(ctx):
files = depset([out_sha1, out_sha256]),
)
def _get_outputs(src):
return {
"sha1": src.name + ".sha1",
"sha256": src.name + ".sha256",
}
hashes = rule(
implementation = _impl,
attrs = {
@ -39,10 +45,7 @@ hashes = rule(
cfg = "host",
),
},
# It looks like we have to do this so that we can reference these outputs in other files
# Not entirely sure why, as we can just generate everything ... maybe a bazel bug?
outputs = {
"sha1": "%{name}.sha1",
"sha256": "%{name}.sha256",
},
# We have to do this so that we can reference these outputs in other files
# https://stackoverflow.com/a/50667861
outputs = _get_outputs,
)