Let PORTAGE_CONFIGROOT/etc/make.conf, where PORTAGE_CONFIGROOT is not /, 
specify ROOT.

In general, a set of configuration files other than the base set is 
intended for a target root other than the live system. Normally, it is 
intended for a particular target root. This patch allows make.conf in this 
situation to specify the target root. A ROOT environment variable, if set, 
overrides this setting (so the user can use a configuration that's 
normally used for target A on target B, if desired).

This patch also postpones the setting of defaults for PORTAGE_CONFIGROOT 
and ROOT until just before they are used, so that it is possible to 
distinguish an emerge command with "ROOT=/" from one without ROOT set.

Signed-off-by: Daniel Barkalow <[EMAIL PROTECTED]>

Index: pym/portage.py
===================================================================
--- pym/portage.py      (revision 5090)
+++ pym/portage.py      (working copy)
@@ -833,9 +833,15 @@
        if not test or (str(test.__class__) != 'portage.config'):
                raise TypeError, "Invalid type for config object: %s" % 
test.__class__
 
+def check_var_directory(varname, var):
+       if not os.path.isdir(var):
+               writemsg("!!! Error: %s='%s' is not a directory. Please correct 
this.\n" % (var, varname),
+                       noiselevel=-1)
+               raise portage_exception.DirectoryNotFound(var)
+
 class config:
        def __init__(self, clone=None, mycpv=None, config_profile_path=None,
-               config_incrementals=None, config_root="/", target_root="/",
+               config_incrementals=None, config_root=None, target_root=None,
                local_config=True):
 
                self.already_in_regenerate = 0
@@ -921,17 +927,13 @@
                        # backupenv is for calculated incremental variables.
                        self.backupenv = os.environ.copy()
 
+                       if not config_root:
+                               config_root = "/"
+
                        config_root = \
                                normalize_path(config_root).rstrip(os.path.sep) 
+ os.path.sep
-                       target_root = \
-                               normalize_path(target_root).rstrip(os.path.sep) 
+ os.path.sep
 
-                       for k, v in (("PORTAGE_CONFIGROOT", config_root),
-                               ("ROOT", target_root)):
-                               if not os.path.isdir(v):
-                                       writemsg("!!! Error: %s='%s' is not a 
directory. Please correct this.\n" % (k, v),
-                                               noiselevel=-1)
-                                       raise 
portage_exception.DirectoryNotFound(v)
+                       check_var_directory("PORTAGE_CONFIGROOT", config_root)
 
                        self.depcachedir = DEPCACHE_PATH
 
@@ -1125,7 +1127,9 @@
                                        noiselevel=-1)
                                sys.exit(1)
 
-
+                       if config_root != "/" and "ROOT" in self.mygcfg and not 
target_root:
+                               target_root = self.mygcfg["ROOT"]
+                       
                        self.configlist.append(self.mygcfg)
                        self.configdict["conf"]=self.configlist[-1]
 
@@ -1156,6 +1160,14 @@
                                                pass
                        del blacklisted, cfg
 
+                       if not target_root:
+                               target_root = "/"
+
+                       target_root = \
+                               normalize_path(target_root).rstrip(os.path.sep) 
+ os.path.sep
+
+                       check_var_directory("ROOT", target_root)
+
                        env_d = getconfig(
                                os.path.join(target_root, "etc", 
"profile.env"), expand=False)
                        # env_d will be None if profile.env doesn't exist.
@@ -7327,7 +7339,7 @@
                        commit_mtimedb(mydict=d, filename=self.filename)
                        self._clean_data = copy.deepcopy(d)
 
-def create_trees(config_root="/", target_root="/", trees=None):
+def create_trees(config_root=None, target_root=None, trees=None):
        if trees is None:
                trees = {}
        else:
@@ -7345,11 +7357,11 @@
 
        myroots = [(settings["ROOT"], settings)]
        if settings["ROOT"] != "/":
-               settings = config(config_root="/", target_root="/",
+               settings = config(config_root=None, target_root=None,
                        config_incrementals=portage_const.INCREMENTALS)
                settings.lock()
                settings.validate()
-               myroots.append(("/", settings))
+               myroots.append((settings["ROOT"], settings))
 
        for myroot, mysettings in myroots:
                trees[myroot] = portage_util.LazyItemsDict(trees.get(myroot, 
None))
Index: bin/emerge
===================================================================
--- bin/emerge  (revision 5090)
+++ bin/emerge  (working copy)
@@ -4289,7 +4289,7 @@
 def load_emerge_config(trees=None):
        kwargs = {}
        for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), 
("target_root", "ROOT")):
-               kwargs[k] = os.environ.get(envvar, "/")
+               kwargs[k] = os.environ.get(envvar)
        trees = portage.create_trees(trees=trees, **kwargs)
 
        settings = trees["/"]["vartree"].settings
-- 
gentoo-portage-dev@gentoo.org mailing list

Reply via email to