More _pkg_use_enabled fixes
authorSebastian Luther <SebastianLuther@gmx.de>
Tue, 24 Aug 2010 12:14:43 +0000 (14:14 +0200)
committerZac Medico <zmedico@gentoo.org>
Tue, 24 Aug 2010 13:48:40 +0000 (06:48 -0700)
pym/_emerge/depgraph.py
pym/_emerge/resolver/slot_collision.py
pym/portage/sets/base.py

index a682e5017f5e91a3978dd8c5c54e3fd56ef6d09a..b939be1282898f79745d539030d5a31642d73f6d 100644 (file)
@@ -543,7 +543,7 @@ class depgraph(object):
                                        parent, atom = parent_atom
                                        atom_set = InternalPackageSet(
                                                initial_atoms=(atom,))
-                                       if atom_set.findAtomForPackage(pkg):
+                                       if atom_set.findAtomForPackage(pkg, modified_use=self._pkg_use_enabled(pkg)):
                                                parent_atoms.add(parent_atom)
                                        else:
                                                self._dynamic_config._slot_conflict_parent_atoms.add(parent_atom)
@@ -766,7 +766,8 @@ class depgraph(object):
                                        # Use package set for matching since it will match via
                                        # PROVIDE when necessary, while match_from_list does not.
                                        atom_set = InternalPackageSet(initial_atoms=[dep.atom])
-                                       if not atom_set.findAtomForPackage(existing_node):
+                                       if not atom_set.findAtomForPackage(existing_node, \
+                                               modified_use=self._pkg_use_enabled(existing_node)):
                                                existing_node_matches = False
                                if existing_node_matches:
                                        # The existing node can be reused.
@@ -1240,7 +1241,7 @@ class depgraph(object):
                                        for pkg2 in pkgs:
                                                if pkg2 is pkg1:
                                                        continue
-                                               if atom_set.findAtomForPackage(pkg2):
+                                               if atom_set.findAtomForPackage(pkg2, modified_use=self._pkg_use_enabled(pkg2)):
                                                        atom_pkg_graph.add(pkg2, atom)
 
                        for pkg in pkgs:
@@ -1916,8 +1917,8 @@ class depgraph(object):
 
                # filter packages that conflict with highest_pkg
                greedy_pkgs = [pkg for pkg in greedy_pkgs if not \
-                       (blockers[highest_pkg].findAtomForPackage(pkg) or \
-                       blockers[pkg].findAtomForPackage(highest_pkg))]
+                       (blockers[highest_pkg].findAtomForPackage(pkg, modified_use=self._pkg_use_enabled(pkg)) or \
+                       blockers[pkg].findAtomForPackage(highest_pkg, modified_use=self._pkg_use_enabled(highest_pkg)))]
 
                if not greedy_pkgs:
                        return []
@@ -1933,8 +1934,8 @@ class depgraph(object):
                                pkg2 = greedy_pkgs[j]
                                if pkg2 in discard_pkgs:
                                        continue
-                               if blockers[pkg1].findAtomForPackage(pkg2) or \
-                                       blockers[pkg2].findAtomForPackage(pkg1):
+                               if blockers[pkg1].findAtomForPackage(pkg2, modified_use=self._pkg_use_enabled(pkg2)) or \
+                                       blockers[pkg2].findAtomForPackage(pkg1, modified_use=self._pkg_use_enabled(pkg1)):
                                        # pkg1 > pkg2
                                        discard_pkgs.add(pkg2)
 
@@ -2060,7 +2061,7 @@ class depgraph(object):
                                                # old-style virtual match even in cases when the
                                                # package does not actually PROVIDE the virtual.
                                                # Filter out any such false matches here.
-                                               if not atom_set.findAtomForPackage(pkg):
+                                               if not atom_set.findAtomForPackage(pkg, modified_use=self._pkg_use_enabled(pkg)):
                                                        continue
                                        if pkg in self._dynamic_config._runtime_pkg_mask:
                                                backtrack_reasons = \
@@ -2068,7 +2069,8 @@ class depgraph(object):
                                                mreasons.append('backtracking: %s' % \
                                                        ', '.join(sorted(backtrack_reasons)))
                                                backtrack_mask = True
-                                       if not mreasons and self._frozen_config.excluded_pkgs.findAtomForPackage(pkg):
+                                       if not mreasons and self._frozen_config.excluded_pkgs.findAtomForPackage(pkg, \
+                                               modified_use=self._pkg_use_enabled(pkg)):
                                                mreasons = ["exclude option"]
                                        if mreasons:
                                                masked_pkg_instances.add(pkg)
