diff mbox series

[2/4] package_manager/rpm: give out useful reason about unmatched packages

Message ID 20250912033325.2887890-2-Qi.Chen@windriver.com
State New
Headers show
Series [1/4] package_manager/__init__.py: add function to give user reason about a missing package | expand

Commit Message

ChenQi Sept. 12, 2025, 3:33 a.m. UTC
From: Chen Qi <Qi.Chen@windriver.com>

Unmatched package error is a common error at rootfs. We want to give
out more useful information to user.

Before this change, if some user specifiy IMAGE_INSTALL += "catch2",
the error message will be like:

  No match for argument: catch2
  Error: Unable to find a match: catch2

With this patch, the error message will be like:

  No match for argument: catch2
  Error: Unable to find a match: catch2
  catch2 is a recipe. Its generated packages are: ['catch2-src', 'catch2-dbg', 'catch2-staticdev', 'catch2-dev', 'catch2-doc']
  Either specify a generated package or set ALLOW_EMPTY:${PN} = "1" in catch2 recipe

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 meta/lib/oe/package_manager/rpm/__init__.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/lib/oe/package_manager/rpm/__init__.py b/meta/lib/oe/package_manager/rpm/__init__.py
index 323ec5008f..20e6cb8744 100644
--- a/meta/lib/oe/package_manager/rpm/__init__.py
+++ b/meta/lib/oe/package_manager/rpm/__init__.py
@@ -330,8 +330,15 @@  class RpmPM(PackageManager):
             return output
         except subprocess.CalledProcessError as e:
             if print_output:
+                e_output = e.output.decode("utf-8")
+                extra_info = ""
+                if "install" in dnf_args:
+                    if "Error: Unable to find a match:" in e_output:
+                        no_match_pkgs = re.search(r'Error: Unable to find a match: ([a-z0-9+\-\._\s]+)', e_output).group(1).split()
+                        for pkg in no_match_pkgs:
+                            extra_info += self.get_missing_pkg_reason(pkg)
                 (bb.note, bb.fatal)[fatal]("Could not invoke dnf. Command "
-                     "'%s' returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
+                     "'%s' returned %d:\n%s%s" % (' '.join(cmd), e.returncode, e_output, extra_info))
             else:
                 (bb.note, bb.fatal)[fatal]("Could not invoke dnf. Command "
                      "'%s' returned %d:" % (' '.join(cmd), e.returncode))