ebuilds.
* Make Package.metadata['LICENSE'] access trigger USE conditional evaluation.
* Make Package.metadata['PROVIDE'] access trigger USE conditional evaluation.
* Initialize Package.metadata['CHOST'] in the Package constructor for
unbuilt ebuilds.
svn path=/main/trunk/; revision=13686
import portage
from portage.cache.mappings import slot_dict_class
-
+from portage.dep import paren_reduce, use_reduce, \
+ paren_normalize, paren_enclose
from _emerge.Task import Task
class Package(Task):
"root_config", "type_name",
"category", "counter", "cp", "cpv_split",
"inherited", "iuse", "mtime",
- "pf", "pv_split", "root", "slot", "slot_atom", "use")
+ "pf", "pv_split", "root", "slot", "slot_atom",) + \
+ ("_use",)
metadata_keys = [
"CHOST", "COUNTER", "DEPEND", "EAPI",
Task.__init__(self, **kwargs)
self.root = self.root_config.root
self.metadata = _PackageMetadataWrapper(self, self.metadata)
+ if not self.built:
+ self.metadata['CHOST'] = self.root_config.settings.get('CHOST', '')
self.cp = portage.cpv_getkey(self.cpv)
slot = self.slot
if not slot:
self.cpv_split = portage.catpkgsplit(self.cpv)
self.pv_split = self.cpv_split[1:]
- class _use(object):
+ class _use_class(object):
__slots__ = ("__weakref__", "enabled")
def __init__(self, use):
self.enabled = frozenset(use)
+ @property
+ def use(self):
+ if self._use is None:
+ self._use = self._use_class(self.metadata['USE'].split())
+ return self._use
+
class _iuse(object):
__slots__ = ("__weakref__", "all", "enabled", "disabled", "iuse_implicit", "regex", "tokens")
__slots__ = ("_pkg",)
_wrapped_keys = frozenset(
- ["COUNTER", "INHERITED", "IUSE", "SLOT", "USE", "_mtime_"])
+ ["COUNTER", "INHERITED", "IUSE", "SLOT", "_mtime_"])
def __init__(self, pkg, metadata):
_PackageMetadataWrapperBase.__init__(self)
self._pkg = pkg
+ """LICENSE with USE conditionals evaluated."""
+
+ if not pkg.built:
+ # USE is lazy, but we want it to show up in self.keys().
+ self['USE'] = ''
+
self.update(metadata)
+ def __getitem__(self, k):
+ v = _PackageMetadataWrapperBase.__getitem__(self, k)
+ if k in ('PROVIDE', 'LICENSE',):
+ if '?' in v:
+ v = paren_enclose(paren_normalize(use_reduce(
+ paren_reduce(v), uselist=self._pkg.use.enabled)))
+ self[k] = v
+
+ elif k == 'USE' and not self._pkg.built:
+ if not v:
+ # This is lazy because it's expensive.
+ pkgsettings = self._pkg.root_config.trees[
+ 'porttree'].dbapi.doebuild_settings
+ pkgsettings.setcpv(self._pkg)
+ v = pkgsettings["PORTAGE_USE"]
+ self['USE'] = v
+
+ return v
+
def __setitem__(self, k, v):
_PackageMetadataWrapperBase.__setitem__(self, k, v)
if k in self._wrapped_keys:
def _set_slot(self, k, v):
self._pkg.slot = v
- def _set_use(self, k, v):
- self._pkg.use = self._pkg._use(v.split())
-
def _set_counter(self, k, v):
if isinstance(v, basestring):
try:
db_keys = list(self.trees[root_config.root][
tree_type].dbapi._aux_cache_keys)
metadata = izip(db_keys, db.aux_get(cpv, db_keys))
- pkg = Package(cpv=cpv, metadata=metadata,
+ return Package(built=(type_name != 'ebuild'),
+ cpv=cpv, metadata=metadata,
root_config=root_config, installed=installed)
- if type_name == "ebuild":
- settings = self.pkgsettings[root_config.root]
- settings.setcpv(pkg)
- pkg.metadata["USE"] = settings["PORTAGE_USE"]
- pkg.metadata['CHOST'] = settings.get('CHOST', '')
-
- return pkg
metadata = izip(db_keys, portdb.aux_get(mykey, db_keys))
pkg = Package(type_name="ebuild", root_config=root_config,
cpv=mykey, metadata=metadata, onlydeps=onlydeps)
- pkgsettings.setcpv(pkg)
- pkg.metadata["USE"] = pkgsettings["PORTAGE_USE"]
- pkg.metadata['CHOST'] = pkgsettings.get('CHOST', '')
self._pkg_cache[pkg] = pkg
args.append(PackageArg(arg=x, package=pkg,
root_config=root_config))
continue
reinstall_for_flags = None
cache_key = (pkg_type, root, cpv, pkg_status)
- calculated_use = True
pkg = self._pkg_cache.get(cache_key)
if pkg is None:
- calculated_use = False
try:
metadata = izip(db_keys, db.aux_get(cpv, db_keys))
except KeyError:
metadata = pkg.metadata
if not built:
metadata['CHOST'] = pkgsettings.get('CHOST', '')
- if not built and ("?" in metadata["LICENSE"] or \
- "?" in metadata["PROVIDE"]):
- # This is avoided whenever possible because
- # it's expensive. It only needs to be done here
- # if it has an effect on visibility.
- pkgsettings.setcpv(pkg)
- metadata["USE"] = pkgsettings["PORTAGE_USE"]
- calculated_use = True
self._pkg_cache[pkg] = pkg
if not installed or (built and matched_packages):
if not visible(pkgsettings, pkg_eb):
continue
- if not pkg.built and not calculated_use:
- # This is avoided whenever possible because
- # it's expensive.
- pkgsettings.setcpv(pkg)
- pkg.metadata["USE"] = pkgsettings["PORTAGE_USE"]
+ # Calculation of USE for unbuilt ebuilds is relatively
+ # expensive, so it is only performed lazily, after the
+ # above visibility checks are complete.
if pkg.cp != atom.cp:
# A cpv can be returned from dbapi.match() as an
myarg = None
if root == self.target_root:
try:
- # Ebuild USE must have been calculated prior
- # to this point, in case atoms have USE deps.
myarg = self._iter_atoms_for_pkg(pkg).next()
except StopIteration:
pass
metadata = izip(db_keys, db.aux_get(cpv, db_keys))
except KeyError:
raise portage.exception.PackageNotFound(cpv)
- pkg = Package(cpv=cpv, metadata=metadata,
+ pkg = Package(built=(type_name != "ebuild"), cpv=cpv,
+ metadata=metadata,
root_config=root_config, installed=installed)
- if type_name == "ebuild":
- settings = self.pkgsettings[root_config.root]
- settings.setcpv(pkg)
- pkg.metadata["USE"] = settings["PORTAGE_USE"]
- pkg.metadata['CHOST'] = settings.get('CHOST', '')
self._pkg_cache[pkg] = pkg
return pkg
installed=installed, metadata=metadata,
operation=action, root_config=root_config,
type_name=pkg_type)
- if pkg_type == "ebuild":
- pkgsettings = self.pkgsettings[myroot]
- pkgsettings.setcpv(pkg)
- pkg.metadata["USE"] = pkgsettings["PORTAGE_USE"]
- pkg.metadata['CHOST'] = pkgsettings.get('CHOST', '')
self._pkg_cache[pkg] = pkg
root_config = self.roots[pkg.root]
db.aux_get(cpv, db_keys)))
except KeyError:
metadata = None
- if metadata and not built:
- pkgsettings.setcpv(cpv, mydb=metadata)
- metadata["USE"] = pkgsettings["PORTAGE_USE"]
- metadata['CHOST'] = pkgsettings.get('CHOST', '')
+
if metadata is None:
mreasons = ["corruption"]
else: