From ca288e594b1160157c9743250422973d30587f0a Mon Sep 17 00:00:00 2001 From: Sebastian Luther Date: Wed, 11 Aug 2010 10:11:58 +0200 Subject: Introduce portage.eapi. Use it everywhere. --- pym/_emerge/EbuildExecuter.py | 3 ++- pym/_emerge/depgraph.py | 3 ++- pym/portage/dbapi/porttree.py | 3 ++- pym/portage/dep/dep_check.py | 5 +++-- pym/portage/eapi.py | 41 ++++++++++++++++++++++++++++++++++ pym/portage/package/ebuild/config.py | 9 ++++---- pym/portage/package/ebuild/doebuild.py | 13 +++++------ pym/repoman/checks.py | 15 +++++++------ 8 files changed, 69 insertions(+), 23 deletions(-) create mode 100644 pym/portage/eapi.py (limited to 'pym') diff --git a/pym/_emerge/EbuildExecuter.py b/pym/_emerge/EbuildExecuter.py index 4496c757d..90cf401a7 100644 --- a/pym/_emerge/EbuildExecuter.py +++ b/pym/_emerge/EbuildExecuter.py @@ -6,6 +6,7 @@ from _emerge.TaskSequence import TaskSequence from _emerge.CompositeTask import CompositeTask import portage from portage import os +from portage.eapi import eapi_has_src_prepare_and_src_configure class EbuildExecuter(CompositeTask): @@ -72,7 +73,7 @@ class EbuildExecuter(CompositeTask): pkg = self.pkg phases = self._phases eapi = pkg.metadata["EAPI"] - if eapi in ("0", "1"): + if not eapi_has_src_prepare_and_src_configure(eapi): # skip src_prepare and src_configure phases = phases[2:] diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index cf090d422..7a717df03 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -17,6 +17,7 @@ from portage.const import PORTAGE_PACKAGE_ATOM from portage.dbapi import dbapi from portage.dbapi.dep_expand import dep_expand from portage.dep import Atom +from portage.eapi import eapi_has_strong_blocks from portage.output import bold, blue, colorize, create_color_func, darkblue, \ darkgreen, green, nc_len, red, teal, turquoise, yellow bad = create_color_func("BAD") @@ -3954,7 +3955,7 @@ class depgraph(object): forbid_overlap = False heuristic_overlap = False for blocker in myblocker_uninstalls.parent_nodes(task): - if blocker.eapi in ("0", "1"): + if not eapi_has_strong_blocks(blocker.eapi): heuristic_overlap = True elif blocker.atom.blocker.overlap.forbid: forbid_overlap = True diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 3553ca1d8..4b266b48b 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -22,6 +22,7 @@ from portage.cache.cache_errors import CacheError from portage.cache.mappings import Mapping from portage.const import REPO_NAME_LOC from portage.dbapi import dbapi +from portage.eapi import eapi_has_src_uri_arrows from portage.exception import PortageException, \ FileNotFound, InvalidDependString, InvalidPackageName from portage.localization import _ @@ -656,7 +657,7 @@ class portdbapi(dbapi): (mypkg, eapi.lstrip("-"))) myuris = use_reduce(myuris, uselist=useflags, matchall=(useflags is None), \ - is_src_uri=True, allow_src_uri_file_renames=(eapi not in ("0", "1"))) + is_src_uri=True, allow_src_uri_file_renames=eapi_has_src_uri_arrows(eapi)) myuris = flatten(myuris) uri_map = OrderedDict() diff --git a/pym/portage/dep/dep_check.py b/pym/portage/dep/dep_check.py index 6ca96967f..691e1b50b 100644 --- a/pym/portage/dep/dep_check.py +++ b/pym/portage/dep/dep_check.py @@ -8,6 +8,7 @@ import logging import portage from portage.dep import Atom, dep_opconvert, match_from_list, \ remove_slot, use_reduce +from portage.eapi import eapi_has_strong_blocks, eapi_has_use_deps from portage.exception import InvalidAtom, InvalidDependString, ParseError from portage.localization import _ from portage.util import writemsg, writemsg_level @@ -65,10 +66,10 @@ def _expand_new_virtuals(mysplit, edebug, mydbapi, mysettings, myroot="/", _("invalid atom: '%s'") % x) else: if x.blocker and x.blocker.overlap.forbid and \ - eapi in ("0", "1"): + not eapi_has_strong_blocks(eapi): raise ParseError( _("invalid atom: '%s'") % (x,)) - if x.use and eapi in ("0", "1"): + if x.use and not eapi_has_use_deps(eapi): raise ParseError( _("invalid atom: '%s'") % (x,)) diff --git a/pym/portage/eapi.py b/pym/portage/eapi.py new file mode 100644 index 000000000..9f3394379 --- /dev/null +++ b/pym/portage/eapi.py @@ -0,0 +1,41 @@ +# Copyright 2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +def eapi_has_iuse_defaults(eapi): + return eapi != "0" + +def eapi_has_slot_deps(eapi): + return eapi != "0" + +def eapi_has_src_uri_arrows(eapi): + return eapi not in ("0", "1") + +def eapi_has_use_deps(eapi): + return eapi not in ("0", "1") + +def eapi_has_strong_blocks(eapi): + return eapi not in ("0", "1") + +def eapi_has_src_prepare_and_src_configure(eapi): + return eapi not in ("0", "1") + +def eapi_supports_prefix(eapi): + return eapi not in ("0", "1", "2") + +def eapi_exports_AA(eapi): + return eapi in ("0", "1", "2", "3") + +def eapi_exports_KV(eapi): + return eapi in ("0", "1", "2", "3") + +def eapi_exports_replace_vars(eapi): + return eapi not in ("0", "1", "2", "3") + +def eapi_has_pkg_pretend(eapi): + return eapi not in ("0", "1", "2", "3") + +def eapi_has_implicit_rdepend(eapi): + return eapi in ("0", "1", "2", "3") + +def eapi_has_dosed_dohard(eapi): + return eapi in ("0", "1", "2", "3") diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 72cdd728f..2f2850ff2 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -34,6 +34,7 @@ from portage.dbapi.vartree import vartree from portage.dep import Atom, best_match_to_list, dep_opconvert, \ flatten, isvalidatom, match_from_list, match_to_list, \ remove_slot, use_reduce +from portage.eapi import eapi_exports_AA, eapi_supports_prefix, eapi_exports_replace_vars from portage.env.loaders import KeyValuePairFileLoader from portage.exception import DirectoryNotFound, InvalidAtom, \ InvalidDependString, ParseError, PortageException @@ -2639,11 +2640,11 @@ class config(object): mydict["USE"] = self.get("PORTAGE_USE", "") # Don't export AA to the ebuild environment in EAPIs that forbid it - if eapi not in ("0", "1", "2", "3", "3_pre2"): + if not eapi_exports_AA(eapi): mydict.pop("AA", None) # Prefix variables are supported starting with EAPI 3. - if phase == 'depend' or eapi in (None, "0", "1", "2"): + if phase == 'depend' or eapi is None or eapi_supports_prefix(eapi): mydict.pop("ED", None) mydict.pop("EPREFIX", None) mydict.pop("EROOT", None) @@ -2652,11 +2653,11 @@ class config(object): mydict.pop('FILESDIR', None) if phase not in ("pretend", "setup", "preinst", "postinst") or \ - eapi in ("0", "1", "2", "3"): + not eapi_exports_replace_vars(eapi): mydict.pop("REPLACING_VERSIONS", None) if phase not in ("prerm", "postrm") or \ - eapi in ("0", "1", "2", "3"): + not eapi_exports_replace_vars(eapi): mydict.pop("REPLACED_BY_VERSION", None) return mydict diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py index f066df757..55dd3b08f 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -38,6 +38,8 @@ from portage.data import portage_gid, portage_uid, secpass, \ uid, userpriv_groups from portage.dbapi.virtual import fakedbapi from portage.dep import Atom, paren_enclose, use_reduce +from portage.eapi import eapi_exports_KV, eapi_has_src_uri_arrows, \ + eapi_has_src_prepare_and_src_configure, eapi_has_pkg_pretend from portage.elog import elog_process from portage.elog.messages import eerror, eqawarn from portage.exception import DigestException, FileNotFound, \ @@ -215,7 +217,7 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, mysettings["PORTAGE_BUILDDIR"], ".exit_status") #set up KV variable -- DEP SPEEDUP :: Don't waste time. Keep var persistent. - if eapi not in ('0', '1', '2', '3', '3_pre2'): + if not eapi_exports_KV(eapi): # Discard KV for EAPIs that don't support it. Cache KV is restored # from the backupenv whenever config.reset() is called. mysettings.pop('KV', None) @@ -1074,7 +1076,7 @@ def _validate_deps(mysettings, myroot, mydo, mydbapi): for k in misc_keys: try: use_reduce(metadata[k], matchall=True, is_src_uri=(k=="SRC_URI"), \ - allow_src_uri_file_renames=(eapi not in ("0", "1"))) + allow_src_uri_file_renames=eapi_has_src_uri_arrows(eapi)) except InvalidDependString as e: msgs.append(" %s: %s\n %s\n" % ( k, metadata[k], str(e))) @@ -1222,13 +1224,10 @@ def spawnebuild(mydo, actionmap, mysettings, debug, alwaysdep=0, eapi = mysettings["EAPI"] - if mydo == "configure" and eapi in ("0", "1"): + if mydo in ("configure", "prepare") and not eapi_has_src_prepare_and_src_configure(eapi): return os.EX_OK - if mydo == "prepare" and eapi in ("0", "1"): - return os.EX_OK - - if mydo == "pretend" and eapi in ("0", "1", "2", "3", "3_pre2"): + if mydo == "pretend" and not eapi_has_pkg_pretend(eapi): return os.EX_OK kwargs = actionmap[mydo]["args"] diff --git a/pym/repoman/checks.py b/pym/repoman/checks.py index 7e76bf782..67333419f 100644 --- a/pym/repoman/checks.py +++ b/pym/repoman/checks.py @@ -1,5 +1,5 @@ # repoman: Checks -# Copyright 2007 Gentoo Foundation +# Copyright 2007, 2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 """This module contains functions used in Repoman to ascertain the quality @@ -8,6 +8,7 @@ and correctness of an ebuild.""" import re import time import repoman.errors as errors +from portage.eapi import * class LineCheck(object): """Run a check on a line of an ebuild.""" @@ -230,7 +231,7 @@ class Eapi3EbuildAssignment(EbuildAssignment): readonly_assignment = re.compile(r'\s*(export\s+)?(ED|EPREFIX|EROOT)=') def check_eapi(self, eapi): - return eapi not in ('0', '1', '2') + return eapi_supports_prefix(eapi) class EbuildNestedDie(LineCheck): """Check ebuild for nested die statements (die statements in subshells""" @@ -341,7 +342,7 @@ class ImplicitRuntimeDeps(LineCheck): # Beginning with EAPI 4, there is no # implicit RDEPEND=$DEPEND assignment # to be concerned with. - return eapi in ('0', '1', '2', '3') + return eapi_has_implicit_rdepend(eapi) def check(self, num, line): if not self._rdepend: @@ -467,7 +468,7 @@ class SrcCompileEconf(PhaseCheck): configure_re = re.compile(r'\s(econf|./configure)') def check_eapi(self, eapi): - return eapi not in ('0', '1') + return eapi_has_src_prepare_and_src_configure(eapi) def phase_check(self, num, line): if self.in_phase == 'src_compile': @@ -481,7 +482,7 @@ class SrcUnpackPatches(PhaseCheck): src_prepare_tools_re = re.compile(r'\s(e?patch|sed)\s') def check_eapi(self, eapi): - return eapi not in ('0', '1') + return eapi_has_src_prepare_and_src_configure(eapi) def phase_check(self, num, line): if self.in_phase == 'src_unpack': @@ -518,7 +519,7 @@ class Eapi4IncompatibleFuncs(LineCheck): banned_commands_re = re.compile(r'^\s*(dosed|dohard)') def check_eapi(self, eapi): - return eapi not in ('0', '1', '2', '3', '3_pre2') + return not eapi_has_dosed_dohard(eapi) def check(self, num, line): m = self.banned_commands_re.match(line) @@ -532,7 +533,7 @@ class Eapi4GoneVars(LineCheck): undefined_vars_re = re.compile(r'.*\$(\{(AA|KV)\}|(AA|KV))') def check_eapi(self, eapi): - return eapi not in ('0', '1', '2', '3', '3_pre2') + return not eapi_exports_AA(eapi) or not eapi_exports_KV(eapi) def check(self, num, line): m = self.undefined_vars_re.match(line) -- cgit v1.2.3-1-g7c22