build: package: split has_cyclical_dep in function (MR 2388)

Split has_cyclical_dependency logic into an extra function, so it is
easier to read.
This commit is contained in:
Oliver Smith 2024-09-17 00:10:30 +02:00
parent b76963ab03
commit 7c4c63f9fc
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -213,6 +213,16 @@ class BuildQueueItem(TypedDict):
chroot: Chroot
def has_cyclical_dependency(unmet_deps: dict[str, list[str]], item: BuildQueueItem, dep: str):
pkgnames = [item["name"]] + list(item["apkbuild"]["subpackages"].keys())
for pkgname in pkgnames:
if pkgname in unmet_deps.get(dep, []):
return True
return False
def prioritise_build_queue(disarray: list[BuildQueueItem]) -> list[BuildQueueItem]:
"""
Figure out The Correct Order to build packages in, or bail.
@ -260,11 +270,8 @@ def prioritise_build_queue(disarray: list[BuildQueueItem]) -> list[BuildQueueIte
if dep in all_pkgnames:
unmet_deps.setdefault(item["name"], []).append(dep)
missing_deps = True
if any(
x in unmet_deps.get(dep, [])
for x in [item["name"]] + list(item["apkbuild"]["subpackages"].keys())
):
# We have a cyclical dependency between item and dep!
if has_cyclical_dependency(unmet_deps, item, dep):
# If a binary package exists for item, we can queue it
# safely and dep will be queued on a future iteration
if item["has_binary"]: