From 8d92c6fed01af61a5bbfca786357d49bd9290cb3 Mon Sep 17 00:00:00 2001 From: Javier Maestro Date: Tue, 3 Dec 2024 18:40:41 +0000 Subject: [PATCH] feat: add more convenience targets Add platform-aware :data and :control convenience targets at the top of the package repo so that we can use `@//:data` directly (see changes to examples/debian_snapshot/BUILD). Also, add :deps to complement :data. --- apt/private/deb_translate_lock.bzl | 30 ++++++++++------------------ apt/private/package.BUILD.tmpl | 17 +++++++++++++--- e2e/smoke/BUILD | 5 +---- examples/debian_snapshot/BUILD.bazel | 5 +---- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/apt/private/deb_translate_lock.bzl b/apt/private/deb_translate_lock.bzl index 6f2f6d4..fdef848 100644 --- a/apt/private/deb_translate_lock.bzl +++ b/apt/private/deb_translate_lock.bzl @@ -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." @@ -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"]) @@ -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 }), ), diff --git a/apt/private/package.BUILD.tmpl b/apt/private/package.BUILD.tmpl index 9c3dd61..8810a96 100644 --- a/apt/private/package.BUILD.tmpl +++ b/apt/private/package.BUILD.tmpl @@ -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"] ) \ No newline at end of file diff --git a/e2e/smoke/BUILD b/e2e/smoke/BUILD index 9097566..269688e 100644 --- a/e2e/smoke/BUILD +++ b/e2e/smoke/BUILD @@ -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 = [ diff --git a/examples/debian_snapshot/BUILD.bazel b/examples/debian_snapshot/BUILD.bazel index 6a42e8b..1d10b0f 100644 --- a/examples/debian_snapshot/BUILD.bazel +++ b/examples/debian_snapshot/BUILD.bazel @@ -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(