From 96225c8cde5d6d3134d17afb9791c08d206cfd74 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 17 May 2008 22:44:22 +0000 Subject: [PATCH] Add the environment and some more files to the existing make.defaults variable substitution support. Variable substitution occurs in the following order: * env.d * env * make.globals * make.defaults * make.conf svn path=/main/trunk/; revision=10351 --- pym/portage/__init__.py | 89 +++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 26ef9fae6..b02bc5160 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -1267,9 +1267,60 @@ class config(object): self.puseforce_list.append(cpdict) del rawpuseforce + make_conf = getconfig( + os.path.join(config_root, MAKE_CONF_FILE.lstrip(os.path.sep)), + tolerant=tolerant, allow_sourcing=True) + + # Allow ROOT setting to come from make.conf if it's not overridden + # by the constructor argument (from the calling environment). + if target_root is None and "ROOT" in make_conf: + target_root = make_conf["ROOT"] + if target_root is None: + target_root = "/" + + # The expand_map is used for variable substitution + # in getconfig() calls, and the getconfig() calls + # update expand_map with the value of each variable + # assignment that occurs. Variable substitution occurs + # in the following order: + # + # * env.d + # * env + # * make.globals + # * make.defaults + # * make.conf + # + expand_map = {} + + env_d = getconfig(os.path.join(target_root, "etc", "profile.env"), + expand=expand_map) + # env_d will be None if profile.env doesn't exist. + if env_d: + self.configdict["env.d"].update(env_d) + expand_map.update(env_d) + + # backupenv is used for calculating incremental variables. + self.backupenv = os.environ.copy() + expand_map.update(self.backupenv) + # make.globals should not be relative to config_root # because it only contains constants. - self.mygcfg = getconfig(os.path.join("/etc", "make.globals")) + self.mygcfg = getconfig(os.path.join("/etc", "make.globals"), + expand=expand_map) + + if env_d: + # Remove duplicate values so they don't override updated + # profile.env values later (profile.env is reloaded in each + # call to self.regenerate). + for k, v in env_d.iteritems(): + try: + if self.backupenv[k] == v: + del self.backupenv[k] + except KeyError: + pass + del k, v + + self.configdict["env"] = self.backupenv.copy() if self.mygcfg is None: self.mygcfg = {} @@ -1280,7 +1331,6 @@ class config(object): self.make_defaults_use = [] self.mygcfg = {} if self.profiles: - expand_map = {} mygcfg_dlists = [getconfig(os.path.join(x, "make.defaults"), expand=expand_map) for x in self.profiles] @@ -1298,7 +1348,7 @@ class config(object): self.mygcfg = getconfig( os.path.join(config_root, MAKE_CONF_FILE.lstrip(os.path.sep)), - tolerant=tolerant, allow_sourcing=True) + tolerant=tolerant, allow_sourcing=True, expand=expand_map) if self.mygcfg is None: self.mygcfg = {} @@ -1307,12 +1357,7 @@ class config(object): "PROFILE_ONLY_VARIABLES", "").split() for k in profile_only_variables: self.mygcfg.pop(k, None) - - # Allow ROOT setting to come from make.conf if it's not overridden - # by the constructor argument (from the calling environment). - if 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] @@ -1323,8 +1368,6 @@ class config(object): self.configlist.append({}) self.configdict["auto"]=self.configlist[-1] - # backupenv is used for calculating incremental variables. - self.backupenv = os.environ.copy() self.configlist.append(self.backupenv) # XXX Why though? self.configdict["backupenv"]=self.configlist[-1] @@ -1332,8 +1375,7 @@ class config(object): for k in profile_only_variables: self.backupenv.pop(k, None) - self.configlist.append(self.backupenv.copy()) - self.configdict["env"]=self.configlist[-1] + self.configlist.append(self.configdict["env"]) # make lookuplist for loading package.* self.lookuplist=self.configlist[:] @@ -1347,33 +1389,12 @@ class config(object): cfg.pop(blacklisted, None) del blacklisted, cfg - if target_root is None: - target_root = "/" - target_root = normalize_path(os.path.abspath( target_root)).rstrip(os.path.sep) + os.path.sep portage.util.ensure_dirs(target_root) 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. - if env_d: - self.configdict["env.d"].update(env_d) - # Remove duplicate values so they don't override updated - # profile.env values later (profile.env is reloaded in each - # call to self.regenerate). - for cfg in (self.configdict["backupenv"], - self.configdict["env"]): - for k, v in env_d.iteritems(): - try: - if cfg[k] == v: - del cfg[k] - except KeyError: - pass - del cfg, k, v - self["PORTAGE_CONFIGROOT"] = config_root self.backup_changes("PORTAGE_CONFIGROOT") self["ROOT"] = target_root -- 2.26.2