-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathhashes.bzl
36 lines (32 loc) · 966 Bytes
/
hashes.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
def _impl(ctx):
in_file = ctx.file.src
basename = ctx.attr.src.label.name
out_sha256 = ctx.actions.declare_file("%s.sha256" % basename)
ctx.actions.run(
executable = ctx.executable._cmd_sha256,
outputs = [out_sha256],
inputs = [in_file],
arguments = [in_file.path, out_sha256.path],
)
return DefaultInfo(
files = depset([out_sha256]),
)
def _get_outputs(src):
return {
"sha256": src.name + ".sha256",
}
hashes = rule(
implementation = _impl,
attrs = {
"src": attr.label(mandatory = True, allow_single_file = True),
"_cmd_sha256": attr.label(
default = Label("//tools:sha256"),
allow_single_file = True,
executable = True,
cfg = "host",
),
},
# We have to do this so that we can reference these outputs in other files
# https://stackoverflow.com/a/50667861
outputs = _get_outputs,
)