env_update: add minimal EPREFIX support
authorZac Medico <zmedico@gentoo.org>
Mon, 29 Aug 2011 06:12:52 +0000 (23:12 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 29 Aug 2011 06:12:52 +0000 (23:12 -0700)
This takes EPREFIX from the env argument and uses it when joining all
paths. Also, ldconfig calls are disabled when EPREFIX is non-empty,
since it's inappropriate to update the global /etc/ld.so.cache in this
case.

pym/portage/dbapi/vartree.py
pym/portage/util/env_update.py

index 6e49f38f88616da440b347d87249e1bc4c68ae5d..6281f7ee590595eda66fb6d0d3594131bb9de96a 100644 (file)
@@ -1845,7 +1845,7 @@ class dblink(object):
                try:
                        env_update(target_root=self.settings['ROOT'],
                                prev_mtimes=ldpath_mtimes,
-                               contents=contents, env=self.settings.environ(),
+                               contents=contents, env=self.settings,
                                writemsg_level=self._display_merge)
                finally:
                        self.vartree.dbapi._fs_unlock()
@@ -3817,7 +3817,7 @@ class dblink(object):
                        #update environment settings, library paths. DO NOT change symlinks.
                        env_update(makelinks=(not downgrade),
                                target_root=self.settings['ROOT'], prev_mtimes=prev_mtimes,
-                               contents=contents, env=self.settings.environ(),
+                               contents=contents, env=self.settings,
                                writemsg_level=self._display_merge)
                finally:
                        self.vartree.dbapi._fs_unlock()
index eb8a0d95139d1f79d163451709dc09f9bd4f8c08..3dc84d4a1057ef091f2c9b144d6ea131791ec0b0 100644 (file)
@@ -47,7 +47,10 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
                prev_mtimes = portage.mtimedb["ldpath"]
        if env is None:
                env = os.environ
-       envd_dir = os.path.join(target_root, "etc", "env.d")
+
+       eprefix = env.get("EPREFIX", "")
+       eprefix_lstrip = eprefix.lstrip(os.sep)
+       envd_dir = os.path.join(target_root, eprefix_lstrip, "etc", "env.d")
        ensure_dirs(envd_dir, mode=0o755)
        fns = listdir(envd_dir, EmptyOnError=1)
        fns.sort()
@@ -123,7 +126,8 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
                they won't be overwritten by this dict.update call."""
                env.update(myconfig)
 
-       ldsoconf_path = os.path.join(target_root, "etc", "ld.so.conf")
+       ldsoconf_path = os.path.join(
+               target_root, eprefix_lstrip, "etc", "ld.so.conf")
        try:
                myld = io.open(_unicode_encode(ldsoconf_path,
                        encoding=_encodings['fs'], errors='strict'),
@@ -156,8 +160,8 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
 
        # Update prelink.conf if we are prelink-enabled
        if prelink_capable:
-               newprelink = atomic_ofstream(
-                       os.path.join(target_root, "etc", "prelink.conf"))
+               newprelink = atomic_ofstream(os.path.join(
+                       target_root, eprefix_lstrip, "etc", "prelink.conf"))
                newprelink.write("# prelink.conf autogenerated by env-update; make all changes to\n")
                newprelink.write("# contents of /etc/env.d directory\n")
 
@@ -193,7 +197,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
        lib_dirs = set()
        for lib_dir in set(specials["LDPATH"] + \
                ['usr/lib','usr/lib64','usr/lib32','lib','lib64','lib32']):
-               x = os.path.join(target_root, lib_dir.lstrip(os.sep))
+               x = os.path.join(target_root, eprefix_lstrip, lib_dir.lstrip(os.sep))
                try:
                        newldpathtime = os.stat(x)[stat.ST_MTIME]
                        lib_dirs.add(normalize_path(x))
@@ -246,7 +250,7 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
                ldconfig = find_binary("%s-ldconfig" % env["CHOST"])
 
        # Only run ldconfig as needed
-       if (ld_cache_update or makelinks) and ldconfig:
+       if (ld_cache_update or makelinks) and ldconfig and not eprefix:
                # ldconfig has very different behaviour between FreeBSD and Linux
                if ostype == "Linux" or ostype.lower().endswith("gnu"):
                        # We can't update links if we haven't cleaned other versions first, as
@@ -272,7 +276,8 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
        cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
 
        #create /etc/profile.env for bash support
-       outfile = atomic_ofstream(os.path.join(target_root, "etc", "profile.env"))
+       outfile = atomic_ofstream(os.path.join(
+               target_root, eprefix_lstrip, "etc", "profile.env"))
        outfile.write(penvnotice)
 
        env_keys = [ x for x in env if x != "LDPATH" ]
@@ -286,7 +291,8 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
        outfile.close()
 
        #create /etc/csh.env for (t)csh support
-       outfile = atomic_ofstream(os.path.join(target_root, "etc", "csh.env"))
+       outfile = atomic_ofstream(os.path.join(
+               target_root, eprefix_lstrip, "etc", "csh.env"))
        outfile.write(cenvnotice)
        for x in env_keys:
                outfile.write("setenv %s '%s'\n" % (x, env[x]))