diff --git a/pungi/phases/gather/sources/source_module.py b/pungi/phases/gather/sources/source_module.py index 969a1fb3..89e87bed 100644 --- a/pungi/phases/gather/sources/source_module.py +++ b/pungi/phases/gather/sources/source_module.py @@ -49,10 +49,9 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase): "support for modules is disabled\n") return packages, groups - # TODO: Enable multilib here and handle "multilib" field in the - # components part of modulemd. We currently cannot do it, because - # it is not clear what is semantic of that modulemd section. - compatible_arches = pungi.arch.get_compatible_arches(arch, multilib=False) + compatible_arches = pungi.arch.get_compatible_arches(arch, multilib=True) + multilib_arches = set(compatible_arches) - set( + pungi.arch.get_compatible_arches(arch)) # Generate architecture specific modulemd metadata, so we can # store per-architecture artifacts there later. @@ -88,18 +87,27 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase): rpm_obj.nevra not in mmd.get_rpm_artifacts().get()): continue - # If the RPM is not filtered out, add it to compose, - # otherwise remove it from arch_mmd artifacts section. - if rpm_obj.name not in mmd.get_rpm_filter().get(): - packages.add((rpm_obj, None)) - added_rpms.setdefault(mmd_id, []) - added_rpms[mmd_id].append(str(rpm_obj.nevra)) - log.write('Adding %s because it is in %s\n' - % (rpm_obj, mmd_id)) - else: + # Filter out the RPM from artifacts if its filtered in MMD. + if rpm_obj.name in mmd.get_rpm_filter().get(): # No need to check if the rpm_obj is in rpm artifacts, # the .remove() method does that anyway. arch_mmd.get_rpm_artifacts().remove(str(rpm_obj.nevra)) + continue + + # Skip the rpm_obj if it's built for multilib arch, but + # multilib is not enabled for this srpm in MMD. + mmd_component = mmd.get_rpm_components()[srpm] + multilib = mmd_component.get_multilib() + multilib = multilib.get() if multilib else set() + if arch not in multilib and rpm_obj.arch in multilib_arches: + continue + + # Add RPM to packages. + packages.add((rpm_obj, None)) + added_rpms.setdefault(mmd_id, []) + added_rpms[mmd_id].append(str(rpm_obj.nevra)) + log.write('Adding %s because it is in %s\n' + % (rpm_obj, mmd_id)) # GatherSource returns all the packages in variant and does not # care which package is in which module, but for modular metadata diff --git a/tests/test_gather_source_module.py b/tests/test_gather_source_module.py index 5e7fa672..e8736e0b 100644 --- a/tests/test_gather_source_module.py +++ b/tests/test_gather_source_module.py @@ -20,25 +20,49 @@ class TestGatherSourceModule(helpers.PungiTestCase): self.compose = helpers.DummyCompose(self.topdir, {}) self.compose.DEBUG = False self.mmd = self.compose.variants["Server"].add_fake_module( - "testmodule:master:1:2017", rpm_nvrs=["pkg-1.0.0-1"]) + "testmodule:master:1:2017", rpm_nvrs=["pkg-1.0.0-1.x86_64", "pkg-1.0.0-1.i686"]) mock_rpm = mock.Mock(version='1.0.0', release='1', epoch=0, excludearch=None, exclusivearch=None, - sourcerpm='pkg-1.0.0-1', nevra='pkg-1.0.0-1') + sourcerpm='pkg-1.0.0-1', nevra='pkg-1.0.0-1.x86_64', + arch="x86_64") mock_rpm.name = 'pkg' self.compose.variants['Server'].pkgset.rpms_by_arch['x86_64'] = [mock_rpm] + mock_rpm = mock.Mock(version='1.0.0', release='1', + epoch=0, excludearch=None, exclusivearch=None, + sourcerpm='pkg-1.0.0-1', nevra='pkg-1.0.0-1.i686', + arch="i686") + mock_rpm.name = 'pkg' + self.compose.variants['Server'].pkgset.rpms_by_arch['i686'] = [mock_rpm] def test_gather_module(self): source = GatherSourceModule(self.compose) packages, groups = source("x86_64", self.compose.variants["Server"]) self.assertEqual(len(packages), 1) - self.assertEqual(list(packages)[0][0].nevra, "pkg-1.0.0-1") + self.assertEqual(list(packages)[0][0].nevra, "pkg-1.0.0-1.x86_64") self.assertEqual(len(groups), 0) variant = self.compose.variants["Server"] arch_mmd = variant.arch_mmds["x86_64"]["testmodule-master"] self.assertEqual(set(arch_mmd.get_rpm_artifacts().get()), - set(["pkg-1.0.0-1"])) + set(["pkg-1.0.0-1.x86_64"])) + + def test_gather_multilib(self): + multilib = Modulemd.SimpleSet() + multilib.add("x86_64") + self.mmd.get_rpm_components()["pkg"].set_multilib(multilib) + + source = GatherSourceModule(self.compose) + packages, groups = source("x86_64", self.compose.variants["Server"]) + self.assertEqual(len(packages), 2) + self.assertEqual(set(package[0].nevra for package in packages), + set(["pkg-1.0.0-1.x86_64", "pkg-1.0.0-1.i686"])) + self.assertEqual(len(groups), 0) + + variant = self.compose.variants["Server"] + arch_mmd = variant.arch_mmds["x86_64"]["testmodule-master"] + self.assertEqual(set(arch_mmd.get_rpm_artifacts().get()), + set(["pkg-1.0.0-1.x86_64", "pkg-1.0.0-1.i686"])) def test_gather_filtered_module(self): filter_set = Modulemd.SimpleSet()