commit:     20ff16e8941af389cd1fc80e10aef1a90f3b5aa8
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Nov 11 09:08:20 2014 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Nov 18 07:15:18 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=20ff16e8

dep_zapdeps: avoid use.mask/force changes (515584)

This patch causes dep_zapdeps to check which USE flags cause a match
to fail, and uses that information to prioritize choices that do not
require changes to use.mask or use.force.

X-Gentoo-Bug: 515584
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=515584
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>

---
 pym/portage/dep/dep_check.py                  | 36 +++++++++++++++-
 pym/portage/tests/resolver/test_or_choices.py | 59 ++++++++++++++++++++++++++-
 2 files changed, 92 insertions(+), 3 deletions(-)

diff --git a/pym/portage/dep/dep_check.py b/pym/portage/dep/dep_check.py
index 62f42ac..ccdda59 100644
--- a/pym/portage/dep/dep_check.py
+++ b/pym/portage/dep/dep_check.py
@@ -317,6 +317,7 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, 
trees=None):
        priority = trees[myroot].get("priority")
        graph_db = trees[myroot].get("graph_db")
        graph    = trees[myroot].get("graph")
+       pkg_use_enabled = trees[myroot].get("pkg_use_enabled")
        want_update_pkg = trees[myroot].get("want_update_pkg")
        vardb = None
        if "vartree" in trees[myroot]:
@@ -349,6 +350,7 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, 
trees=None):
 
                all_available = True
                all_use_satisfied = True
+               all_use_unmasked = True
                slot_map = {}
                cp_map = {}
                for atom in atoms:
@@ -369,6 +371,32 @@ def dep_zapdeps(unreduced, reduced, myroot, 
use_binaries=0, trees=None):
                                avail_pkg_use = mydbapi_match_pkgs(atom)
                                if not avail_pkg_use:
                                        all_use_satisfied = False
+
+                                       if pkg_use_enabled is not None:
+                                               # Check which USE flags cause 
the match to fail,
+                                               # so we can prioritize choices 
that do not
+                                               # require changes to use.mask 
or use.force
+                                               # (see bug #515584).
+                                               violated_atom = 
atom.violated_conditionals(
+                                                       
pkg_use_enabled(avail_pkg),
+                                                       
avail_pkg.iuse.is_valid_flag)
+
+                                               # Note that violated_atom.use 
can be None here,
+                                               # since evaluation can collapse 
conditional USE
+                                               # deps that cause the match to 
fail due to
+                                               # missing IUSE (match uses 
atom.unevaluated_atom
+                                               # to detect such missing IUSE).
+                                               if violated_atom.use is not 
None:
+                                                       for flag in 
violated_atom.use.enabled:
+                                                               if flag in 
avail_pkg.use.mask:
+                                                                       
all_use_unmasked = False
+                                                                       break
+                                                       else:
+                                                               for flag in 
violated_atom.use.disabled:
+                                                                       if flag 
in avail_pkg.use.force and \
+                                                                               
flag not in avail_pkg.use.mask:
+                                                                               
all_use_unmasked = False
+                                                                               
break
                                else:
                                        # highest (ascending order)
                                        avail_pkg_use = avail_pkg_use[-1]
@@ -416,7 +444,9 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, 
trees=None):
                                        else:
                                                
preferred_non_installed.append(this_choice)
                                else:
-                                       if all_installed_slots:
+                                       if not all_use_unmasked:
+                                               other.append(this_choice)
+                                       elif all_installed_slots:
                                                
unsat_use_installed.append(this_choice)
                                        else:
                                                
unsat_use_non_installed.append(this_choice)
@@ -490,7 +520,9 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, 
trees=None):
                                                else:
                                                        
preferred_non_installed.append(this_choice)
                                        else:
-                                               if all_in_graph:
+                                               if not all_use_unmasked:
+                                                       
other.append(this_choice)
+                                               elif all_in_graph:
                                                        
unsat_use_in_graph.append(this_choice)
                                                elif all_installed_slots:
                                                        
unsat_use_installed.append(this_choice)

diff --git a/pym/portage/tests/resolver/test_or_choices.py 
b/pym/portage/tests/resolver/test_or_choices.py
index d9d14f0..4aae0b2 100644
--- a/pym/portage/tests/resolver/test_or_choices.py
+++ b/pym/portage/tests/resolver/test_or_choices.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Gentoo Foundation
+# Copyright 2013-2014 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from portage.tests import TestCase
@@ -205,3 +205,60 @@ class OrChoicesTestCase(TestCase):
                                self.assertEqual(test_case.test_success, True, 
test_case.fail_msg)
                finally:
                        playground.cleanup()
+
+
+       def testUseMask(self):
+
+               profile = {
+                       "use.mask":
+                       (
+                               "abi_ppc_32",
+                       ),
+               }
+
+               ebuilds = {
+
+                       "sys-libs/A-1" : {
+                               "EAPI": "5",
+                               "RDEPEND": "|| ( sys-libs/zlib[abi_ppc_32(-)] " 
+ \
+                                       "sys-libs/zlib[abi_x86_32(-)] )"
+                       },
+
+                       "sys-libs/zlib-1.2.8-r1" : {
+                               "EAPI": "5",
+                               "IUSE": "abi_ppc_32 abi_x86_32"
+                       },
+
+                       "sys-libs/zlib-1.2.8" : {
+                               "EAPI": "5",
+                               "IUSE": ""
+                       },
+               }
+
+               test_cases = (
+
+                       # bug #515584: We want to prefer choices that do
+                       # not require changes to use.mask or use.force.
+                       # In this case, abi_ppc_32 is use.masked in the
+                       # profile, so we want to avoid that choice.
+                       ResolverPlaygroundTestCase(
+                               ["sys-libs/A"],
+                               options = {},
+                               success = False,
+                               use_changes = {
+                                       'sys-libs/zlib-1.2.8-r1': 
{'abi_x86_32': True}
+                               },
+                               mergelist = ["sys-libs/zlib-1.2.8-r1", 
"sys-libs/A-1"]
+                       ),
+
+               )
+
+               playground = ResolverPlayground(ebuilds=ebuilds,
+                       profile=profile, debug=False)
+               try:
+                       for test_case in test_cases:
+                               playground.run_TestCase(test_case)
+                               self.assertEqual(test_case.test_success, True,
+                                       test_case.fail_msg)
+               finally:
+                       playground.cleanup()

Reply via email to