pmb.helpers.package.get: no crash if dep missing (!1909)

Fix the function, so it does not crash anymore when the
replace_subpkgnames argument is set and a dependency cannot be resolved.
Instead, print a useful warning that shows which pmaport caused the
error (that has always been a pain to figure out), and simply don't
replace the potential subpkgname with the real pkgname, just use the
dependency name as-is.

Resolve annoying crashes in bpo dependency resolving, like this one
(caused by a few linux-* pmaports for bad downstream kernels that depend
on python, not apparent at all from the message):

[09:08:15] Calculate packages that need to be built (all packages, aarch64)
[09:08:26] ERROR: Package 'python': Could not find aport, and could not find this package in any APKINDEX!

Related: https://builds.sr.ht/~postmarketos/job/184022
This commit is contained in:
Oliver Smith 2020-04-10 19:15:34 +02:00
parent 29a3cb2b8c
commit b18ec9a693
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 23 additions and 10 deletions

View File

@ -6,12 +6,13 @@ Functions that work on both pmaports and (binary package) repos. See also:
- pmb/helpers/repo.py (work on binary package repos)
"""
import copy
import logging
import pmb.helpers.pmaports
import pmb.helpers.repo
def get(args, pkgname, arch, replace_subpkgnames=False):
def get(args, pkgname, arch, replace_subpkgnames=False, must_exist=True):
""" Find a package in pmaports, and as fallback in the APKINDEXes of the
binary packages.
:param pkgname: package name (e.g. "hello-world")
@ -22,12 +23,14 @@ def get(args, pkgname, arch, replace_subpkgnames=False):
with check_arch(). Example: "armhf"
:param replace_subpkgnames: replace all subpkgnames with their main
pkgnames in the depends (see #1733)
:returns: data from the parsed APKBUILD or APKINDEX in the following
format: {"arch": ["noarch"],
"depends": ["busybox-extras", "lddtree", ...],
"pkgname": "postmarketos-mkinitfs",
"provides": ["mkinitfs=0..1"],
"version": "0.0.4-r10"} """
:param must_exist: raise an exception, if not found
:returns: * data from the parsed APKBUILD or APKINDEX in the following
format: {"arch": ["noarch"],
"depends": ["busybox-extras", "lddtree", ...],
"pkgname": "postmarketos-mkinitfs",
"provides": ["mkinitfs=0..1"],
"version": "0.0.4-r10"}
* None if the package was not found """
# Cached result
cache_key = "pmb.helpers.package.get"
if (arch in args.cache[cache_key] and
@ -78,9 +81,17 @@ def get(args, pkgname, arch, replace_subpkgnames=False):
if replace_subpkgnames:
depends_new = []
for depend in ret["depends"]:
depend = get(args, depend, arch)["pkgname"]
if depend not in depends_new:
depends_new += [depend]
depend_data = get(args, depend, arch, must_exist=False)
if not depend_data:
logging.warning(f"WARNING: {pkgname}: failed to resolve"
f" dependency '{depend}'")
# Can't replace potential subpkgname
if depend not in depends_new:
depends_new += [depend]
continue
depend_pkgname = depend_data["pkgname"]
if depend_pkgname not in depends_new:
depends_new += [depend_pkgname]
ret["depends"] = depends_new
# Save to cache and return
@ -93,6 +104,8 @@ def get(args, pkgname, arch, replace_subpkgnames=False):
return ret
# Could not find the package
if not must_exist:
return None
raise RuntimeError("Package '" + pkgname + "': Could not find aport, and"
" could not find this package in any APKINDEX!")