Introduce portage.eapi. Use it everywhere.
authorSebastian Luther <SebastianLuther@gmx.de>
Wed, 11 Aug 2010 08:11:58 +0000 (10:11 +0200)
committerZac Medico <zmedico@gentoo.org>
Wed, 11 Aug 2010 08:19:35 +0000 (01:19 -0700)
bin/repoman
pym/_emerge/EbuildExecuter.py
pym/_emerge/depgraph.py
pym/portage/dbapi/porttree.py
pym/portage/dep/dep_check.py
pym/portage/eapi.py [new file with mode: 0644]
pym/portage/package/ebuild/config.py
pym/portage/package/ebuild/doebuild.py
pym/repoman/checks.py

index ffb435238ade01e0f9ca5103a3be63865c7b8d3a..b296d675ffb1d79d140cc0e033f0fb7ad3e6e8de 100755 (executable)
@@ -72,6 +72,7 @@ from portage.output import bold, create_color_func, \
 from portage.output import ConsoleStyleFile, StyleWriter
 from portage.util import cmp_sort_key, writemsg_level
 from portage.package.ebuild.digestgen import digestgen
+from portage.eapi import *
 
 if sys.hexversion >= 0x3000000:
        basestring = str
@@ -1447,7 +1448,7 @@ for x in scanlist:
                        # Check that URIs don't reference a server from thirdpartymirrors.
                        for uri in portage.flatten(portage.dep.use_reduce( \
                                myaux["SRC_URI"], matchall=True, is_src_uri=True, \
-                               allow_src_uri_file_renames=(eapi not in ("0", "1")))):
+                               allow_src_uri_file_renames=eapi_has_src_uri_arrows(eapi))):
                                contains_mirror = False
                                for mirror in thirdpartymirrors:
                                        if uri.startswith(mirror):
@@ -1652,21 +1653,21 @@ for x in scanlist:
                                                                stats[mytype + '.suspect'] += 1
                                                                fails[mytype + '.suspect'].append(
                                                                        relative_path + ": '%s'" % atom)
-                                               if eapi == "0":
+                                               if not eapi_has_slot_deps(eapi):
                                                        if portage.dep.dep_getslot(atom):
                                                                stats['EAPI.incompatible'] += 1
                                                                fails['EAPI.incompatible'].append(
                                                                        (relative_path + ": %s slot dependency" + \
                                                                        " not supported with EAPI='%s':" + \
                                                                        " '%s'") % (mytype, eapi, atom))
-                                               if atom.use and eapi in ("0", "1"):
+                                               if atom.use and not eapi_has_use_deps(eapi):
                                                        stats['EAPI.incompatible'] += 1
                                                        fails['EAPI.incompatible'].append(
                                                                (relative_path + ": %s use dependency" + \
                                                                " not supported with EAPI='%s':" + \
                                                                " '%s'") % (mytype, eapi, atom))
                                                if atom.blocker and atom.blocker.overlap.forbid \
-                                                       and eapi in ("0", "1"):
+                                                       and not eapi_has_strong_blocks(eapi):
                                                        stats['EAPI.incompatible'] += 1
                                                        fails['EAPI.incompatible'].append(
                                                                (relative_path + ": %s new blocker syntax" + \
@@ -1709,7 +1710,7 @@ for x in scanlist:
                        if myuse[mypos] and (myuse[mypos] in muselist):
                                del myuse[mypos]
 
-               if default_use and eapi == "0":
+               if default_use and not eapi_has_iuse_defaults(eapi):
                        for myflag in default_use:
                                stats['EAPI.incompatible'] += 1
                                fails['EAPI.incompatible'].append(
index 4496c757d2e5407bf2b43c731ddb3911e91a3a1f..90cf401a75c41076ca5ed22736040ed38007066d 100644 (file)
@@ -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:]
 
index cf090d4226e523729bee2550fd3cb1a5064c1926..7a717df032bedbb765c2a611b4243b3575f790ef 100644 (file)
@@ -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
index 3553ca1d854223946afe90702a308c3a49fad271..4b266b48be408cb778c4226a9b59bc2d1aef5a10 100644 (file)
@@ -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()
index 6ca96967f19921893d80e9943c06536438ea9a8a..691e1b50bd0c324b5da15ce33c3139cbaee374db 100644 (file)
@@ -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 (file)
index 0000000..9f33943
--- /dev/null
@@ -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")
index 72cdd728f4b31c6528cc91473b3530ad9fdf80be..2f2850ff2889d05b3babb2ba93ae2b9c0ef294ee 100644 (file)
@@ -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
index f066df7576c080234079bde6e28f996aef905456..55dd3b08fdb49b6684879b95d6cc8ffc7c86e54d 100644 (file)
@@ -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"]
index 7e76bf78266555481a0c034d0bf1abafb93acbed..67333419f2b6298ac6645749bba50289c58ffe16 100644 (file)
@@ -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)