From ff269a8675ddb21373728e055df90a8717a0a1ff Mon Sep 17 00:00:00 2001 From: Haibo Lin Date: Tue, 11 Feb 2020 14:38:59 +0800 Subject: [PATCH] gather: Make additional_packages accept debuginfo packages Now debuginfo packages defined in additional_packages option could be handled correctly. JIRA: COMPOSE-4085 Signed-off-by: Haibo Lin --- doc/configuration.rst | 5 +++++ pungi/gather_dnf.py | 47 +++++++++++++++++++++++++++++++++---------- tests/test_gather.py | 9 +++++++++ 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index ba753e5b..b2f8ecff 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -706,6 +706,11 @@ Options used, so wildcards are possible. The package can be specified as name only or ``name.arch``. + With ``dnf`` gathering backend, you can specify a debuginfo package to be + included. This is meant to include a package if autodetection does not get + it. If you add a debuginfo package that does not have anything else from + the same build included in the compose, the sources will not be pulled in. + **filter_packages** (*list*) -- packages to be excluded from a variant and architecture; format: ``[(variant_uid_regex, {arch|*: [package_globs]})]`` diff --git a/pungi/gather_dnf.py b/pungi/gather_dnf.py index 9637fac7..6a959173 100644 --- a/pungi/gather_dnf.py +++ b/pungi/gather_dnf.py @@ -18,6 +18,7 @@ from enum import Enum from itertools import count import logging import os +import re from kobo.rpmlib import parse_nvra @@ -325,7 +326,7 @@ class Gather(GatherBase): return pkg in pkgs def _add_packages(self, packages, pulled_by=None, req=None, reason=None, dest=None): - dest = dest or self.result_binary_packages + dest = dest if dest is not None else self.result_binary_packages for i in packages: assert i is not None if i not in dest: @@ -458,6 +459,7 @@ class Gather(GatherBase): @Profiler("Gather.add_initial_packages()") def add_initial_packages(self, pattern_list): added = set() + added_debuginfo = set() excludes = [] includes = [] @@ -472,17 +474,35 @@ class Gather(GatherBase): for pattern in includes: with Profiler("Gather.add_initial_packages():include"): + debuginfo = False if pattern == "system-release" and self.opts.greedy_method == "all": pkgs = self.q_binary_packages.filter( provides="system-release" ).apply() else: - if pattern.endswith(".+"): - pkgs = self.q_multilib_binary_packages.filter( - name__glob=pattern[:-2] - ).apply() + for p in DEBUG_PATTERNS: + p = p.replace("*", ".+") + if re.match(p, pattern): + debuginfo = True + break + if debuginfo: + if pattern.endswith(".+"): + pkgs = self.q_multilib_debug_packages.filter( + name__glob=pattern[:-2] + ).apply() + else: + pkgs = self.q_debug_packages.filter( + name__glob=pattern + ).apply() else: - pkgs = self.q_binary_packages.filter(name__glob=pattern).apply() + if pattern.endswith(".+"): + pkgs = self.q_multilib_binary_packages.filter( + name__glob=pattern[:-2] + ).apply() + else: + pkgs = self.q_binary_packages.filter( + name__glob=pattern + ).apply() if not pkgs: self.logger.error("No package matches pattern %s" % pattern) @@ -495,14 +515,17 @@ class Gather(GatherBase): packages_by_name.setdefault(po.name, []).append(po) for name, packages in packages_by_name.items(): - pkgs = self._get_best_package(packages) + pkgs = self._get_best_package(packages, debuginfo=debuginfo) if pkgs: - added.update(pkgs) + if debuginfo: + added_debuginfo.update(pkgs) + else: + added.update(pkgs) - for pkg in added: + for pkg in added | added_debuginfo: self._set_flag(pkg, PkgFlag.input) - return added + return added, added_debuginfo @Profiler("Gather.init_query_cache()") def init_query_cache(self): @@ -947,8 +970,10 @@ class Gather(GatherBase): self.conditional_packages = conditional_packages or [] self.logger.debug("INITIAL PACKAGES") - added = self.add_initial_packages(pattern_list) + added, added_debuginfo = self.add_initial_packages(pattern_list) self._add_packages(added) + if added_debuginfo: + self._add_packages(added_debuginfo, dest=self.result_debug_packages) added = self.log_count("PREPOPULATE", self.add_prepopulate_packages) self._add_packages(added, reason="prepopulate") diff --git a/tests/test_gather.py b/tests/test_gather.py index 348da9e3..38bc2300 100644 --- a/tests/test_gather.py +++ b/tests/test_gather.py @@ -2613,3 +2613,12 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase): ], ) six.assertCountEqual(self, pkg_map["debuginfo"], []) + + def test_explicit_debug(self): + pkg_map = self.go(["dummy-bash-debuginfo"], None) + + six.assertCountEqual(self, pkg_map["rpm"], []) + six.assertCountEqual(self, pkg_map["srpm"], []) + six.assertCountEqual( + self, pkg_map["debuginfo"], ["dummy-bash-debuginfo-4.2.37-6.x86_64.rpm"], + )