summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/emerge2
-rw-r--r--pym/portage.py46
2 files changed, 34 insertions, 14 deletions
diff --git a/bin/emerge b/bin/emerge
index b5bbc456b..a0a9c4aec 100755
--- a/bin/emerge
+++ b/bin/emerge
@@ -4271,7 +4271,7 @@ def validate_ebuild_environment(trees):
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, None)
trees = portage.create_trees(trees=trees, **kwargs)
settings = trees["/"]["vartree"].settings
diff --git a/pym/portage.py b/pym/portage.py
index e48850fb7..443a871f5 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -835,7 +835,7 @@ def check_config_instance(test):
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 +921,20 @@ class config:
# backupenv is for calculated incremental variables.
self.backupenv = os.environ.copy()
+ 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)
+
+ if config_root is None:
+ 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 +1128,16 @@ class config:
noiselevel=-1)
sys.exit(1)
-
+ # Allow ROOT setting to come from make.conf if it's not overridden
+ # by the constructor argument (from the calling environment). As a
+ # special exception for a very common use case, config_root == "/"
+ # implies that ROOT in make.conf should be ignored. That way, the
+ # user can chroot into $ROOT and the ROOT setting in make.conf will
+ # be automatically ignored (unless config_root is other than "/").
+ if config_root != "/" and \
+ target_root is None and "ROOT" in self.mygcfg:
+ target_root = self.mygcfg["ROOT"]
+
self.configlist.append(self.mygcfg)
self.configdict["conf"]=self.configlist[-1]
@@ -1156,6 +1168,14 @@ class config:
pass
del blacklisted, cfg
+ if target_root is None:
+ 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.
@@ -7324,7 +7344,7 @@ class MtimeDB(dict):
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:
@@ -7342,11 +7362,11 @@ def create_trees(config_root="/", target_root="/", trees=None):
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))