@@ -2332,7 +2334,7 @@ class depgraph(object):
                                                # package does not actually PROVIDE the virtual.
                                                # Filter out any such false matches here.
                                                if not InternalPackageSet(initial_atoms=(atom,)
-                                                       ).findAtomForPackage(pkg):
+                                                       ).findAtomForPackage(pkg, modified_use=self._pkg_use_enabled(pkg)):
                                                        continue
                                        yield pkg
 
@@ -2575,7 +2577,8 @@ class depgraph(object):
                                                continue
 
                                        if not pkg.installed and \
-                                               self._frozen_config.excluded_pkgs.findAtomForPackage(pkg):
+                                               self._frozen_config.excluded_pkgs.findAtomForPackage(pkg, \
+                                                       modified_use=self._pkg_use_enabled(pkg)):
                                                continue
 
                                        if dont_miss_updates:
@@ -2733,7 +2736,7 @@ class depgraph(object):
                                                        break
                                                # Use PackageSet.findAtomForPackage()
                                                # for PROVIDE support.
-                                               if atom_set.findAtomForPackage(e_pkg):
+                                               if atom_set.findAtomForPackage(e_pkg, modified_use=self._pkg_use_enabled(e_pkg)):
                                                        if highest_version and \
                                                                e_pkg.cp == atom_cp and \
                                                                e_pkg < highest_version and \
@@ -3245,13 +3248,13 @@ class depgraph(object):
                        blocked_initial = set()
                        for atom in atoms:
                                for pkg in initial_db.match_pkgs(atom):
-                                       if atom_set.findAtomForPackage(pkg):
+                                       if atom_set.findAtomForPackage(pkg, modified_use=self._pkg_use_enabled(pkg)):
                                                blocked_initial.add(pkg)
 
                        blocked_final = set()
                        for atom in atoms:
                                for pkg in final_db.match_pkgs(atom):
-                                       if atom_set.findAtomForPackage(pkg):
+                                       if atom_set.findAtomForPackage(pkg, modified_use=self._pkg_use_enabled(pkg)):
                                                blocked_final.add(pkg)
 
                        if not blocked_initial and not blocked_final:
@@ -4742,11 +4745,11 @@ class depgraph(object):
                                pkg_system = False
                                pkg_world = False
                                try:
-                                       pkg_system = system_set.findAtomForPackage(pkg)
-                                       pkg_world  = world_set.findAtomForPackage(pkg)
+                                       pkg_system = system_set.findAtomForPackage(pkg, modified_use=self._pkg_use_enabled(pkg))
+                                       pkg_world  = world_set.findAtomForPackage(pkg, modified_use=self._pkg_use_enabled(pkg))
                                        if not (oneshot or pkg_world) and \
                                                myroot == self._frozen_config.target_root and \
-                                               favorites_set.findAtomForPackage(pkg):
+                                               favorites_set.findAtomForPackage(pkg, modified_use=self._pkg_use_enabled(pkg)):
                                                # Maybe it will be added to world now.
                                                if create_world_atom(pkg, favorites_set, root_config):
                                                        pkg_world = True
@@ -5428,7 +5431,8 @@ class depgraph(object):
                                raise
 
                        if "merge" == pkg.operation and \
-                               self._frozen_config.excluded_pkgs.findAtomForPackage(pkg):
+                               self._frozen_config.excluded_pkgs.findAtomForPackage(pkg, \
+                                       modified_use=self._pkg_use_enabled(pkg)):
                                continue
 
                        if "merge" == pkg.operation and not self._pkg_visibility_check(pkg):
index 53cebf6eac487ebfb88f7e2976b83156e2f05ba6..03d7a6a55238a8d4ae8a2994d1f8a837e37e2b72 100644 (file)
@@ -198,7 +198,8 @@ class slot_conflict_handler(object):
                                                        if other_pkg == pkg:
                                                                continue
 
-                                                       if not atom_without_use_set.findAtomForPackage(other_pkg):
+                                                       if not atom_without_use_set.findAtomForPackage(other_pkg, \
+                                                               modified_use=_pkg_use_enabled(other_pkg)):
                                                                #The version range does not match.
                                                                sub_type = None
                                                                if atom.operator in (">=", ">"):
@@ -212,7 +213,8 @@ class slot_conflict_handler(object):
                                                                atoms.add((ppkg, atom, other_pkg))
                                                                num_all_specific_atoms += 1
                                                                collision_reasons[("version", sub_type)] = atoms
-                                                       elif not atom_set.findAtomForPackage(other_pkg):
+                                                       elif not atom_set.findAtomForPackage(other_pkg, \
+                                                               modified_use=_pkg_use_enabled(other_pkg)):
                                                                #Use conditionals not met.
                                                                violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
                                                                        other_pkg.iuse.is_valid_flag, _pkg_use_enabled(ppkg))
