From 5fed550abb53eec2799c652bc54f829b8f4a815c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 30 Apr 2009 21:15:25 +0000 Subject: [PATCH] Move PORTAGE_RESTRICT calculation to config.setcpv() (lazy evaluation) and fix it to work correctly for pre-built packages. (trunk r13569) svn path=/main/branches/2.1.6/; revision=13571 --- pym/portage/__init__.py | 57 +++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 6e42e2088..d09797f07 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -2063,29 +2063,43 @@ class config(object): DeprecationWarning) return 1 - class _lazy_accept_license(object): - """ - Generate a pruned version of ACCEPT_LICENSE, by intersection with - LICENSE. This is required since otherwise ACCEPT_LICENSE might be too - big (bigger than ARG_MAX), causing execve() calls to fail with E2BIG - errors as in bug #262647. - """ - __slots__ = ('built_use', 'settings',) + class _lazy_vars(object): + + __slots__ = ('built_use', 'settings', 'values') def __init__(self, built_use, settings): self.built_use = built_use self.settings = settings + self.values = None - def __call__(self): + def __getitem__(self, k): + if self.values is None: + self.values = self._init_values() + return self.values[k] + + def _init_values(self): + values = {} settings = self.settings use = self.built_use if use is None: use = settings['PORTAGE_USE'] + use = set(use.split()) + values['ACCEPT_LICENSE'] = self._accept_license(use, settings) + values['PORTAGE_RESTRICT'] = self._restrict(use, settings) + return values + + def _accept_license(self, use, settings): + """ + Generate a pruned version of ACCEPT_LICENSE, by intersection with + LICENSE. This is required since otherwise ACCEPT_LICENSE might be + too big (bigger than ARG_MAX), causing execve() calls to fail with + E2BIG errors as in bug #262647. + """ try: licenses = set(flatten( dep.use_reduce(dep.paren_reduce( settings['LICENSE']), - uselist=use.split()))) + uselist=use))) except exception.InvalidDependString: licenses = set() licenses.discard('||') @@ -2093,6 +2107,16 @@ class config(object): licenses.intersection_update(settings._accept_license) return ' '.join(sorted(licenses)) + def _restrict(self, use, settings): + try: + restrict = set(flatten( + dep.use_reduce(dep.paren_reduce( + settings['RESTRICT']), + uselist=use))) + except exception.InvalidDependString: + restrict = set() + return ' '.join(sorted(restrict)) + class _lazy_use_expand(object): """ Lazily evaluate USE_EXPAND variables since they are only needed when @@ -2315,8 +2339,11 @@ class config(object): if k != 'USE': env_configdict.pop(k, None) + lazy_vars = self._lazy_vars(built_use, self) env_configdict.addLazySingleton('ACCEPT_LICENSE', - self._lazy_accept_license(built_use, self)) + lazy_vars.__getitem__, 'ACCEPT_LICENSE') + env_configdict.addLazySingleton('PORTAGE_RESTRICT', + lazy_vars.__getitem__, 'PORTAGE_RESTRICT') # If reset() has not been called, it's safe to return # early if IUSE has not changed. @@ -5331,14 +5358,6 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m if not eapi_is_supported(eapi): # can't do anything with this. raise portage.exception.UnsupportedAPIException(mycpv, eapi) - try: - mysettings["PORTAGE_RESTRICT"] = " ".join(flatten( - portage.dep.use_reduce(portage.dep.paren_reduce( - mysettings["RESTRICT"]), - uselist=mysettings["PORTAGE_USE"].split()))) - except portage.exception.InvalidDependString: - # RESTRICT is validated again inside doebuild, so let this go - mysettings["PORTAGE_RESTRICT"] = "" if mysplit[2] == "r0": mysettings["PVR"]=mysplit[1] -- 2.26.2