commit:     3b08575233ecf1d3e6f31f959741a4826aeac4a9
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 14 06:57:45 2014 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Nov 14 17:28:19 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=3b085752

portageq: fix eroot parameter (bug #529200)

The portageq eroot parameter has been broken since commit
c9f6aa9f0151adb3c86706eaef1914cdbdcf2b6d, due to premature instantiation
of portage.settings (before the ROOT variable was set). Premature access
to the portage.settings attribute must be avoided by using other
available means to determine the EPREFIX.

Fixes: c9f6aa9f0151 ("Add cross-prefix support")
X-Gentoo-Bug: 529200
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=529200
Acked-by: Alexander Berntsen <bernalex <AT> gentoo.org>

---
 bin/portageq                            |  9 ++++++++-
 pym/portage/tests/emerge/test_simple.py | 10 ++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/bin/portageq b/bin/portageq
index 009f116..ef565d1 100755
--- a/bin/portageq
+++ b/bin/portageq
@@ -1392,7 +1392,14 @@ def main(argv):
                        sys.stderr.write("Run portageq with --help for info\n")
                        sys.stderr.flush()
                        sys.exit(os.EX_USAGE)
-               eprefix = portage.settings["EPREFIX"]
+               # Calculate EPREFIX and ROOT that will be used to construct
+               # portage.settings later. It's tempting to use
+               # portage.settings["EPREFIX"] here, but that would force
+               # instantiation of portage.settings, which we don't want to do
+               # until after we've calculated ROOT (see bug #529200).
+               eprefix = os.environ.get("EPREFIX", portage.const.EPREFIX)
+               if eprefix:
+                       eprefix = portage.util.normalize_path(eprefix)
                eroot = portage.util.normalize_path(argv[2])
 
                if eprefix:

diff --git a/pym/portage/tests/emerge/test_simple.py 
b/pym/portage/tests/emerge/test_simple.py
index 6c20a07..0101362 100644
--- a/pym/portage/tests/emerge/test_simple.py
+++ b/pym/portage/tests/emerge/test_simple.py
@@ -217,6 +217,8 @@ pkg_preinst() {
                self.assertFalse(test_ebuild is None)
 
                cross_prefix = os.path.join(eprefix, "cross_prefix")
+               cross_root = os.path.join(eprefix, "cross_root")
+               cross_eroot = os.path.join(cross_root, eprefix.lstrip(os.sep))
 
                test_commands = (
                        env_update_cmd,
@@ -318,6 +320,10 @@ pkg_preinst() {
                                portageq_cmd + ("has_version", cross_prefix, 
"dev-libs/A"),
                        ({"EPREFIX" : cross_prefix},) + \
                                portageq_cmd + ("has_version", cross_prefix, 
"dev-libs/B"),
+
+                       # Test ROOT support
+                       ({"ROOT": cross_root},) + emerge_cmd + ("dev-libs/B",),
+                       portageq_cmd + ("has_version", cross_eroot, 
"dev-libs/B"),
                )
 
                distdir = playground.distdir
@@ -372,8 +378,8 @@ pkg_preinst() {
                                os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"]
 
                updates_dir = os.path.join(test_repo_location, "profiles", 
"updates")
-               dirs = [cachedir, cachedir_pregen, cross_prefix, distdir, 
fake_bin,
-                       portage_tmpdir, updates_dir,
+               dirs = [cachedir, cachedir_pregen, cross_eroot, cross_prefix,
+                       distdir, fake_bin, portage_tmpdir, updates_dir,
                        user_config_dir, var_cache_edb]
                etc_symlinks = ("dispatch-conf.conf", "etc-update.conf")
                # Override things that may be unavailable, or may have 
portability

Reply via email to