diff options
author | Zac Medico <zmedico@gentoo.org> | 2012-05-08 23:38:47 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2012-05-09 00:09:22 -0700 |
commit | 20817801dd4ef0117bcc7b33c90650da1e920385 (patch) | |
tree | c2e30f858b87e9d1504774a8e84791aff149453c /pym/portage/__init__.py | |
parent | 476f99337da69662660bfe2a0406b9ac5b4678c4 (diff) | |
download | portage-20817801dd4ef0117bcc7b33c90650da1e920385.tar.gz portage-20817801dd4ef0117bcc7b33c90650da1e920385.tar.bz2 portage-20817801dd4ef0117bcc7b33c90650da1e920385.zip |
Parse EAPI with pattern from PMS section 7.3.1.
This implements the specification that was approved in Gentoo's council
meeting on May 8, 2012 (see bug #402167). The parse-eapi-ebuild-head
FEATURES setting is now enabled by default, and causes non-conformant
ebuilds to be treated as invalid. This behavior will soon become
enabled unconditionally.
Diffstat (limited to 'pym/portage/__init__.py')
-rw-r--r-- | pym/portage/__init__.py | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 3495b96ec..31d580742 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -435,29 +435,25 @@ def eapi_is_supported(eapi): return False return eapi <= portage.const.EAPI -# Generally, it's best not to assume that cache entries for unsupported EAPIs -# can be validated. However, the current package manager specification does not -# guarantee that the EAPI can be parsed without sourcing the ebuild, so -# it's too costly to discard existing cache entries for unsupported EAPIs. -# Therefore, by default, assume that cache entries for unsupported EAPIs can be -# validated. If FEATURES=parse-eapi-* is enabled, this assumption is discarded -# since the EAPI can be determined without the incurring the cost of sourcing -# the ebuild. -_validate_cache_for_unsupported_eapis = True - -_parse_eapi_ebuild_head_re = re.compile(r'^EAPI=[\'"]?([^\'"#]*)') -_parse_eapi_ebuild_head_max_lines = 30 +# This pattern is specified by PMS section 7.3.1. +_pms_eapi_re = re.compile(r"^[ \t]*EAPI=(['\"]?)([A-Za-z0-9+_.-]*)\1[ \t]*(#.*)?$") +_comment_or_blank_line = re.compile(r"^\s*(#.*)?$") def _parse_eapi_ebuild_head(f): - count = 0 + eapi = None + eapi_lineno = None + lineno = 0 for line in f: - m = _parse_eapi_ebuild_head_re.match(line) - if m is not None: - return m.group(1).strip() - count += 1 - if count >= _parse_eapi_ebuild_head_max_lines: + lineno += 1 + m = _comment_or_blank_line.match(line) + if m is None: + eapi_lineno = lineno + m = _pms_eapi_re.match(line) + if m is not None: + eapi = m.group(2) break - return '0' + + return (eapi, eapi_lineno) def _movefile(src, dest, **kwargs): """Calls movefile and raises a PortageException if an error occurs.""" |