depgraph: tweak slot-operator merge order
authorZac Medico <zmedico@gentoo.org>
Sat, 6 Jul 2013 21:45:04 +0000 (14:45 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 6 Jul 2013 21:45:04 +0000 (14:45 -0700)
This handles circular DEPEND/RDEPEND with one := operator, so that when
both deps are already satisfied by installed packages, the := dep is
given higher priority in merge order.

pym/_emerge/AbstractDepPriority.py
pym/_emerge/DepPriority.py
pym/_emerge/DepPrioritySatisfiedRange.py
pym/_emerge/UnmergeDepPriority.py
pym/_emerge/depgraph.py
pym/portage/tests/resolver/test_merge_order.py

index 94f26efc5bd47e7c00853219e9d5bb7786c2bf2a..1fcd043455d5194339e310971b8622a75d498fb5 100644 (file)
@@ -1,11 +1,12 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import copy
 from portage.util.SlotObject import SlotObject
 
 class AbstractDepPriority(SlotObject):
-       __slots__ = ("buildtime", "runtime", "runtime_post")
+       __slots__ = ("buildtime", "buildtime_slot_op",
+               "runtime", "runtime_post", "runtime_slot_op")
 
        def __lt__(self, other):
                return self.__int__() < other
index 3c2256a8e7bf592a913c85a14373324af9547339..34fdb481cff8b41a334469969590dba90da28cd8 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from _emerge.AbstractDepPriority import AbstractDepPriority
@@ -16,31 +16,38 @@ class DepPriority(AbstractDepPriority):
 
                Attributes                            Hardness
 
-               buildtime                               0
-               runtime                                -1
-               runtime_post                           -2
-               optional                               -3
-               (none of the above)                    -4
+               buildtime_slot_op                       0
+               buildtime                              -1
+               runtime                                -2
+               runtime_post                           -3
+               optional                               -4
+               (none of the above)                    -5
 
                """
 
                if self.optional:
-                       return -3
-               if self.buildtime:
+                       return -4
+               if self.buildtime_slot_op:
                        return 0
-               if self.runtime:
+               if self.buildtime:
                        return -1
-               if self.runtime_post:
+               if self.runtime:
                        return -2
-               return -4
+               if self.runtime_post:
+                       return -3
+               return -5
 
        def __str__(self):
                if self.ignored:
                        return "ignored"
                if self.optional:
                        return "optional"
+               if self.buildtime_slot_op:
+                       return "buildtime_slot_op"
                if self.buildtime:
                        return "buildtime"
+               if self.runtime_slot_op:
+                       return "runtime_slot_op"
                if self.runtime:
                        return "runtime"
                if self.runtime_post:
index edb29df96eecc98c92b5bc5822906cd17a0dfa70..e5fdba9f1e3977b492b80ad166d4c82f17595375 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from _emerge.DepPriority import DepPriority
@@ -7,17 +7,18 @@ class DepPrioritySatisfiedRange(object):
        DepPriority                         Index      Category
 
        not satisfied and buildtime                    HARD
-       not satisfied and runtime              6       MEDIUM
-       not satisfied and runtime_post         5       MEDIUM_SOFT
+       not satisfied and runtime              7       MEDIUM
+       not satisfied and runtime_post         6       MEDIUM_SOFT
+       satisfied and buildtime_slot_op        5       SOFT
        satisfied and buildtime                4       SOFT
        satisfied and runtime                  3       SOFT
        satisfied and runtime_post             2       SOFT
        optional                               1       SOFT
        (none of the above)                    0       NONE
        """
-       MEDIUM      = 6
-       MEDIUM_SOFT = 5
-       SOFT        = 4
+       MEDIUM      = 7
+       MEDIUM_SOFT = 6
+       SOFT        = 5
        NONE        = 0
 
        @classmethod
@@ -48,6 +49,15 @@ class DepPrioritySatisfiedRange(object):
 
        @classmethod
        def _ignore_satisfied_buildtime(cls, priority):
+               if priority.__class__ is not DepPriority:
+                       return False
+               if priority.buildtime_slot_op:
+                       return False
+               return bool(priority.optional or \
+                       priority.satisfied)
+
+       @classmethod
+       def _ignore_satisfied_buildtime_slot_op(cls, priority):
                if priority.__class__ is not DepPriority:
                        return False
                return bool(priority.optional or \
@@ -80,6 +90,7 @@ DepPrioritySatisfiedRange.ignore_priority = (
        DepPrioritySatisfiedRange._ignore_satisfied_runtime_post,
        DepPrioritySatisfiedRange._ignore_satisfied_runtime,
        DepPrioritySatisfiedRange._ignore_satisfied_buildtime,
+       DepPrioritySatisfiedRange._ignore_satisfied_buildtime_slot_op,
        DepPrioritySatisfiedRange._ignore_runtime_post,
        DepPrioritySatisfiedRange._ignore_runtime
 )
index 43166006fe64c7f5b0f72425272cf15069e7a9e8..0457ea904e285862e10412dcb90348975652e1c6 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from _emerge.AbstractDepPriority import AbstractDepPriority
@@ -7,15 +7,16 @@ class UnmergeDepPriority(AbstractDepPriority):
        """
        Combination of properties           Priority  Category
 
-       runtime                                0       HARD
-       runtime_post                          -1       HARD
-       buildtime                             -2       SOFT
-       (none of the above)                   -2       SOFT
+       runtime_slot_op                        0       HARD
+       runtime                               -1       HARD
+       runtime_post                          -2       HARD
+       buildtime                             -3       SOFT
+       (none of the above)                   -3       SOFT
        """
 
        MAX    =  0
-       SOFT   = -2
-       MIN    = -2
+       SOFT   = -3
+       MIN    = -3
 
        def __init__(self, **kwargs):
                AbstractDepPriority.__init__(self, **kwargs)
@@ -23,13 +24,15 @@ class UnmergeDepPriority(AbstractDepPriority):
                        self.optional = True
 
        def __int__(self):
-               if self.runtime:
+               if self.runtime_slot_op:
                        return 0
-               if self.runtime_post:
+               if self.runtime:
                        return -1
-               if self.buildtime:
+               if self.runtime_post:
                        return -2
-               return -2
+               if self.buildtime:
+                       return -3
+               return -3
 
        def __str__(self):
                if self.ignored:
index b2d79a808300f397c4acc68f875e21fe6afee2ab..939adde49a59b97ca58ba1de7665d92489e06a65 100644 (file)
@@ -2254,6 +2254,13 @@ class depgraph(object):
 
                        mypriority = dep_priority.copy()
                        if not atom.blocker:
+
+                               if atom.slot_operator == "=":
+                                       if mypriority.buildtime:
+                                               mypriority.buildtime_slot_op = True
+                                       if mypriority.runtime:
+                                               mypriority.runtime_slot_op = True
+
                                inst_pkgs = [inst_pkg for inst_pkg in
                                        reversed(vardb.match_pkgs(atom))
                                        if not reinstall_atoms.findAtomForPackage(inst_pkg,
index 5b5709afe174bbd2caafca6864702f3647f864bf..5d000d12b1e0c5a8504ee4352218ce3194ad368f 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2011 Gentoo Foundation
+# Copyright 2011-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import portage
@@ -191,6 +191,12 @@ class MergeOrderTestCase(TestCase):
                                "DEPEND"  : "kde-base/libkdegames",
                                "RDEPEND" : "kde-base/libkdegames",
                        },
+                       "media-libs/mesa-9.1.3" : {
+                               "EAPI" : "5",
+                               "IUSE" : "+xorg",
+                               "DEPEND" : "xorg? ( x11-base/xorg-server:= )",
+                               "RDEPEND" : "xorg? ( x11-base/xorg-server:= )",
+                       },
                        "media-video/libav-0.7_pre20110327" : {
                                "EAPI" : "2",
                                "IUSE" : "X +encode",
@@ -205,6 +211,12 @@ class MergeOrderTestCase(TestCase):
                                "IUSE" : "X +encode",
                                "RDEPEND" : "|| ( >=media-video/ffmpeg-0.6.90_rc0-r2[X=,encode=] >=media-video/libav-0.6.90_rc[X=,encode=] )",
                        },
+                       "x11-base/xorg-server-1.14.1" : {
+                               "EAPI" : "5",
+                               "SLOT": "0/1.14.1",
+                               "DEPEND" : "media-libs/mesa",
+                               "RDEPEND" : "media-libs/mesa",
+                       },
                }
 
                installed = {
@@ -256,6 +268,13 @@ class MergeOrderTestCase(TestCase):
                                "RDEPEND": "",
                        },
                        "app-arch/xz-utils-5.0.1" : {},
+                       "media-libs/mesa-9.1.3" : {
+                               "EAPI" : "5",
+                               "IUSE" : "+xorg",
+                               "USE": "xorg",
+                               "DEPEND" : "x11-base/xorg-server:0/1.14.1=",
+                               "RDEPEND" : "x11-base/xorg-server:0/1.14.1=",
+                       },
                        "media-video/ffmpeg-0.7_rc1" : {
                                "EAPI" : "2",
                                "IUSE" : "X +encode",
@@ -267,6 +286,12 @@ class MergeOrderTestCase(TestCase):
                                "USE" : "encode",
                                "RDEPEND" : "|| ( >=media-video/ffmpeg-0.6.90_rc0-r2[X=,encode=] >=media-video/libav-0.6.90_rc[X=,encode=] )",
                        },
+                       "x11-base/xorg-server-1.14.1" : {
+                               "EAPI" : "5",
+                               "SLOT": "0/1.14.1",
+                               "DEPEND" : "media-libs/mesa",
+                               "RDEPEND" : "media-libs/mesa",
+                       },
                }
 
                test_cases = (
@@ -434,6 +459,14 @@ class MergeOrderTestCase(TestCase):
                                        ('kde-base/libkdegames-3.5.7', 'kde-base/kmines-3.5.7'),
                                ),
                                mergelist = [('kde-base/kdelibs-3.5.7', 'dev-util/pkgconfig-0.25-r2', 'kde-misc/kdnssd-avahi-0.1.2', 'app-arch/xz-utils-5.0.2', 'kde-base/libkdegames-3.5.7', 'kde-base/kdnssd-3.5.7', 'kde-base/kmines-3.5.7')]),
+                       # Test satisfied circular DEPEND/RDEPEND with one := operator.
+                       # Both deps are already satisfied by installed packages, but
+                       # the := dep is given higher priority in merge order.
+                       ResolverPlaygroundTestCase(
+                               ["media-libs/mesa", "x11-base/xorg-server"],
+                               success=True,
+                               all_permutations = True,
+                               mergelist = ['x11-base/xorg-server-1.14.1', 'media-libs/mesa-9.1.3']),
                )
 
                playground = ResolverPlayground(ebuilds=ebuilds, installed=installed)