From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 800FE158020 for ; Fri, 25 Nov 2022 03:36:38 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 72DE1E0955; Fri, 25 Nov 2022 03:36:37 +0000 (UTC) Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6B609E0955 for ; Fri, 25 Nov 2022 03:36:37 +0000 (UTC) Received: by mail-pl1-x636.google.com with SMTP id k7so2889606pll.6 for ; Thu, 24 Nov 2022 19:36:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=45cOCI/mJoxpuQAsakmMvrvpoYpE6SOI2IDaV2uYJ9c=; b=NU9oUXsGzMJqBQlaqkFi+MoU/qJ1b/UkK4xvOmyxpC9hW59qWe8IjlgVk+7sgm3wHN lNDaCq/CnRMKAylE2AP/yAycJsuGfe3COClgBIBCuLlDsTe6us3xSHNLKzeFl/z1KgtW mn4Y+8iQB1UyCJhxauu96WJhfry/8tgFzrNhc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=45cOCI/mJoxpuQAsakmMvrvpoYpE6SOI2IDaV2uYJ9c=; b=Y/DV3Cj8q1OvT3uYam/dEwtJEh2CFDlmnc3d7d+X7s7TU3z8oxgM4Bmhj6oEmaA3ZC 7cClJxvQv1qg3Ht9IS+nBBUaCwaysG7UPOPRjr6LwauxG/K85yEXUJWglyGlFrQ1WUz7 NCzHJqkUuLh2VrBZ9F4rFSfTtji2o87K4UPao77V4ysluZpppC61g4CMKjslRvnM8Yv/ YGeUjHtXh5X5DOUKSo+kwy9mt7AlqKeBg0bpcuMvdgoSeaLRPfHZv2wvp4G69EFSr9qY HD7Qd9fwi0hVHPPmvlPHJFr4t2DmUayVjQml3dMK1yJrPlS4nAlJK86+PGcSfrFAkwDK 2SiQ== X-Gm-Message-State: ANoB5pl4CuagnTDpjFWNsSOF53vQFVTWYcjjKh31H7XRrcQFREBKbOq2 ExUJct1siAN1dR0Mc4amVYOPhcwVN6WKAQ== X-Google-Smtp-Source: AA0mqf6XsezLnocwo4Xe2dhTu/vNzybDaCTe7hhYlZRZ11IA0imCryVLLyJGCv7ccwk/wjgsPUb3jA== X-Received: by 2002:a17:90a:5c85:b0:20a:92d2:226a with SMTP id r5-20020a17090a5c8500b0020a92d2226amr27141832pji.155.1669347395985; Thu, 24 Nov 2022 19:36:35 -0800 (PST) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:5d98:6fda:de11:3c9]) by smtp.gmail.com with ESMTPSA id 22-20020a621616000000b0053e468a78a8sm1937037pfw.158.2022.11.24.19.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Nov 2022 19:36:35 -0800 (PST) From: Pin-yen Lin To: gentoo-portage-dev@lists.gentoo.org Cc: Pin-yen Lin Subject: [gentoo-portage-dev] [PATCH 1/2] Move and rename check_reverse_dependencies Date: Fri, 25 Nov 2022 11:36:26 +0800 Message-Id: <20221125033627.1105638-1-treapking@chromium.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: 21d47478-e546-48ee-a554-35893bd9e999 X-Archives-Hash: 621e50daab7ac041cc9fc7e9debf2f5e Move the function outside the original scope and rename the function to _slot_operator_check_reverse_dependencies to accommodate the coding style. Signed-off-by: Pin-yen Lin --- lib/_emerge/depgraph.py | 232 +++++++++++++++++++++------------------- 1 file changed, 119 insertions(+), 113 deletions(-) diff --git a/lib/_emerge/depgraph.py b/lib/_emerge/depgraph.py index c976f8205..ce6cabcc1 100644 --- a/lib/_emerge/depgraph.py +++ b/lib/_emerge/depgraph.py @@ -2240,6 +2240,117 @@ class depgraph: return None + def _slot_operator_check_reverse_dependencies( + self, existing_pkg, candidate_pkg, replacement_parent=None + ): + """ + Check if candidate_pkg satisfies all of existing_pkg's non- + slot operator parents. + """ + debug = "--debug" in self._frozen_config.myopts + built_slot_operator_parents = set() + for parent, atom in self._dynamic_config._parent_atoms.get( + existing_pkg, [] + ): + if atom.soname or atom.slot_operator_built: + built_slot_operator_parents.add(parent) + + for parent, atom in self._dynamic_config._parent_atoms.get( + existing_pkg, [] + ): + if isinstance(parent, Package): + if parent in built_slot_operator_parents: + if hasattr(atom, "_orig_atom"): + # If atom is the result of virtual expansion, then + # derefrence it to _orig_atom so that it will be correctly + # handled as a built slot operator dependency when + # appropriate (see bug 764764). + atom = atom._orig_atom + # This parent may need to be rebuilt, therefore + # discard its soname and built slot operator + # dependency components which are not necessarily + # relevant. + if atom.soname: + continue + elif atom.package and atom.slot_operator_built: + # This discards the slot/subslot component. + atom = atom.with_slot("=") + + if replacement_parent is not None and ( + replacement_parent.slot_atom == parent.slot_atom + or replacement_parent.cpv == parent.cpv + ): + # This parent is irrelevant because we intend to + # replace it with replacement_parent. + continue + + if any( + pkg is not parent + and (pkg.slot_atom == parent.slot_atom or pkg.cpv == parent.cpv) + for pkg in self._dynamic_config._package_tracker.match( + parent.root, Atom(parent.cp) + ) + ): + # This parent may need to be eliminated due to a + # slot conflict, so its dependencies aren't + # necessarily relevant. + continue + + if not self._too_deep( + parent.depth + ) and not self._frozen_config.excluded_pkgs.findAtomForPackage( + parent, modified_use=self._pkg_use_enabled(parent) + ): + # Check for common reasons that the parent's + # dependency might be irrelevant. + if self._upgrade_available(parent): + # This parent could be replaced by + # an upgrade (bug 584626). + continue + if parent.installed and self._in_blocker_conflict(parent): + # This parent could be uninstalled in order + # to solve a blocker conflict (bug 612772). + continue + if self._dynamic_config.digraph.has_edge(parent, existing_pkg): + # There is a direct circular dependency between + # parent and existing_pkg. This type of + # relationship tends to prevent updates + # of packages (bug 612874). Since candidate_pkg + # is available, we risk a missed update if we + # don't try to eliminate this parent from the + # graph. Therefore, we give candidate_pkg a + # chance, and assume that it will be masked + # by backtracking if necessary. + continue + + atom_set = InternalPackageSet(initial_atoms=(atom,), allow_repo=True) + if not atom_set.findAtomForPackage( + candidate_pkg, modified_use=self._pkg_use_enabled(candidate_pkg) + ): + if debug: + parent_atoms = [] + for ( + other_parent, + other_atom, + ) in self._dynamic_config._parent_atoms.get(existing_pkg, []): + if other_parent is parent: + parent_atoms.append(other_atom) + msg = ( + "", + "", + "_slot_operator_check_reverse_dependencies:", + " candidate package does not match atom '%s': %s" + % (atom, candidate_pkg), + " parent: %s" % parent, + " parent atoms: %s" % " ".join(parent_atoms), + "", + ) + writemsg_level( + "\n".join(msg), noiselevel=-1, level=logging.DEBUG + ) + return False + return True + def _slot_operator_update_probe( self, dep, new_child_slot=False, slot_conflict=False, autounmask_level=None ): @@ -2274,116 +2385,6 @@ class depgraph: want_downgrade = None want_downgrade_parent = None - def check_reverse_dependencies( - existing_pkg, candidate_pkg, replacement_parent=None - ): - """ - Check if candidate_pkg satisfies all of existing_pkg's non- - slot operator parents. - """ - built_slot_operator_parents = set() - for parent, atom in self._dynamic_config._parent_atoms.get( - existing_pkg, [] - ): - if atom.soname or atom.slot_operator_built: - built_slot_operator_parents.add(parent) - - for parent, atom in self._dynamic_config._parent_atoms.get( - existing_pkg, [] - ): - if isinstance(parent, Package): - if parent in built_slot_operator_parents: - if hasattr(atom, "_orig_atom"): - # If atom is the result of virtual expansion, then - # derefrence it to _orig_atom so that it will be correctly - # handled as a built slot operator dependency when - # appropriate (see bug 764764). - atom = atom._orig_atom - # This parent may need to be rebuilt, therefore - # discard its soname and built slot operator - # dependency components which are not necessarily - # relevant. - if atom.soname: - continue - elif atom.package and atom.slot_operator_built: - # This discards the slot/subslot component. - atom = atom.with_slot("=") - - if replacement_parent is not None and ( - replacement_parent.slot_atom == parent.slot_atom - or replacement_parent.cpv == parent.cpv - ): - # This parent is irrelevant because we intend to - # replace it with replacement_parent. - continue - - if any( - pkg is not parent - and (pkg.slot_atom == parent.slot_atom or pkg.cpv == parent.cpv) - for pkg in self._dynamic_config._package_tracker.match( - parent.root, Atom(parent.cp) - ) - ): - # This parent may need to be eliminated due to a - # slot conflict, so its dependencies aren't - # necessarily relevant. - continue - - if not self._too_deep( - parent.depth - ) and not self._frozen_config.excluded_pkgs.findAtomForPackage( - parent, modified_use=self._pkg_use_enabled(parent) - ): - # Check for common reasons that the parent's - # dependency might be irrelevant. - if self._upgrade_available(parent): - # This parent could be replaced by - # an upgrade (bug 584626). - continue - if parent.installed and self._in_blocker_conflict(parent): - # This parent could be uninstalled in order - # to solve a blocker conflict (bug 612772). - continue - if self._dynamic_config.digraph.has_edge(parent, existing_pkg): - # There is a direct circular dependency between - # parent and existing_pkg. This type of - # relationship tends to prevent updates - # of packages (bug 612874). Since candidate_pkg - # is available, we risk a missed update if we - # don't try to eliminate this parent from the - # graph. Therefore, we give candidate_pkg a - # chance, and assume that it will be masked - # by backtracking if necessary. - continue - - atom_set = InternalPackageSet(initial_atoms=(atom,), allow_repo=True) - if not atom_set.findAtomForPackage( - candidate_pkg, modified_use=self._pkg_use_enabled(candidate_pkg) - ): - if debug: - parent_atoms = [] - for ( - other_parent, - other_atom, - ) in self._dynamic_config._parent_atoms.get(existing_pkg, []): - if other_parent is parent: - parent_atoms.append(other_atom) - msg = ( - "", - "", - "check_reverse_dependencies:", - " candidate package does not match atom '%s': %s" - % (atom, candidate_pkg), - " parent: %s" % parent, - " parent atoms: %s" % " ".join(parent_atoms), - "", - ) - writemsg_level( - "\n".join(msg), noiselevel=-1, level=logging.DEBUG - ) - return False - return True - for replacement_parent in self._iter_similar_available( dep.parent, dep.parent.slot_atom, autounmask_level=autounmask_level ): @@ -2397,7 +2398,9 @@ class depgraph: if not want_downgrade_parent: continue - if not check_reverse_dependencies(dep.parent, replacement_parent): + if not self._slot_operator_check_reverse_dependencies( + dep.parent, replacement_parent + ): continue selected_atoms = None @@ -2510,8 +2513,11 @@ class depgraph: if atom_not_selected: break - if not insignificant and check_reverse_dependencies( - dep.child, pkg, replacement_parent=replacement_parent + if ( + not insignificant + and self._slot_operator_check_reverse_dependencies( + dep.child, pkg, replacement_parent=replacement_parent + ) ): candidate_pkg_atoms.append((pkg, unevaluated_atom or atom)) -- 2.38.1.584.g0f3c55d4c2-goog