diff mbox series

[3/4] package_manager/deb: give out useful reason about an unmatched package

Message ID 20250912033325.2887890-3-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>

Give out useful information when a package could not be matched.

Before the change:

  E: Package 'catch2' has no installation candidate

With this patch:

  E: Package 'catch2' has no installation candidate
  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/deb/__init__.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oe/package_manager/deb/__init__.py b/meta/lib/oe/package_manager/deb/__init__.py
index e09e81e490..eb48f3f982 100644
--- a/meta/lib/oe/package_manager/deb/__init__.py
+++ b/meta/lib/oe/package_manager/deb/__init__.py
@@ -244,9 +244,19 @@  class DpkgPM(OpkgDpkgPM):
             output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
             bb.note(output.decode("utf-8"))
         except subprocess.CalledProcessError as e:
+            e_output = e.output.decode("utf-8")
+            extra_info = ""
+            for e_line in e_output.split('\n'):
+                if 'has no installation candidate' in e_line or 'Unable to locate package' in e_line:
+                    match = re.search(r"E: Package '([a-z0-9+\-\._]+)' has no installation candidate", e_line)
+                    if match:
+                        pkg = match.group(1)
+                    else:
+                        pkg = re.search(r"E: Unable to locate package ([a-z0-9+\-\._]+)", e_line).group(1)
+                    extra_info += self.get_missing_pkg_reason(pkg)
             (bb.fatal, bb.warn)[attempt_only]("Unable to install packages. "
-                                              "Command '%s' returned %d:\n%s" %
-                                              (cmd, e.returncode, e.output.decode("utf-8")))
+                                              "Command '%s' returned %d:\n%s%s" %
+                                              (cmd, e.returncode, e_output, extra_info))
 
         # rename *.dpkg-new files/dirs
         for root, dirs, files in os.walk(self.target_rootfs):