@@ -441,11 +443,11 @@ class slot_conflict_handler(object):
                                        continue
 
                                i = InternalPackageSet(initial_atoms=(atom,))
-                               if i.findAtomForPackage(pkg):
+                               if i.findAtomForPackage(pkg, modified_use=_pkg_use_enabled(pkg)):
                                        continue
 
                                i = InternalPackageSet(initial_atoms=(atom.without_use,))
-                               if not i.findAtomForPackage(pkg):
+                               if not i.findAtomForPackage(pkg, modified_use=_pkg_use_enabled(pkg)):
                                        #Version range does not match.
                                        if self.debug:
                                                writemsg(str(pkg) + " does not satify all version requirements." + \
@@ -673,44 +675,38 @@ class slot_conflict_handler(object):
 
                #Check if all atoms are satisfied after the changes are applied.
                for id, pkg in enumerate(config):
+                       new_use = _pkg_use_enabled(pkg)
                        if pkg in required_changes:
-                               old_use = set(_pkg_use_enabled(pkg))
-                               new_use = set(_pkg_use_enabled(pkg))
-                               use_has_changed = False
+                               old_use = pkg.use.enabled
+                               new_use = set(new_use)
                                for flag, state in required_changes[pkg].items():
-                                       if state == "enabled" and flag not in new_use:
+                                       if state == "enabled":
                                                new_use.add(flag)
-                                               use_has_changed = True
-                                       elif state == "disabled" and flag in new_use:
-                                               use_has_changed = True
-                                               new_use.remove(flag)
-                               if use_has_changed:
-                                       new_pkg = pkg.copy()
-                                       new_pkg.metadata["USE"] = " ".join(new_use)
-                               else:
-                                       new_pkg = pkg
-                       else:
-                               new_pkg = pkg
+                                       elif state == "disabled":
+                                               new_use.discard(flag)
+                               if not new_use.symmetric_difference(old_use):
+                                       #avoid copying the package in findAtomForPackage if possible
+                                       new_use = old_use
 
                        for ppkg, atom in all_conflict_atoms_by_slotatom[id]:
                                if not hasattr(ppkg, "use"):
                                        #It's a SetArg or something like that.
                                        continue
-                               new_use = set(_pkg_use_enabled(ppkg))
+                               ppkg_new_use = set(_pkg_use_enabled(ppkg))
                                if ppkg in required_changes:
                                        for flag, state in required_changes[ppkg].items():
-                                               if state == "enabled" and flag not in new_use:
-                                                       new_use.add(flag)
-                                               elif state == "disabled" and flag in new_use:
-                                                       new_use.remove(flag)
+                                               if state == "enabled":
+                                                       ppkg_new_use.add(flag)
+                                               elif state == "disabled":
+                                                       ppkg_new_use.discard(flag)
 
-                               new_atom = atom.unevaluated_atom.evaluate_conditionals(new_use)
+                               new_atom = atom.unevaluated_atom.evaluate_conditionals(ppkg_new_use)
                                i = InternalPackageSet(initial_atoms=(new_atom,))
-                               if not i.findAtomForPackage(new_pkg):
+                               if not i.findAtomForPackage(pkg, new_use):
                                        #We managed to create a new problem with our changes.
                                        is_valid_solution = False
                                        if self.debug:
-                                               writemsg("new conflict introduced: " + str(new_pkg) + \
+                                               writemsg("new conflict introduced: " + str(pkg) + \
                                                        " does not match " + new_atom + " from " + str(ppkg) + "\n", noiselevel=-1)
                                        break
 
index f2e74515777ebcc8b0c4f0872d43f77828da0ad3..f3cf37359457432b67b200b84635fe3dfa855e23 100644 (file)
@@ -114,12 +114,16 @@ class PackageSet(object):
                        self._atommap.setdefault(a.cp, set()).add(a)
        
        # Not sure if this one should really be in PackageSet
-       def findAtomForPackage(self, pkg):
+       def findAtomForPackage(self, pkg, modified_use=None):
                """Return the best match for a given package from the arguments, or
                None if there are no matches.  This matches virtual arguments against
                the PROVIDE metadata.  This can raise an InvalidDependString exception
                if an error occurs while parsing PROVIDE."""
 
+               if modified_use is not None and modified_use is not pkg.use.enabled:
+                       pkg = pkg.copy()
+                       pkg.metadata["USE"] = " ".join(modified_use)
+
                # Atoms matched via PROVIDE must be temporarily transformed since
                # match_from_list() only works correctly when atom.cp == pkg.cp.
                rev_transform = {}