-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patharchive.bzl
31 lines (27 loc) · 1018 Bytes
/
archive.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
load("@bazel_ipfs//:tools_repo.bzl", "attr_ipfs")
EXIT_SUCCESS = 0
def _ref(r_ctx):
if (not (r_ctx.attr.ref or r_ctx.attr.ref_file)):
fail("must specify one of ref or ref_file")
if (r_ctx.attr.ref and r_ctx.attr.ref_file):
fail("ref and ref_file are mutually exclusive")
return r_ctx.attr.ref if r_ctx.attr.ref else r_ctx.read(r_ctx.attr.ref_file).strip()
def _ipfs_archive_impl(r_ctx):
ipfs = r_ctx.path(r_ctx.attr._ipfs)
ref = _ref(r_ctx)
archive = ref + "." + r_ctx.attr.extension
command = [str(ipfs), "get", "-o", archive, ref]
e_res = r_ctx.execute(command)
if e_res.return_code != EXIT_SUCCESS:
fail(" ".join(command) + " failed: " + e_res.stderr)
r_ctx.extract(archive)
r_ctx.delete(archive)
ipfs_archive = repository_rule(
implementation = _ipfs_archive_impl,
attrs = {
"ref": attr.string(),
"ref_file": attr.label(),
"extension": attr.string(mandatory = True),
"_ipfs": attr_ipfs(attr),
},
)