Fix #948: a package depending on itself recursed forever (#963)

This commit is contained in:
Oliver Smith 2017-12-02 11:51:43 +00:00 committed by GitHub
parent 30d1a5cada
commit ae97f9d738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

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

View File

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