Skip to contentSkip to conversation

package_manager/__init__.py: add function to give user reason about a missing package

PATCH New [email protected] 1 participant 4 messages Sep 12, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 package_manager/__init__.py: add function to give user reason about a missing package

From: Chen Qi <[email protected]>

When users specify some package in IMAGE_INSTALL, but get some error at rootfs time, the user might be confusing. This usually happens when the user puts a recipe name in IMAGE_INSTALL.

To helper user understand more about what's going on, add a common function here which makes use of pkgdata data to give the possible reason about a missing package. This function is expected to be used by package backends such as rpm.

---
 meta/lib/oe/package_manager/__init__.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
meta/lib/oe/package_manager/__init__.py +22 -0
index 5c98a104be..88bc5ab195 100644
@@ -17,6 +17,7 @@ import oe.utils
 import oe.path
 import string
 from oe.gpg_sign import get_signer
+import oe.packagedata
 import hashlib
 import fnmatch
 
@@ -447,6 +448,27 @@ class PackageManager(object, metaclass=ABCMeta):
             return res
         return _append(uris, base_paths)
 
+    def get_missing_pkg_reason(self, pkg):
+        """
+        Return a string describing the possible reason of a missing package.
+        """
+        reason = ""
+        if not oe.packagedata.packaged(pkg, self.d):
+            if oe.packagedata.has_pkgdata(pkg, self.d):
+                packaged_pkgs = []
+                recipe_data = oe.packagedata.read_pkgdata(pkg, self.d)
+                for subpkg in recipe_data.get("PACKAGES", "").split():
+                    if oe.packagedata.packaged(subpkg, self.d):
+                        packaged_pkgs.append(subpkg)
+                reason = "%s is a recipe. Its generated packages are: %s\n" % (pkg, packaged_pkgs)
+                reason += "Either specify a generated package or set ALLOW_EMPTY:${PN} = \"1\" in %s recipe\n" % pkg
+            else:
+                reason = "%s is neither a recipe nor a generated package.\n" % pkg
+        else:
+            reason = "%s is a generated package.\n" % pkg
+            reason += "The reason it's not found might be that it's not in %s\n" % oe.path.join(self.d.getVar('WORKDIR'), "oe-rootfs-repo")
+        return reason
+
 def create_packages_dir(d, subrepo_dir, deploydir, taskname, filterbydependencies, include_self=False):
     """
     Go through our do_package_write_X dependencies and hardlink the packages we depend
Signature · 1 line
2.49.0
#1 lore raw

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

From: Chen Qi <[email protected]>

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

---
 meta/lib/oe/package_manager/rpm/__init__.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
meta/lib/oe/package_manager/rpm/__init__.py +8 -1
index 323ec5008f..20e6cb8744 100644
@@ -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))
Signature · 1 line
2.49.0
#2 lore raw

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

In reply to [email protected]

From: Chen Qi <[email protected]>

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

---
 meta/lib/oe/package_manager/deb/__init__.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
meta/lib/oe/package_manager/deb/__init__.py +12 -2
index e09e81e490..eb48f3f982 100644
@@ -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):
Signature · 1 line
2.49.0
#3 lore raw

PATCH 4/4 package_manager/ipk: give out useful reason about an unmatched package

In reply to [email protected]

From: Chen Qi <[email protected]>

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

Before the change:

error: opkg_solver_install: No candidates to install catch2 (null)!

With this patch:

error: opkg_solver_install: No candidates to install catch2 (null)!
...
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

---
 meta/lib/oe/package_manager/ipk/__init__.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
meta/lib/oe/package_manager/ipk/__init__.py +14 -2
index 3d998e52ff..4794f31f88 100644
@@ -307,9 +307,21 @@ class OpkgPM(OpkgDpkgPM):
             if failed_pkgs:
                 failed_postinsts_abort(failed_pkgs, self.d.expand("${T}/log.do_${BB_CURRENTTASK}"))
         except subprocess.CalledProcessError as e:
+            e_output = e.output.decode("utf-8")
+            extra_info = ""
+            unmatched_pkgs = []
+            for e_line in e_output.split('\n'):
+                if "error: opkg_solver_install: No candidates to install" in e_line:
+                    unmatched_pkg = re.search(r"error: opkg_solver_install: No candidates to install ([a-z0-9+\-\._]+)", e_line).group(1)
+                    unmatched_pkgs.append(unmatched_pkg)
+                elif "error: opkg_prepare_url_for_install: Couldn't find anything to satisfy" in e_line:
+                    unmatched_pkg = re.search(r"error: opkg_prepare_url_for_install: Couldn't find anything to satisfy '([a-z0-9+\-\._]+)'", e_line).group(1)
+                    unmatched_pkgs.append(unmatched_pkg)
+            for pkg in unmatched_pkgs:
+                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))
 
     def remove(self, pkgs, with_dependencies=True):
         if not pkgs:
Signature · 1 line
2.49.0