From cf9d648ac9a0c5565ede5db48a34cac536baf190 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sun, 20 Oct 2019 19:53:54 +0200 Subject: [PATCH] pmaports.guess_main: new assumption for -dev pkgs (!1827) Packages ending in -dev: just assume that the originating aport has the same pkgname, except for the -dev at the end. Otherwise we may end up with the wrong package. For example, if something depends on plasma-framework-dev, and plasma-framework is in Alpine, but plasma is in pmaports, then the regular guess_main() algorithm below would pick plasma instead of plasma-framework. Fixes: build.postmarketos.org#52 --- pmb/helpers/pmaports.py | 31 +++++++++++++++++++++++++++++++ test/test_helpers_pmaports.py | 15 +++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/pmb/helpers/pmaports.py b/pmb/helpers/pmaports.py index 2d60cc99..d2dac675 100644 --- a/pmb/helpers/pmaports.py +++ b/pmb/helpers/pmaports.py @@ -41,6 +41,28 @@ def get_list(args): return ret +def guess_main_dev(args, subpkgname): + """ + Check if a package without "-dev" at the end exists in pmaports or not, and + log the appropriate message. Don't call this function directly, use + guess_main() instead. + + :param subpkgname: subpackage name, must end in "-dev" + :returns: full path to the pmaport or None + """ + pkgname = subpkgname[:-4] + paths = glob.glob(args.aports + "/*/" + pkgname) + if paths: + logging.debug(subpkgname + ": guessed to be a subpackage of " + + pkgname + " (just removed '-dev')") + return paths[0] + + logging.debug(subpkgname + ": guessed to be a subpackage of " + pkgname + + ", which we can't find in pmaports, so it's probably in" + " Alpine") + return None + + def guess_main(args, subpkgname): """ Find the main package by assuming it is a prefix of the subpkgname. @@ -54,6 +76,15 @@ def guess_main(args, subpkgname): "/home/user/code/pmbootstrap/aports/main/u-boot" * None when we couldn't find a main package """ + # Packages ending in -dev: just assume that the originating aport has the + # same pkgname, except for the -dev at the end. If we use the other method + # below on subpackages, we may end up with the wrong package. For example, + # if something depends on plasma-framework-dev, and plasma-framework is in + # Alpine, but plasma is in pmaports, then the cutting algorithm below would + # pick plasma instead of plasma-framework. + if subpkgname.endswith("-dev"): + return guess_main_dev(args, subpkgname) + # Iterate until the cut up subpkgname is gone words = subpkgname.split("-") while len(words) > 1: diff --git a/test/test_helpers_pmaports.py b/test/test_helpers_pmaports.py index 676cb017..2055dee6 100644 --- a/test/test_helpers_pmaports.py +++ b/test/test_helpers_pmaports.py @@ -50,3 +50,18 @@ def test_guess_main(args, tmpdir): assert func(args, "qemu-system-x86_64") == tmpdir + "/temp/qemu" assert func(args, "some-pkg-sub-pkg") == tmpdir + "/main/some-pkg" assert func(args, "qemuPackageWithoutDashes") is None + + +def test_guess_main_dev(args, tmpdir): + # Fake pmaports folder + tmpdir = str(tmpdir) + args.aports = tmpdir + os.makedirs(tmpdir + "/temp/plasma") + + func = pmb.helpers.pmaports.guess_main_dev + assert func(args, "plasma-framework-dev") is None + assert func(args, "plasma-dev") == tmpdir + "/temp/plasma" + + func = pmb.helpers.pmaports.guess_main + assert func(args, "plasma-framework-dev") is None + assert func(args, "plasma-randomsubpkg") == tmpdir + "/temp/plasma"