forked from GoogleContainerTools/distroless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dpkg.bzl
80 lines (72 loc) · 2.48 KB
/
dpkg.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def _dpkg_list_impl(repository_ctx):
repository_ctx.file("file/BUILD", """
package(default_visibility = ["//visibility:public"])
deb_files = glob(["*.deb"])
exports_files(deb_files + ["packages.bzl"])
""")
args = [
repository_ctx.path(repository_ctx.attr._dpkg_parser),
"--package-files",
",".join([str(repository_ctx.path(src_path)) for src_path in repository_ctx.attr.sources]),
"--packages",
",".join(repository_ctx.attr.packages),
"--workspace-name",
repository_ctx.name,
]
result = repository_ctx.execute(args)
if result.return_code:
fail("dpkg_parser command failed: %s (%s)" % (result.stderr, " ".join([str(a) for a in args])))
_dpkg_list = repository_rule(
_dpkg_list_impl,
attrs = {
"sources": attr.label_list(
allow_files = True,
),
"packages": attr.string_list(),
"_dpkg_parser": attr.label(
executable = True,
default = Label("@dpkg_parser//file:downloaded"),
cfg = "host",
),
},
)
def _dpkg_src_impl(repository_ctx):
repository_ctx.file("file/BUILD", """
package(default_visibility = ["//visibility:public"])
exports_files(["Packages.json", "os_release.tar"])
""")
args = [
repository_ctx.path(repository_ctx.attr._dpkg_parser),
"--download-and-extract-only=True",
"--mirror-url=" + repository_ctx.attr.url,
"--arch=" + repository_ctx.attr.arch,
"--distro=" + repository_ctx.attr.distro,
"--snapshot=" + repository_ctx.attr.snapshot,
"--packages-gz-url=" + repository_ctx.attr.packages_gz_url,
"--package-prefix=" + repository_ctx.attr.package_prefix,
"--sha256=" + repository_ctx.attr.sha256,
]
result = repository_ctx.execute(args)
if result.return_code:
fail("dpkg_parser command failed: %s (%s)" % (result.stderr, " ".join([str(a) for a in args])))
_dpkg_src = repository_rule(
_dpkg_src_impl,
attrs = {
"url": attr.string(),
"arch": attr.string(),
"distro": attr.string(),
"snapshot": attr.string(),
"packages_gz_url": attr.string(),
"package_prefix": attr.string(),
"sha256": attr.string(),
"_dpkg_parser": attr.label(
executable = True,
default = Label("@dpkg_parser//file:downloaded"),
cfg = "host",
),
},
)
def dpkg_list(**kwargs):
_dpkg_list(**kwargs)
def dpkg_src(**kwargs):
_dpkg_src(**kwargs)