This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
forked from GoogleContainerTools/distroless
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdpkg.bzl
74 lines (66 loc) · 2.61 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
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 = [
# dpkg_parser.par must be built separately beforehand (bazel build ... //package_manager:dpkg_parser.par)
str(repository_ctx.path(Label("//:WORKSPACE")).dirname) + "/bazel-bin/package_manager/dpkg_parser.par",
"--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,
"--versionsfile",
str(repository_ctx.path(Label("//:WORKSPACE")).dirname) + "/" + repository_ctx.attr.name + ".versions",
]
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(),
},
)
def _dpkg_src_impl(repository_ctx):
repository_ctx.file("file/BUILD", """
package(default_visibility = ["//visibility:public"])
exports_files(["Packages.json", "os_release.tar"])
""")
args = [
# dpkg_parser.par must be built separately beforehand (bazel build ... //package_manager:dpkg_parser.par)
str(repository_ctx.path(Label("//:WORKSPACE")).dirname) + "/bazel-bin/package_manager/dpkg_parser.par",
"--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(),
},
)
def dpkg_list(**kwargs):
_dpkg_list(**kwargs)
def dpkg_src(**kwargs):
_dpkg_src(**kwargs)