From d5a4d37da883ab2e47d95fb0dd545f6ea7a3ffae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Tue, 29 Sep 2026 11:02:53 +0200 Subject: [PATCH] pkg_deb: add installed_size_file attribute Lets installed_size be supplied from a file, so callers can compute it themselves. --- docs/latest.md | 11 ++++++----- pkg/private/deb/deb.bzl | 15 +++++++++++++-- tests/deb/BUILD | 11 +++++++++++ tests/deb/installed_size_file | 1 + tests/deb/pkg_deb_test.py | 8 ++++++++ 5 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 tests/deb/installed_size_file diff --git a/docs/latest.md b/docs/latest.md index d6f5dbb5..c5422a92 100755 --- a/docs/latest.md +++ b/docs/latest.md @@ -95,10 +95,10 @@ load("@rules_pkg//pkg/private/deb:deb.bzl", "pkg_deb") pkg_deb(name, data, out, architecture, architecture_file, breaks, built_using, built_using_file, changelog, conffiles, conffiles_file, config, conflicts, depends, depends_file, description, description_file, distribution, enhances, homepage, - installed_size, license, maintainer, md5sums, package, package_file_name, - package_variables, postinst, postrm, predepends, preinst, prerm, priority, provides, - provides_file, recommends, replaces, replaces_file, section, suggests, templates, - triggers, urgency, version, version_file) + installed_size, installed_size_file, license, maintainer, md5sums, package, + package_file_name, package_variables, postinst, postrm, predepends, preinst, prerm, + priority, provides, provides_file, recommends, replaces, replaces_file, section, + suggests, templates, triggers, urgency, version, version_file) Create a Debian package. @@ -137,7 +137,8 @@ include both. If you need downstream rule to specifically depend on only the .de | distribution | "distribution: See http://www.debian.org/doc/debian-policy. | String | optional | `"unstable"` | | enhances | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | `[]` | | homepage | The homepage of the project. | String | optional | `""` | -| installed_size | The approximate total size (in KiB) of the package's installed files. Corresponds to the Installed-Size field in the control file. See https://www.debian.org/doc/debian-policy/ch-controlfields.html#installed-size. | String | optional | `""` | +| installed_size | The approximate total size (in KiB) of the package's installed files. Corresponds to the Installed-Size field in the control file. See https://www.debian.org/doc/debian-policy/ch-controlfields.html#installed-size. Mutually exclusive with `installed_size_file`. | String | optional | `""` | +| installed_size_file | File that contains the approximate total size (in KiB) of the package's installed files. Mutually exclusive with `installed_size`. | Label | optional | `None` | | license | The license of the project. | String | optional | `""` | | maintainer | The maintainer of the package. | String | required | | | md5sums | A file listing md5 checksums of files in the data archive. This file is optional. See https://manpages.debian.org/bookworm/dpkg-dev/deb-md5sums.5.en.html. | Label | optional | `None` | diff --git a/pkg/private/deb/deb.bzl b/pkg/private/deb/deb.bzl index 169b007a..7ef1eaf6 100644 --- a/pkg/private/deb/deb.bzl +++ b/pkg/private/deb/deb.bzl @@ -137,7 +137,12 @@ def _pkg_deb_impl(ctx): for d in ctx.attr.depends: args.add("--depends", substitute_package_variables(ctx, d)) - if ctx.attr.installed_size: + if ctx.attr.installed_size_file: + if ctx.attr.installed_size: + fail("Both installed_size and installed_size_file attributes were specified") + args.add("--installed_size", "@" + ctx.file.installed_size_file.path) + files.append(ctx.file.installed_size_file) + elif ctx.attr.installed_size: args.add("--installed_size", substitute_package_variables(ctx, ctx.attr.installed_size)) if ctx.attr.priority: args.add("--priority", substitute_package_variables(ctx, ctx.attr.priority)) @@ -346,7 +351,13 @@ See https://www.debian.org/doc/debian-policy/ch-files.html#s-config-files.""", "installed_size": attr.string( doc = """The approximate total size (in KiB) of the package's installed files. Corresponds to the Installed-Size field in the control file. - See https://www.debian.org/doc/debian-policy/ch-controlfields.html#installed-size.""", + See https://www.debian.org/doc/debian-policy/ch-controlfields.html#installed-size. + Mutually exclusive with `installed_size_file`.""", + ), + "installed_size_file": attr.label( + doc = """File that contains the approximate total size (in KiB) of the + package's installed files. Mutually exclusive with `installed_size`.""", + allow_single_file = True, ), "license": attr.string(doc = """The license of the project."""), "breaks": attr.string_list( diff --git a/tests/deb/BUILD b/tests/deb/BUILD index f7e947f4..305d3860 100644 --- a/tests/deb/BUILD +++ b/tests/deb/BUILD @@ -101,6 +101,16 @@ pkg_deb( version = "4.5.6", ) +pkg_deb( + name = "test_deb_installed_size_file", + data = ":tar_input", + description = "installed_size_file test package", + installed_size_file = "installed_size_file", + maintainer = "someone@somewhere.com", + package = "fizzbuzz-installed-size-file", + version = "1.0.0", +) + py_test( name = "pkg_deb_test", size = "medium", @@ -110,6 +120,7 @@ py_test( data = [ # The target includes both the .deb and .changes files in DefaultInfo ":test_deb", + ":test_deb_installed_size_file", ], imports = ["../.."], python_version = "PY3", diff --git a/tests/deb/installed_size_file b/tests/deb/installed_size_file new file mode 100644 index 00000000..9c9ddc2c --- /dev/null +++ b/tests/deb/installed_size_file @@ -0,0 +1 @@ +5678 diff --git a/tests/deb/pkg_deb_test.py b/tests/deb/pkg_deb_test.py index 8c89d5d6..120ada1a 100644 --- a/tests/deb/pkg_deb_test.py +++ b/tests/deb/pkg_deb_test.py @@ -65,6 +65,9 @@ def setUp(self): # Note: Rlocation requires forward slashes. os.path.join() will not work. self.deb_path = self.runfiles.Rlocation('rules_pkg/tests/deb/fizzbuzz_4.5.6_all.deb') self.deb_file = DebInspect(self.deb_path) + self.installed_size_file_deb_path = self.runfiles.Rlocation( + 'rules_pkg/tests/deb/fizzbuzz-installed-size-file_1.0.0_all.deb') + self.installed_size_file_deb_file = DebInspect(self.installed_size_file_deb_path) def assert_control_content(self, expected, match_order=False): self.assert_tar_stream_content( @@ -172,6 +175,11 @@ def test_description(self): if control.find(field) < 0: self.fail('Missing control field: <%s> in <%s>' % (field, control)) + def test_installed_size_file(self): + control = self.installed_size_file_deb_file.get_deb_ctl_file('control') + if control.find('Installed-Size: 5678') < 0: + self.fail('Missing control field: in <%s>' % control) + def test_control_files(self): expected = [ {'name': './changelog', 'mode': 0o644},