Skip to content

Commit

Permalink
feat: add more convenience targets
Browse files Browse the repository at this point in the history
Add platform-aware :data and :control convenience targets at the top of
the package repo so that we can use `@<REPO>//<PACKAGE>:data` directly
(see changes to examples/debian_snapshot/BUILD).

Also, add :deps to complement :data.
  • Loading branch information
jjmaestro committed Dec 5, 2024
1 parent 7b342e2 commit 8d92c6f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
30 changes: 11 additions & 19 deletions apt/private/deb_translate_lock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ _DEB_IMPORT_TMPL = '''\
)
'''

_PACKAGE_TEMPLATE = """\
alias(
name = "{target_name}",
actual = select({data_targets}),
visibility = ["//visibility:public"],
)
alias(
name = "control",
actual = select({control_targets}),
visibility = ["//visibility:public"],
)
"""

_ROOT_BUILD_TMPL = """\
"Generated by rules_distroless. DO NOT EDIT."
Expand Down Expand Up @@ -150,6 +136,8 @@ def _deb_translate_lock_impl(rctx):
"%s/%s/BUILD.bazel" % (package["name"], package["arch"]),
package_template.format(
target_name = package["arch"],
data_targets = '"@%s//:data"' % repo_name,
control_targets = '"@%s//:control"' % repo_name,
src = '"@%s//:data"' % repo_name,
deps = starlark_codegen_utils.to_list_attr([
"//%s/%s" % (dep["name"], package["arch"])
Expand All @@ -167,14 +155,18 @@ def _deb_translate_lock_impl(rctx):
for (package) in lockf.packages():
rctx.file(
"%s/BUILD.bazel" % (package["name"]),
_PACKAGE_TEMPLATE.format(
package_template.format(
target_name = package["name"],
data_targets = starlark_codegen_utils.to_dict_attr({
"//:linux_%s" % arch: "//%s/%s" % (package["name"], arch)
data_targets = "select(%s)" % starlark_codegen_utils.to_dict_attr({
"//:linux_%s" % arch: "//%s/%s:data" % (package["name"], package["arch"])
for arch in architectures._values
}),
control_targets = "select(%s)" % starlark_codegen_utils.to_dict_attr({
"//:linux_%s" % arch: "//%s/%s:control" % (package["name"], package["arch"])
for arch in architectures._values
}),
control_targets = starlark_codegen_utils.to_dict_attr({
"//:linux_%s" % arch: "//%s/%s:control" % (package["name"], arch)
deps = "select(%s)" % starlark_codegen_utils.to_dict_list_attr({
"//:linux_%s" % arch: ["//%s/%s:deps" % (package["name"], package["arch"])]
for arch in architectures._values
}),
),
Expand Down
17 changes: 14 additions & 3 deletions apt/private/package.BUILD.tmpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
"""Generated by rules_distroless. DO NOT EDIT."""

alias(
name = "data",
actual = "@{repo_name}//:data",
actual = {data_targets},
visibility = ["//visibility:public"],
)

alias(
name = "control",
actual = "@{repo_name}//:control",
actual = {control_targets},
visibility = ["//visibility:public"],
)

filegroup(
name = "deps",
srcs = {deps},
visibility = ["//visibility:public"],
)

filegroup(
name = "{target_name}",
srcs = [
":deps",
":data",
],
visibility = ["//visibility:public"],
srcs = {deps} + [":data"]
)
5 changes: 1 addition & 4 deletions e2e/smoke/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ tar(

cacerts(
name = "cacerts",
package = select({
"@platforms//cpu:arm64": "@bullseye//ca-certificates/arm64:data",
"@platforms//cpu:x86_64": "@bullseye//ca-certificates/amd64:data",
}),
package = "@bullseye//ca-certificates:data",
)

PACKAGES = [
Expand Down
5 changes: 1 addition & 4 deletions examples/debian_snapshot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ tar(

cacerts(
name = "cacerts",
package = select({
"@platforms//cpu:arm64": "@bullseye//ca-certificates/arm64:data",
"@platforms//cpu:x86_64": "@bullseye//ca-certificates/amd64:data",
}),
package = "@bullseye//ca-certificates:data",
)

oci_image(
Expand Down

0 comments on commit 8d92c6f

Please sign in to comment.