From 4cb8671fe41e55f1c868ffb85078425c5c2deb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 22 Sep 2022 16:17:53 +0200 Subject: [PATCH] Allow disabling inheriting ExcludeArch to noarch packages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copying ExcludeArch/ExclusiveArch from source rpm to noarch is an easy option to block shipping that particular noarch package from a certain architecture. However, there is no way to bypass it, and it is rather confusing and not discoverable. An alternative way to remove an unwanted package is to use the good old `filter_packages`, which has enough granularity to remove pretty much anything from anywhere. The only downside is that it requires a change in configuration, so it can't be done by a packager directly from a spec file. When we decide to break backwards compatibility, this option should be removed and the entire ExcludeArch/ExclusiveArch inheritance removed completely. JIRA: ENGCMP-2606 Signed-off-by: Lubomír Sedlář (cherry picked from commit ab508c151140f8e392fc9f5505653103e52060f3) --- doc/configuration.rst | 10 ++++++++++ pungi/checks.py | 4 ++++ pungi/phases/pkgset/common.py | 9 +++++++-- pungi/phases/pkgset/pkgsets.py | 23 +++++++++++++++++++---- tests/test_pkgset_common.py | 12 +++++++++--- tests/test_pkgset_pkgsets.py | 22 ++++++++++++++++++++++ 6 files changed, 71 insertions(+), 9 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index c0119d6d..80c0c962 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -581,6 +581,16 @@ Options with everything. Set this option to ``False`` to ignore ``noarch`` in ``ExclusiveArch`` and always consider only binary architectures. +**pkgset_inherit_exclusive_arch_to_noarch** = True + (*bool*) -- When set to ``True``, the value of ``ExclusiveArch`` or + ``ExcludeArch`` will be copied from source rpm to all its noarch packages. + That will than limit which architectures the noarch packages can be + included in. + + By setting this option to ``False`` this step is skipped, and noarch + packages will by default land in all architectures. They can still be + excluded by listing them in a relevant section of ``filter_packages``. + **pkgset_allow_reuse** = True (*bool*) -- When set to ``True``, *Pungi* will try to reuse pkgset data from the old composes specified by ``--old-composes``. When enabled, this diff --git a/pungi/checks.py b/pungi/checks.py index 5d11fb7b..e3415831 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -865,6 +865,10 @@ def make_schema(): "type": "boolean", "default": True, }, + "pkgset_inherit_exclusive_arch_to_noarch": { + "type": "boolean", + "default": True, + }, "pkgset_scratch_modules": { "type": "object", "patternProperties": { diff --git a/pungi/phases/pkgset/common.py b/pungi/phases/pkgset/common.py index 14dad789..800eaa6c 100644 --- a/pungi/phases/pkgset/common.py +++ b/pungi/phases/pkgset/common.py @@ -38,12 +38,17 @@ from pungi.phases.createrepo import add_modular_metadata def populate_arch_pkgsets(compose, path_prefix, global_pkgset): result = {} - exclusive_noarch = compose.conf["pkgset_exclusive_arch_considers_noarch"] + for arch in compose.get_arches(): compose.log_info("Populating package set for arch: %s", arch) is_multilib = is_arch_multilib(compose.conf, arch) arches = get_valid_arches(arch, is_multilib, add_src=True) - pkgset = global_pkgset.subset(arch, arches, exclusive_noarch=exclusive_noarch) + pkgset = global_pkgset.subset( + arch, + arches, + exclusive_noarch=compose.conf["pkgset_exclusive_arch_considers_noarch"], + inherit_to_noarch=compose.conf["pkgset_inherit_exclusive_arch_to_noarch"], + ) pkgset.save_file_list( compose.paths.work.package_list(arch=arch, pkgset=global_pkgset), remove_path_prefix=path_prefix, diff --git a/pungi/phases/pkgset/pkgsets.py b/pungi/phases/pkgset/pkgsets.py index d917b63b..293bd5b0 100644 --- a/pungi/phases/pkgset/pkgsets.py +++ b/pungi/phases/pkgset/pkgsets.py @@ -211,16 +211,31 @@ class PackageSetBase(kobo.log.LoggingBase): return self.rpms_by_arch - def subset(self, primary_arch, arch_list, exclusive_noarch=True): + def subset( + self, primary_arch, arch_list, exclusive_noarch=True, inherit_to_noarch=True + ): """Create a subset of this package set that only includes packages compatible with""" pkgset = PackageSetBase( self.name, self.sigkey_ordering, logger=self._logger, arches=arch_list ) - pkgset.merge(self, primary_arch, arch_list, exclusive_noarch=exclusive_noarch) + pkgset.merge( + self, + primary_arch, + arch_list, + exclusive_noarch=exclusive_noarch, + inherit_to_noarch=inherit_to_noarch, + ) return pkgset - def merge(self, other, primary_arch, arch_list, exclusive_noarch=True): + def merge( + self, + other, + primary_arch, + arch_list, + exclusive_noarch=True, + inherit_to_noarch=True, + ): """ Merge ``other`` package set into this instance. """ @@ -259,7 +274,7 @@ class PackageSetBase(kobo.log.LoggingBase): if i.file_path in self.file_cache: # TODO: test if it really works continue - if exclusivearch_list and arch == "noarch": + if inherit_to_noarch and exclusivearch_list and arch == "noarch": if is_excluded(i, exclusivearch_list, logger=self._logger): continue diff --git a/tests/test_pkgset_common.py b/tests/test_pkgset_common.py index 2fce72ff..7bd525ec 100755 --- a/tests/test_pkgset_common.py +++ b/tests/test_pkgset_common.py @@ -47,7 +47,7 @@ class TestMaterializedPkgsetCreate(helpers.PungiTestCase): pkgset.name = name pkgset.reuse = None - def mock_subset(primary, arch_list, exclusive_noarch): + def mock_subset(primary, arch_list, **kwargs): self.subsets[primary] = mock.Mock() return self.subsets[primary] @@ -73,10 +73,16 @@ class TestMaterializedPkgsetCreate(helpers.PungiTestCase): self.assertEqual(result["amd64"], self.subsets["amd64"]) self.pkgset.subset.assert_any_call( - "x86_64", ["x86_64", "noarch", "src"], exclusive_noarch=True + "x86_64", + ["x86_64", "noarch", "src"], + exclusive_noarch=True, + inherit_to_noarch=True, ) self.pkgset.subset.assert_any_call( - "amd64", ["amd64", "x86_64", "noarch", "src"], exclusive_noarch=True + "amd64", + ["amd64", "x86_64", "noarch", "src"], + exclusive_noarch=True, + inherit_to_noarch=True, ) for arch, pkgset in result.package_sets.items(): diff --git a/tests/test_pkgset_pkgsets.py b/tests/test_pkgset_pkgsets.py index d0f46cc5..55295167 100644 --- a/tests/test_pkgset_pkgsets.py +++ b/tests/test_pkgset_pkgsets.py @@ -1181,6 +1181,28 @@ class TestMergePackageSets(PkgsetCompareMixin, unittest.TestCase): first.rpms_by_arch, {"i686": ["rpms/bash@4.3.42@4.fc24@i686"], "noarch": []} ) + def test_merge_doesnt_exclude_noarch_exclude_arch_when_configured(self): + first = pkgsets.PackageSetBase("first", [None]) + second = pkgsets.PackageSetBase("second", [None]) + + pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686") + first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) + + pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@noarch") + pkg.excludearch = ["i686"] + second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) + + first.merge(second, "i386", ["i686", "noarch"], inherit_to_noarch=False) + + print(first.rpms_by_arch) + self.assertPkgsetEqual( + first.rpms_by_arch, + { + "i686": ["rpms/bash@4.3.42@4.fc24@i686"], + "noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"], + }, + ) + def test_merge_excludes_noarch_exclusive_arch(self): first = pkgsets.PackageSetBase("first", [None]) second = pkgsets.PackageSetBase("second", [None])