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
This commit is contained in:
Oliver Smith 2019-10-20 19:53:54 +02:00
parent 8a5c8fcc3e
commit cf9d648ac9
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
2 changed files with 46 additions and 0 deletions

View File

@ -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:

View File

@ -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"