From ae97f9d7383cc37e6b5f7b3778bb72e5a67d442e Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sat, 2 Dec 2017 11:51:43 +0000 Subject: [PATCH] Fix #948: a package depending on itself recursed forever (#963) --- pmb/build/_package.py | 10 +++++++++- test/test_build_package.py | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pmb/build/_package.py b/pmb/build/_package.py index b1239141..8fce4360 100644 --- a/pmb/build/_package.py +++ b/pmb/build/_package.py @@ -78,11 +78,19 @@ def get_depends(args, apkbuild): :returns: list of dependency pkgnames (eg. ["sdl2", "sdl2_net"]) """ + # Read makedepends and depends ret = list(apkbuild["makedepends"]) if "ignore_depends" not in args or not args.ignore_depends: ret += apkbuild["depends"] + ret = sorted(set(ret)) - return sorted(set(ret)) + # Don't recurse forever when a package depends on itself (#948) + for pkgname in [apkbuild["pkgname"]] + list(apkbuild["subpackages"]): + if pkgname in ret: + logging.verbose(apkbuild["pkgname"] + ": ignoring dependency on" + " itself: " + pkgname) + ret.remove(pkgname) + return ret def build_depends(args, apkbuild, arch, strict): diff --git a/test/test_build_package.py b/test/test_build_package.py index d2ed2d58..a4c35eeb 100644 --- a/test/test_build_package.py +++ b/test/test_build_package.py @@ -112,7 +112,8 @@ def test_check_arch(args): def test_get_depends(monkeypatch): func = pmb.build._package.get_depends - apkbuild = {"depends": ["a"], "makedepends": ["c", "b"]} + apkbuild = {"pkgname": "test", "depends": ["a"], "makedepends": ["c", "b"], + "subpackages": ["d"]} # Depends + makedepends args = args_patched(monkeypatch, ["pmbootstrap", "build", "test"]) @@ -124,11 +125,22 @@ def test_get_depends(monkeypatch): args = args_patched(monkeypatch, ["pmbootstrap", "build", "-i", "test"]) assert func(args, apkbuild) == ["b", "c"] + # Package depends on its own subpackage + apkbuild["makedepends"] = ["d"] + args = args_patched(monkeypatch, ["pmbootstrap", "build", "test"]) + assert func(args, apkbuild) == ["a"] + + # Package depends on itself + apkbuild["makedepends"] = ["c", "b", "test"] + args = args_patched(monkeypatch, ["pmbootstrap", "build", "test"]) + assert func(args, apkbuild) == ["a", "b", "c"] + def test_build_depends(args, monkeypatch): # Shortcut and fake apkbuild func = pmb.build._package.build_depends - apkbuild = {"pkgname": "test", "depends": ["a"], "makedepends": ["b"]} + apkbuild = {"pkgname": "test", "depends": ["a"], "makedepends": ["b"], + "subpackages": ["d"]} # No depends built (first makedepends + depends, then only makedepends) monkeypatch.setattr(pmb.build._package, "package", return_none)