1 |
Author: zmedico |
2 |
Date: 2009-04-30 21:15:25 +0000 (Thu, 30 Apr 2009) |
3 |
New Revision: 13571 |
4 |
|
5 |
Modified: |
6 |
main/branches/2.1.6/pym/portage/__init__.py |
7 |
Log: |
8 |
Move PORTAGE_RESTRICT calculation to config.setcpv() (lazy evaluation) and |
9 |
fix it to work correctly for pre-built packages. (trunk r13569) |
10 |
|
11 |
Modified: main/branches/2.1.6/pym/portage/__init__.py |
12 |
=================================================================== |
13 |
--- main/branches/2.1.6/pym/portage/__init__.py 2009-04-30 21:14:27 UTC (rev 13570) |
14 |
+++ main/branches/2.1.6/pym/portage/__init__.py 2009-04-30 21:15:25 UTC (rev 13571) |
15 |
@@ -2063,29 +2063,43 @@ |
16 |
DeprecationWarning) |
17 |
return 1 |
18 |
|
19 |
- class _lazy_accept_license(object): |
20 |
- """ |
21 |
- Generate a pruned version of ACCEPT_LICENSE, by intersection with |
22 |
- LICENSE. This is required since otherwise ACCEPT_LICENSE might be too |
23 |
- big (bigger than ARG_MAX), causing execve() calls to fail with E2BIG |
24 |
- errors as in bug #262647. |
25 |
- """ |
26 |
- __slots__ = ('built_use', 'settings',) |
27 |
+ class _lazy_vars(object): |
28 |
|
29 |
+ __slots__ = ('built_use', 'settings', 'values') |
30 |
+ |
31 |
def __init__(self, built_use, settings): |
32 |
self.built_use = built_use |
33 |
self.settings = settings |
34 |
+ self.values = None |
35 |
|
36 |
- def __call__(self): |
37 |
+ def __getitem__(self, k): |
38 |
+ if self.values is None: |
39 |
+ self.values = self._init_values() |
40 |
+ return self.values[k] |
41 |
+ |
42 |
+ def _init_values(self): |
43 |
+ values = {} |
44 |
settings = self.settings |
45 |
use = self.built_use |
46 |
if use is None: |
47 |
use = settings['PORTAGE_USE'] |
48 |
+ use = set(use.split()) |
49 |
+ values['ACCEPT_LICENSE'] = self._accept_license(use, settings) |
50 |
+ values['PORTAGE_RESTRICT'] = self._restrict(use, settings) |
51 |
+ return values |
52 |
+ |
53 |
+ def _accept_license(self, use, settings): |
54 |
+ """ |
55 |
+ Generate a pruned version of ACCEPT_LICENSE, by intersection with |
56 |
+ LICENSE. This is required since otherwise ACCEPT_LICENSE might be |
57 |
+ too big (bigger than ARG_MAX), causing execve() calls to fail with |
58 |
+ E2BIG errors as in bug #262647. |
59 |
+ """ |
60 |
try: |
61 |
licenses = set(flatten( |
62 |
dep.use_reduce(dep.paren_reduce( |
63 |
settings['LICENSE']), |
64 |
- uselist=use.split()))) |
65 |
+ uselist=use))) |
66 |
except exception.InvalidDependString: |
67 |
licenses = set() |
68 |
licenses.discard('||') |
69 |
@@ -2093,6 +2107,16 @@ |
70 |
licenses.intersection_update(settings._accept_license) |
71 |
return ' '.join(sorted(licenses)) |
72 |
|
73 |
+ def _restrict(self, use, settings): |
74 |
+ try: |
75 |
+ restrict = set(flatten( |
76 |
+ dep.use_reduce(dep.paren_reduce( |
77 |
+ settings['RESTRICT']), |
78 |
+ uselist=use))) |
79 |
+ except exception.InvalidDependString: |
80 |
+ restrict = set() |
81 |
+ return ' '.join(sorted(restrict)) |
82 |
+ |
83 |
class _lazy_use_expand(object): |
84 |
""" |
85 |
Lazily evaluate USE_EXPAND variables since they are only needed when |
86 |
@@ -2315,8 +2339,11 @@ |
87 |
if k != 'USE': |
88 |
env_configdict.pop(k, None) |
89 |
|
90 |
+ lazy_vars = self._lazy_vars(built_use, self) |
91 |
env_configdict.addLazySingleton('ACCEPT_LICENSE', |
92 |
- self._lazy_accept_license(built_use, self)) |
93 |
+ lazy_vars.__getitem__, 'ACCEPT_LICENSE') |
94 |
+ env_configdict.addLazySingleton('PORTAGE_RESTRICT', |
95 |
+ lazy_vars.__getitem__, 'PORTAGE_RESTRICT') |
96 |
|
97 |
# If reset() has not been called, it's safe to return |
98 |
# early if IUSE has not changed. |
99 |
@@ -5331,14 +5358,6 @@ |
100 |
if not eapi_is_supported(eapi): |
101 |
# can't do anything with this. |
102 |
raise portage.exception.UnsupportedAPIException(mycpv, eapi) |
103 |
- try: |
104 |
- mysettings["PORTAGE_RESTRICT"] = " ".join(flatten( |
105 |
- portage.dep.use_reduce(portage.dep.paren_reduce( |
106 |
- mysettings["RESTRICT"]), |
107 |
- uselist=mysettings["PORTAGE_USE"].split()))) |
108 |
- except portage.exception.InvalidDependString: |
109 |
- # RESTRICT is validated again inside doebuild, so let this go |
110 |
- mysettings["PORTAGE_RESTRICT"] = "" |
111 |
|
112 |
if mysplit[2] == "r0": |
113 |
mysettings["PVR"]=mysplit[1] |