1 |
Let PORTAGE_CONFIGROOT/etc/make.conf, where PORTAGE_CONFIGROOT is not /, |
2 |
specify ROOT. |
3 |
|
4 |
In general, a set of configuration files other than the base set is |
5 |
intended for a target root other than the live system. Normally, it is |
6 |
intended for a particular target root. This patch allows make.conf in this |
7 |
situation to specify the target root. A ROOT environment variable, if set, |
8 |
overrides this setting (so the user can use a configuration that's |
9 |
normally used for target A on target B, if desired). |
10 |
|
11 |
This patch also postpones the setting of defaults for PORTAGE_CONFIGROOT |
12 |
and ROOT until just before they are used, so that it is possible to |
13 |
distinguish an emerge command with "ROOT=/" from one without ROOT set. |
14 |
|
15 |
Signed-off-by: Daniel Barkalow <barkalow@××××××××.org> |
16 |
|
17 |
Index: pym/portage.py |
18 |
=================================================================== |
19 |
--- pym/portage.py (revision 5090) |
20 |
+++ pym/portage.py (working copy) |
21 |
@@ -833,9 +833,15 @@ |
22 |
if not test or (str(test.__class__) != 'portage.config'): |
23 |
raise TypeError, "Invalid type for config object: %s" % test.__class__ |
24 |
|
25 |
+def check_var_directory(varname, var): |
26 |
+ if not os.path.isdir(var): |
27 |
+ writemsg("!!! Error: %s='%s' is not a directory. Please correct this.\n" % (var, varname), |
28 |
+ noiselevel=-1) |
29 |
+ raise portage_exception.DirectoryNotFound(var) |
30 |
+ |
31 |
class config: |
32 |
def __init__(self, clone=None, mycpv=None, config_profile_path=None, |
33 |
- config_incrementals=None, config_root="/", target_root="/", |
34 |
+ config_incrementals=None, config_root=None, target_root=None, |
35 |
local_config=True): |
36 |
|
37 |
self.already_in_regenerate = 0 |
38 |
@@ -921,17 +927,13 @@ |
39 |
# backupenv is for calculated incremental variables. |
40 |
self.backupenv = os.environ.copy() |
41 |
|
42 |
+ if not config_root: |
43 |
+ config_root = "/" |
44 |
+ |
45 |
config_root = \ |
46 |
normalize_path(config_root).rstrip(os.path.sep) + os.path.sep |
47 |
- target_root = \ |
48 |
- normalize_path(target_root).rstrip(os.path.sep) + os.path.sep |
49 |
|
50 |
- for k, v in (("PORTAGE_CONFIGROOT", config_root), |
51 |
- ("ROOT", target_root)): |
52 |
- if not os.path.isdir(v): |
53 |
- writemsg("!!! Error: %s='%s' is not a directory. Please correct this.\n" % (k, v), |
54 |
- noiselevel=-1) |
55 |
- raise portage_exception.DirectoryNotFound(v) |
56 |
+ check_var_directory("PORTAGE_CONFIGROOT", config_root) |
57 |
|
58 |
self.depcachedir = DEPCACHE_PATH |
59 |
|
60 |
@@ -1125,7 +1127,9 @@ |
61 |
noiselevel=-1) |
62 |
sys.exit(1) |
63 |
|
64 |
- |
65 |
+ if config_root != "/" and "ROOT" in self.mygcfg and not target_root: |
66 |
+ target_root = self.mygcfg["ROOT"] |
67 |
+ |
68 |
self.configlist.append(self.mygcfg) |
69 |
self.configdict["conf"]=self.configlist[-1] |
70 |
|
71 |
@@ -1156,6 +1160,14 @@ |
72 |
pass |
73 |
del blacklisted, cfg |
74 |
|
75 |
+ if not target_root: |
76 |
+ target_root = "/" |
77 |
+ |
78 |
+ target_root = \ |
79 |
+ normalize_path(target_root).rstrip(os.path.sep) + os.path.sep |
80 |
+ |
81 |
+ check_var_directory("ROOT", target_root) |
82 |
+ |
83 |
env_d = getconfig( |
84 |
os.path.join(target_root, "etc", "profile.env"), expand=False) |
85 |
# env_d will be None if profile.env doesn't exist. |
86 |
@@ -7327,7 +7339,7 @@ |
87 |
commit_mtimedb(mydict=d, filename=self.filename) |
88 |
self._clean_data = copy.deepcopy(d) |
89 |
|
90 |
-def create_trees(config_root="/", target_root="/", trees=None): |
91 |
+def create_trees(config_root=None, target_root=None, trees=None): |
92 |
if trees is None: |
93 |
trees = {} |
94 |
else: |
95 |
@@ -7345,11 +7357,11 @@ |
96 |
|
97 |
myroots = [(settings["ROOT"], settings)] |
98 |
if settings["ROOT"] != "/": |
99 |
- settings = config(config_root="/", target_root="/", |
100 |
+ settings = config(config_root=None, target_root=None, |
101 |
config_incrementals=portage_const.INCREMENTALS) |
102 |
settings.lock() |
103 |
settings.validate() |
104 |
- myroots.append(("/", settings)) |
105 |
+ myroots.append((settings["ROOT"], settings)) |
106 |
|
107 |
for myroot, mysettings in myroots: |
108 |
trees[myroot] = portage_util.LazyItemsDict(trees.get(myroot, None)) |
109 |
Index: bin/emerge |
110 |
=================================================================== |
111 |
--- bin/emerge (revision 5090) |
112 |
+++ bin/emerge (working copy) |
113 |
@@ -4289,7 +4289,7 @@ |
114 |
def load_emerge_config(trees=None): |
115 |
kwargs = {} |
116 |
for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), ("target_root", "ROOT")): |
117 |
- kwargs[k] = os.environ.get(envvar, "/") |
118 |
+ kwargs[k] = os.environ.get(envvar) |
119 |
trees = portage.create_trees(trees=trees, **kwargs) |
120 |
|
121 |
settings = trees["/"]["vartree"].settings |
122 |
-- |
123 |
gentoo-portage-dev@g.o mailing list |