commit: afe9939fc89927346806e8013535bcc15688cb69 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Mon Sep 8 07:27:34 2014 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Tue Sep 9 20:56:46 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=afe9939f
config.setcpv: fix bug #522362 Fix config.setcpv to regenerate USE settings in order to account for package.env USE settings from the previous package instance. X-Gentoo-Bug: 522362 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=522362 Acked-by: Alexander Berntsen <bernalex <AT> gentoo.org> Acked-by: Brian Dolbec <dolsen <AT> gentoo.org> --- pym/portage/package/ebuild/config.py | 4 ++ pym/portage/tests/ebuild/test_config.py | 71 +++++++++++++++++++++++- pym/portage/tests/resolver/ResolverPlayground.py | 7 ++- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index f639e14..264ed8e 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -1360,6 +1360,7 @@ class config(object): previous_iuse = pkg_configdict.get("IUSE") previous_iuse_effective = pkg_configdict.get("IUSE_EFFECTIVE") previous_features = pkg_configdict.get("FEATURES") + previous_penv = self._penv aux_keys = self._setcpv_aux_keys @@ -1527,6 +1528,9 @@ class config(object): else: pkg_configdict['USE'] = self.puse + elif previous_penv: + has_changed = True + if has_changed: self.reset(keeping_pkg=1) diff --git a/pym/portage/tests/ebuild/test_config.py b/pym/portage/tests/ebuild/test_config.py index 08e0a5d..20aac51 100644 --- a/pym/portage/tests/ebuild/test_config.py +++ b/pym/portage/tests/ebuild/test_config.py @@ -1,13 +1,20 @@ # Copyright 2010-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +from __future__ import unicode_literals + +import io +import tempfile + import portage -from portage import os +from portage import os, shutil, _encodings +from portage.const import USER_CONFIG_PATH from portage.dep import Atom from portage.package.ebuild.config import config from portage.package.ebuild._config.LicenseManager import LicenseManager from portage.tests import TestCase from portage.tests.resolver.ResolverPlayground import ResolverPlayground, ResolverPlaygroundTestCase +from portage.util import normalize_path class ConfigTestCase(TestCase): @@ -274,3 +281,65 @@ class ConfigTestCase(TestCase): self.assertEqual(test_case.test_success, True, test_case.fail_msg) finally: playground.cleanup() + + + def testSetCpv(self): + """ + Test the clone via constructor. + """ + + ebuilds = { + "dev-libs/A-1": {"IUSE": "static-libs"}, + "dev-libs/B-1": {"IUSE": "static-libs"}, + } + + env_files = { + "A" : ("USE=\"static-libs\"",) + } + + package_env = ( + "dev-libs/A A", + ) + + eprefix = normalize_path(tempfile.mkdtemp()) + playground = None + try: + user_config_dir = os.path.join(eprefix, USER_CONFIG_PATH) + os.makedirs(user_config_dir) + + with io.open(os.path.join(user_config_dir, "package.env"), + mode='w', encoding=_encodings['content']) as f: + for line in package_env: + f.write(line + "\n") + + env_dir = os.path.join(user_config_dir, "env") + os.makedirs(env_dir) + for k, v in env_files.items(): + with io.open(os.path.join(env_dir, k), mode='w', + encoding=_encodings['content']) as f: + for line in v: + f.write(line + "\n") + + playground = ResolverPlayground(eprefix=eprefix, ebuilds=ebuilds) + settings = config(clone=playground.settings) + + result = playground.run(["=dev-libs/A-1"]) + pkg, existing_node = result.depgraph._select_package( + playground.eroot, Atom("=dev-libs/A-1")) + settings.setcpv(pkg) + self.assertTrue("static-libs" in + settings["PORTAGE_USE"].split()) + + # Test bug #522362, where a USE=static-libs package.env + # setting leaked from one setcpv call to the next. + pkg, existing_node = result.depgraph._select_package( + playground.eroot, Atom("=dev-libs/B-1")) + settings.setcpv(pkg) + self.assertTrue("static-libs" not in + settings["PORTAGE_USE"].split()) + + finally: + if playground is None: + shutil.rmtree(eprefix) + else: + playground.cleanup() diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py index 077e271..9ee1d5e 100644 --- a/pym/portage/tests/resolver/ResolverPlayground.py +++ b/pym/portage/tests/resolver/ResolverPlayground.py @@ -58,7 +58,7 @@ class ResolverPlayground(object): def __init__(self, ebuilds={}, binpkgs={}, installed={}, profile={}, repo_configs={}, \ user_config={}, sets={}, world=[], world_sets=[], distfiles={}, - targetroot=False, debug=False): + eprefix=None, targetroot=False, debug=False): """ ebuilds: cpv -> metadata mapping simulating available ebuilds. installed: cpv -> metadata mapping simulating installed packages. @@ -66,7 +66,10 @@ class ResolverPlayground(object): profile: settings defined by the profile. """ self.debug = debug - self.eprefix = normalize_path(tempfile.mkdtemp()) + if eprefix is None: + self.eprefix = normalize_path(tempfile.mkdtemp()) + else: + self.eprefix = normalize_path(eprefix) portage.const.EPREFIX = self.eprefix.rstrip(os.sep) self.eroot = self.eprefix + os.sep
