From bcfdc3fb1b1eee97bb67693d6125aae6c3cb21dc Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Tue, 21 Nov 2023 23:24:41 +0100 Subject: [PATCH] pkg resolver: don't guess if pmaport was found If we found an APKBUILD already, with the exact name of the package we are looking for, then don't also guess what other package could contain the package as subpackage. The guess was thrown away with the previous logic, but it caused misleading verbose logs like: lomiri-history-service: guessed to be a subpackage of lomiri Also this is slightly faster. While at it, tweak the related comments to make this easier to understand. Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20231121222457.2871-1-ollieparanoid@postmarketos.org%3E --- pmb/helpers/pmaports.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/pmb/helpers/pmaports.py b/pmb/helpers/pmaports.py index 7cf02eba..6d5535bf 100644 --- a/pmb/helpers/pmaports.py +++ b/pmb/helpers/pmaports.py @@ -153,28 +153,32 @@ def find(args, package, must_exist=True): if "*" in package: raise RuntimeError("Invalid pkgname: " + package) - # Search in packages + # Try to find an APKBUILD with the exact pkgname we are looking for path = _find_apkbuilds(args).get(package) if path: ret = os.path.dirname(path) + else: + # No luck, take a guess what APKBUILD could have the package we are + # looking for as subpackage + guess = guess_main(args, package) + if guess: + # Parse the APKBUILD and verify if the guess was right + if _find_package_in_apkbuild(package, f'{guess}/APKBUILD'): + ret = guess + else: + # Otherwise parse all APKBUILDs (takes time!), is the + # package we are looking for a subpackage of any of those? + for path_current in _find_apkbuilds(args).values(): + if _find_package_in_apkbuild(package, path_current): + ret = os.path.dirname(path_current) + break - # Try to guess based on the subpackage name - guess = guess_main(args, package) - if guess: - # ... but see if we were right - if _find_package_in_apkbuild(package, f'{guess}/APKBUILD'): - ret = guess - - # Search in subpackages and provides - if not ret: - for path_current in _find_apkbuilds(args).values(): - if _find_package_in_apkbuild(package, path_current): - ret = os.path.dirname(path_current) - break - - # Use the guess otherwise - if not ret: - ret = guess + # If we still didn't find anything, as last resort: assume our + # initial guess was right and the APKBUILD parser just didn't + # find the subpackage in there because it is behind shell logic + # that we don't parse. + if not ret: + ret = guess # Crash when necessary if ret is None and must_exist: