Skip to content

Commit

Permalink
feat: add more convenience targets (#121)
Browse files Browse the repository at this point in the history
Mirror the "inner" (per-arch) :data and :control convenience targets to
platform-aware targets at the top of the package repo so that we can use
`@<REPO>//<PACKAGE>:data` directly (see changes to
examples/debian_snapshot/BUILD).
  • Loading branch information
jjmaestro authored Jan 22, 2025
1 parent dd3f02f commit 2354eb3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
22 changes: 18 additions & 4 deletions apt/private/deb_translate_lock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ _DEB_IMPORT_TMPL = '''\
)
'''

_PACKAGE_TEMPLATE = """\
_PACKAGE_TEMPLATE = '''\
"""Generated by rules_distroless. DO NOT EDIT."""
alias(
name = "{target_name}",
name = "data",
actual = select({data_targets}),
visibility = ["//visibility:public"],
)
Expand All @@ -34,7 +36,13 @@ alias(
actual = select({control_targets}),
visibility = ["//visibility:public"],
)
"""
filegroup(
name = "{target_name}",
srcs = select({deps}) + [":data"],
visibility = ["//visibility:public"],
)
'''

_ROOT_BUILD_TMPL = """\
"Generated by rules_distroless. DO NOT EDIT."
Expand Down Expand Up @@ -179,6 +187,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 @@ -199,13 +209,17 @@ def _deb_translate_lock_impl(rctx):
_PACKAGE_TEMPLATE.format(
target_name = package_name,
data_targets = starlark_codegen_utils.to_dict_attr({
"//:linux_%s" % arch: "//%s/%s" % (package_name, arch)
"//:linux_%s" % arch: "//%s/%s:data" % (package_name, arch)
for arch in package_archs
}),
control_targets = starlark_codegen_utils.to_dict_attr({
"//:linux_%s" % arch: "//%s/%s:control" % (package_name, arch)
for arch in package_archs
}),
deps = starlark_codegen_utils.to_dict_list_attr({
"//:linux_%s" % arch: ["//%s/%s" % (package_name, arch)]
for arch in package_archs
}),
),
)

Expand Down
8 changes: 5 additions & 3 deletions apt/private/package.BUILD.tmpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"""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 = "{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 @@ -58,10 +58,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
5 changes: 1 addition & 4 deletions examples/debian_snapshot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,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 2354eb3

Please sign in to comment.