-
-
Notifications
You must be signed in to change notification settings - Fork 530
/
Copy pathhash.bzl
48 lines (42 loc) · 1.46 KB
/
hash.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# buildifier: disable=module-docstring
def _impl(ctx):
# Create actions to generate the three output files.
# Actions are run only when the corresponding file is requested.
ctx.actions.run_shell(
outputs = [ctx.outputs.md5],
inputs = [ctx.file.src],
use_default_shell_env = True,
command = "md5sum {} > {}".format(ctx.file.src.path, ctx.outputs.md5.path),
)
ctx.actions.run_shell(
outputs = [ctx.outputs.sha1],
inputs = [ctx.file.src],
use_default_shell_env = True,
command = "sha1sum {} > {}".format(ctx.file.src.path, ctx.outputs.sha1.path),
)
ctx.actions.run_shell(
outputs = [ctx.outputs.sha256],
inputs = [ctx.file.src],
use_default_shell_env = True,
command = "sha256sum {} > {}".format(ctx.file.src.path, ctx.outputs.sha256.path),
)
# By default (if you run `bazel build` on this target, or if you use it as a
# source of another target), only the sha256 is computed.
return DefaultInfo(files = depset([ctx.outputs.sha256]))
_hashes = rule(
implementation = _impl,
attrs = {
"src": attr.label(mandatory = True, allow_single_file = True),
"md5": attr.output(),
"sha1": attr.output(),
"sha256": attr.output(),
},
)
def hashes(**kwargs):
name = kwargs["name"]
_hashes(
md5 = "%s.md5" % name,
sha1 = "%s.sha1" % name,
sha256 = "%s.sha256" % name,
**kwargs
)