From 21e1cccbc36cc2995b9f31616783da5533a91c47 Mon Sep 17 00:00:00 2001 From: Tom van der Woerdt Date: Wed, 24 Apr 2024 22:14:25 +0200 Subject: Add support for "Epoch" attributes in RPMs (#858) --- pkg/rpm_pfg.bzl | 11 +++++++++++ tests/rpm/BUILD | 27 +++++++++++++++++++++++++++ tests/rpm/pkg_rpm_basic_test.py | 7 +++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/pkg/rpm_pfg.bzl b/pkg/rpm_pfg.bzl index b3eac5c..99b84bc 100644 --- a/pkg/rpm_pfg.bzl +++ b/pkg/rpm_pfg.bzl @@ -48,6 +48,7 @@ PackageSubRPMInfo = provider( "description": "Multi-line description of this subpackage", "post_scriptlet": "RPM `$post` scriplet for this subpackage", "architecture": "Subpackage architecture", + "epoch": "RPM `Epoch` tag for this subpackage", "version": "RPM `Version` tag for this subpackage", "requires": "List of RPM capability expressions that this package requires", "provides": "List of RPM capability expressions that this package provides", @@ -336,6 +337,9 @@ def _process_subrpm(ctx, rpm_name, rpm_info, rpm_ctx, debuginfo_type): if rpm_info.architecture: rpm_lines += ["BuildArch: %s" % rpm_info.architecture] + if rpm_info.epoch: + rpm_lines += ["Epoch: %s" % rpm_info.epoch] + if rpm_info.version: rpm_lines += ["Version: %s" % rpm_info.version] @@ -530,6 +534,8 @@ def _pkg_rpm_impl(ctx): elif ctx.attr.source_date_epoch >= 0: rpm_ctx.make_rpm_args.append("--source_date_epoch=" + str(ctx.attr.source_date_epoch)) + if ctx.attr.epoch: + preamble_pieces.append("Epoch: " + ctx.attr.epoch) if ctx.attr.summary: preamble_pieces.append("Summary: " + ctx.attr.summary) if ctx.attr.url: @@ -921,6 +927,9 @@ pkg_rpm = rule( doc = "See 'Common Attributes' in the rules_pkg reference", providers = [PackageVariablesInfo], ), + "epoch": attr.string( + doc = """Optional; RPM "Epoch" tag.""", + ), "version": attr.string( doc = """RPM "Version" tag. @@ -1268,6 +1277,7 @@ def _pkg_sub_rpm_impl(ctx): description = ctx.attr.description, post_scriptlet = ctx.attr.post_scriptlet, architecture = ctx.attr.architecture, + epoch = ctx.attr.epoch, version = ctx.attr.version, requires = ctx.attr.requires, provides = ctx.attr.provides, @@ -1304,6 +1314,7 @@ pkg_sub_rpm = rule( "description": attr.string(doc = "Multi-line description of this subrpm"), "post_scriptlet": attr.string(doc = "RPM `%post` scriplet for this subrpm"), "architecture": attr.string(doc = "Sub RPM architecture"), + "epoch": attr.string(doc = "RPM `Epoch` tag for this subrpm"), "version": attr.string(doc = "RPM `Version` tag for this subrpm"), "requires": attr.string_list(doc = "List of RPM capability expressions that this package requires"), "provides": attr.string_list(doc = "List of RPM capability expressions that this package provides"), diff --git a/tests/rpm/BUILD b/tests/rpm/BUILD index b35c1ed..7aeaa8f 100644 --- a/tests/rpm/BUILD +++ b/tests/rpm/BUILD @@ -280,6 +280,7 @@ pkg_rpm( architecture = "noarch", conflicts = ["not-a-test"], description = """pkg_rpm test rpm description""", + epoch = "1", license = "Apache 2.0", post_scriptlet_file = ":post", postun_scriptlet_file = ":postun", @@ -295,6 +296,31 @@ pkg_rpm( version_file = ":version_file", ) +# Like the first one, except we set an epoch +pkg_rpm( + name = "test_rpm_epoch", + srcs = [ + ":test_pfg", + ], + architecture = "noarch", + conflicts = ["not-a-test"], + description = """pkg_rpm test rpm description""", + epoch = "1", + license = "Apache 2.0", + post_scriptlet = _POST_SCRIPTLET, + postun_scriptlet = _POSTUN_SCRIPTLET, + pre_scriptlet = _PRE_SCRIPTLET, + preun_scriptlet = _PREUN_SCRIPTLET, + posttrans_scriptlet = _POSTTRANS_SCRIPTLET, + provides = ["test"], + release = _RELEASE, + requires = ["test-lib > 1.0"], + requires_contextual = {"preun": ["bash"]}, + spec_template = "template-test.spec.tpl", + summary = "pkg_rpm test rpm summary", + version = _VERSION, +) + ############################################################################ # Test RPM metadata -- used to verify RPM contents in tests ############################################################################ @@ -407,6 +433,7 @@ sh_library( ":test_rpm_metadata", ":test_rpm_scriptlets_files", ":test_rpm_release_version_files", + ":test_rpm_epoch", ], ) diff --git a/tests/rpm/pkg_rpm_basic_test.py b/tests/rpm/pkg_rpm_basic_test.py index 8b29934..ab5c49e 100644 --- a/tests/rpm/pkg_rpm_basic_test.py +++ b/tests/rpm/pkg_rpm_basic_test.py @@ -52,6 +52,8 @@ class PkgRpmBasicTest(unittest.TestCase): "rules_pkg/tests/rpm/test_rpm_scriptlets_files-1.1.1-2222.noarch.rpm") self.test_rpm_release_version_files = self.runfiles.Rlocation( "rules_pkg/tests/rpm/test_rpm_release_version_files--.noarch.rpm") + self.test_rpm_epoch = self.runfiles.Rlocation( + "rules_pkg/tests/rpm/test_rpm_epoch-1.1.1-2222.noarch.rpm") self.maxDiff = None def test_scriptlet_content(self): @@ -83,6 +85,7 @@ echo posttrans for rpm, fields in [ (self.test_rpm_path, {"NAME": b"test_rpm"}), (self.test_rpm_release_version_files, {"NAME": b"test_rpm_release_version_files"}), + (self.test_rpm_epoch, {"NAME": b"test_rpm_epoch", "EPOCH": b"1"}), ]: fields.update(common_fields) for fieldname, expected in fields.items(): @@ -176,7 +179,7 @@ echo posttrans # - "interp" for scriptlet interpreter dependencies # - "postun" for dependencies of the "postun" scriptlet # - "manual" for values that are explicitly specified - ":%{{{tag}FLAGS:deptype}}" + ":%{{{tag}FLAGS!deptype}}" "\n]" ).format(tag = tag) @@ -190,7 +193,7 @@ echo posttrans sio = io.StringIO(rpm_output.decode('utf-8')) rpm_output_reader = csv.DictReader( - sio, delimiter=':', fieldnames=rpm_queryformat_fieldnames) + sio, delimiter='!', fieldnames=rpm_queryformat_fieldnames) # Get everything in the same order as the read-in metadata file rpm_outputs_filtered_unsorted = [line for line in rpm_output_reader -- cgit v1.2.3