From f3ba0de3605b84c40e06530d88fc320ed00d159c Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Fri, 15 Feb 2019 15:32:39 +0100 Subject: [PATCH] repo_missing: return pkgnames, not subpkgnames (!1757) "breeze-icons" depends on "qt5-qtbase-dev", but "pmbootstrap repo_missing" should return "qt5-qtbase" instead. This patch fixes it, as one can see with: $ pmbootstrap repo_missing --built breeze-icons --overview --- pmb/helpers/package.py | 30 +++++++++++++++++++++++------- pmb/helpers/repo_missing.py | 2 +- test/test_helpers_package.py | 20 ++++++++++---------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/pmb/helpers/package.py b/pmb/helpers/package.py index faf563c7..a47a9e29 100644 --- a/pmb/helpers/package.py +++ b/pmb/helpers/package.py @@ -32,7 +32,7 @@ import pmb.helpers.pmaports import pmb.helpers.repo -def get(args, pkgname, arch): +def get(args, pkgname, arch, replace_subpkgnames=False): """ Find a package in pmaports, and as fallback in the APKINDEXes of the binary packages. :param pkgname: package name (e.g. "hello-world") @@ -41,6 +41,8 @@ def get(args, pkgname, arch): arch to see whether the package exists at all. So make sure to check the returned arch against what you wanted 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", ...], @@ -50,8 +52,9 @@ def get(args, pkgname, arch): # Cached result cache_key = "pmb.helpers.package.get" if (arch in args.cache[cache_key] and - pkgname in args.cache[cache_key][arch]): - return args.cache[cache_key][arch][pkgname] + pkgname in args.cache[cache_key][arch] and + replace_subpkgnames in args.cache[cache_key][arch][pkgname]): + return args.cache[cache_key][arch][pkgname][replace_subpkgnames] # Find in pmaports ret = None @@ -59,7 +62,7 @@ def get(args, pkgname, arch): if pmaport: ret = {"arch": pmaport["arch"], "depends": pmb.build._package.get_depends(args, pmaport), - "pkgname": pkgname, + "pkgname": pmaport["pkgname"], "provides": pmaport["provides"], "version": pmaport["pkgver"] + "-r" + pmaport["pkgrel"]} @@ -86,11 +89,22 @@ def get(args, pkgname, arch): if ret and isinstance(ret["arch"], str): ret["arch"] = [ret["arch"]] + # Replace subpkgnames if desired + 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] + ret["depends"] = depends_new + # Save to cache and return if ret: if arch not in args.cache[cache_key]: args.cache[cache_key][arch] = {} - args.cache[cache_key][arch][pkgname] = ret + if pkgname not in args.cache[cache_key][arch]: + args.cache[cache_key][arch][pkgname] = {} + args.cache[cache_key][arch][pkgname][replace_subpkgnames] = ret return ret # Could not find the package @@ -122,8 +136,10 @@ def depends_recurse(args, pkgname, arch): for depend in package["depends"]: if depend not in ret: queue += [depend] - if pkgname_queue not in ret: - ret += [pkgname_queue] + + # Add the pkgname (not possible subpkgname) to ret + if package["pkgname"] not in ret: + ret += [package["pkgname"]] ret.sort() # Save to cache and return diff --git a/pmb/helpers/repo_missing.py b/pmb/helpers/repo_missing.py index c8560f91..3d12e447 100644 --- a/pmb/helpers/repo_missing.py +++ b/pmb/helpers/repo_missing.py @@ -120,7 +120,7 @@ def generate_output_format(args, arch, pkgnames): "depends": ["hello-world"]}] """ ret = [] for pkgname in pkgnames: - entry = pmb.helpers.package.get(args, pkgname, arch) + entry = pmb.helpers.package.get(args, pkgname, arch, True) ret += [{"pkgname": entry["pkgname"], "repo": pmb.helpers.pmaports.get_repo(args, pkgname), "version": entry["version"], diff --git a/test/test_helpers_package.py b/test/test_helpers_package.py index b4efd702..0129aa0f 100644 --- a/test/test_helpers_package.py +++ b/test/test_helpers_package.py @@ -101,10 +101,10 @@ def test_helpers_package_depends_recurse(args): """ Test pmb.helpers.package.depends_recurse() """ # Put fake data into the pmb.helpers.package.get() cache - cache = {"a": {"depends": ["b", "c"]}, - "b": {"depends": []}, - "c": {"depends": ["d"]}, - "d": {"depends": ["b"]}} + cache = {"a": {False: {"pkgname": "a", "depends": ["b", "c"]}}, + "b": {False: {"pkgname": "b", "depends": []}}, + "c": {False: {"pkgname": "c", "depends": ["d"]}}, + "d": {False: {"pkgname": "d", "depends": ["b"]}}} args.cache["pmb.helpers.package.get"]["armhf"] = cache # Normal runs @@ -121,22 +121,22 @@ def test_helpers_package_check_arch_package(args): """ Test pmb.helpers.package.check_arch(): binary = True """ # Put fake data into the pmb.helpers.package.get() cache func = pmb.helpers.package.check_arch - cache = {"a": {"arch": []}} + cache = {"a": {False: {"arch": []}}} args.cache["pmb.helpers.package.get"]["armhf"] = cache - cache["a"]["arch"] = ["all !armhf"] + cache["a"][False]["arch"] = ["all !armhf"] assert func(args, "a", "armhf") is False - cache["a"]["arch"] = ["all"] + cache["a"][False]["arch"] = ["all"] assert func(args, "a", "armhf") is True - cache["a"]["arch"] = ["noarch"] + cache["a"][False]["arch"] = ["noarch"] assert func(args, "a", "armhf") is True - cache["a"]["arch"] = ["armhf"] + cache["a"][False]["arch"] = ["armhf"] assert func(args, "a", "armhf") is True - cache["a"]["arch"] = ["aarch64"] + cache["a"][False]["arch"] = ["aarch64"] assert func(args, "a", "armhf") is False