doebuild_environent: handle A/AA initialization
authorZac Medico <zmedico@gentoo.org>
Tue, 18 Jan 2011 20:43:12 +0000 (12:43 -0800)
committerZac Medico <zmedico@gentoo.org>
Tue, 18 Jan 2011 20:43:12 +0000 (12:43 -0800)
This allows elimination of duplicate code, some of which was introduced
by the fix for bug #351505.

pym/_emerge/EbuildBuild.py
pym/_emerge/EbuildExecuter.py
pym/portage/package/ebuild/_spawn_nofetch.py
pym/portage/package/ebuild/doebuild.py

index 23509584201fd694a93589772048c5311dfac9cc..1eab21d341d10a79da7df2c78dd7ff435a1a03c9 100644 (file)
@@ -226,13 +226,6 @@ class EbuildBuild(CompositeTask):
                        return
 
                self.returncode = None
-               if "A" not in self.settings.configdict["pkg"]:
-                       mytree = os.path.dirname(os.path.dirname(
-                               os.path.dirname(self._ebuild_path)))
-                       portdb = self.pkg.root_config.trees[self._tree].dbapi
-                       fetch_map = portdb.getFetchMap(self.pkg.cpv,
-                               useflags=self.pkg.use.enabled, mytree=mytree)
-                       self.settings.configdict["pkg"]["A"] = " ".join(fetch_map)
                nofetch_phase = EbuildPhase(background=self.background,
                        phase='nofetch', scheduler=self.scheduler, settings=self.settings)
                self._start_task(nofetch_phase, self._nofetch_exit)
index 419ee6b1a8d83a709f29c8a3d0fb91de7b9b4ef3..d3a4dd8dd6b951b37e66e4feda66679efe4cba76 100644 (file)
@@ -35,13 +35,7 @@ class EbuildExecuter(CompositeTask):
 
                portdb = pkg.root_config.trees['porttree'].dbapi
                ebuild_path = settings['EBUILD']
-               mytree = os.path.dirname(os.path.dirname(
-                       os.path.dirname(ebuild_path)))
-               alist = portdb.getFetchMap(pkg.cpv,
-                       useflags=pkg.use.enabled, mytree=mytree)
-               aalist = portdb.getFetchMap(pkg.cpv, mytree=mytree)
-               settings.configdict["pkg"]["A"] = " ".join(alist)
-               settings.configdict["pkg"]["AA"] = " ".join(aalist)
+               alist = settings.configdict["pkg"].get("A", "").split()
                _prepare_fake_distdir(settings, alist)
 
                if eapi_exports_replace_vars(settings['EAPI']):
index 1678faf56b2c2ac905c331396f1de6f1d5b3d944..befdc89d4792026b83830fd835c1414a4ab42a1e 100644 (file)
@@ -60,12 +60,6 @@ def spawn_nofetch(portdb, ebuild_path, settings=None):
        try:
                doebuild_environment(ebuild_path, 'nofetch',
                        settings=settings, db=portdb)
-               if "A" not in settings.configdict["pkg"]:
-                       mytree = os.path.dirname(os.path.dirname(
-                               os.path.dirname(ebuild_path)))
-                       fetch_map = portdb.getFetchMap(settings.mycpv,
-                               useflags=settings["PORTAGE_USE"].split(), mytree=mytree)
-                       settings.configdict["pkg"]["A"] = " ".join(fetch_map)
                restrict = settings['PORTAGE_RESTRICT'].split()
                defined_phases = settings['DEFINED_PHASES'].split()
                if not defined_phases:
index aeb3f864a95a2fd45c37e12dc53e79400c88c8f9..753b36af6ea01103f34bdf2e4b7026346d9f6f99 100644 (file)
@@ -37,6 +37,7 @@ from portage.const import EBUILD_SH_ENV_FILE, EBUILD_SH_ENV_DIR, \
        EBUILD_SH_BINARY, INVALID_ENV_FILE, MISC_SH_BINARY
 from portage.data import portage_gid, portage_uid, secpass, \
        uid, userpriv_groups
+from portage.dbapi.porttree import _parse_uri_map
 from portage.dbapi.virtual import fakedbapi
 from portage.dep import Atom, paren_enclose, use_reduce
 from portage.eapi import eapi_exports_KV, eapi_exports_merge_type, \
@@ -132,6 +133,7 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
        mydbapi = db
        ebuild_path = os.path.abspath(myebuild)
        pkg_dir     = os.path.dirname(ebuild_path)
+       mytree = os.path.dirname(os.path.dirname(pkg_dir))
 
        if "CATEGORY" in mysettings.configdict["pkg"]:
                cat = mysettings.configdict["pkg"]["CATEGORY"]
@@ -199,7 +201,6 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
        mysettings["PF"]       = mypv
 
        if hasattr(mydbapi, '_repo_info'):
-               mytree = os.path.dirname(os.path.dirname(pkg_dir))
                repo_info = mydbapi._repo_info[mytree]
                mysettings['PORTDIR'] = repo_info.portdir
                mysettings['PORTDIR_OVERLAY'] = repo_info.portdir_overlay
@@ -240,6 +241,31 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
                        # can't do anything with this.
                        raise UnsupportedAPIException(mycpv, eapi)
 
+               if "A" not in mysettings.configdict["pkg"] or \
+                       "AA" not in mysettings.configdict["pkg"]:
+                       src_uri, = mydbapi.aux_get(mysettings.mycpv,
+                               ["SRC_URI"], mytree=mytree)
+                       metadata = {
+                               "EAPI"    : eapi,
+                               "SRC_URI" : src_uri,
+                       }
+                       use = frozenset(mysettings["PORTAGE_USE"].split())
+                       try:
+                               uri_map = _parse_uri_map(mysettings.mycpv, metadata, use=use)
+                       except InvalidDependString:
+                               mysettings.configdict["pkg"]["A"] = ""
+                       else:
+                               mysettings.configdict["pkg"]["A"] = " ".join(uri_map)
+
+                       # NOTE: We initialize AA here, regardless of EAPI, since
+                       # it's used by doebuild() for fetchall support.
+                       try:
+                               uri_map = _parse_uri_map(mysettings.mycpv, metadata)
+                       except InvalidDependString:
+                               mysettings.configdict["pkg"]["AA"] = ""
+                       else:
+                               mysettings.configdict["pkg"]["AA"] = " ".join(uri_map)
+
        if mysplit[2] == "r0":
                mysettings["PVR"]=mysplit[1]
        else:
@@ -681,50 +707,21 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
                # Only try and fetch the files if we are going to need them ...
                # otherwise, if user has FEATURES=noauto and they run `ebuild clean
                # unpack compile install`, we will try and fetch 4 times :/
-               need_distfiles = \
+               need_distfiles = tree == "porttree" and \
                        (mydo in ("fetch", "unpack") or \
                        mydo not in ("digest", "manifest") and "noauto" not in features)
-               alist = mysettings.configdict["pkg"].get("A")
-               aalist = mysettings.configdict["pkg"].get("AA")
-               if not hasattr(mydbapi, 'getFetchMap'):
-                       if alist is None:
-                               alist = ""
-                       if aalist is None:
-                               aalist = ""
-                       alist = set(alist.split())
-                       aalist = set(aalist.split())
-               elif alist is None or aalist is None or \
-                       need_distfiles:
-                       # Make sure we get the correct tree in case there are overlays.
-                       mytree = os.path.realpath(
-                               os.path.dirname(os.path.dirname(mysettings["O"])))
-                       useflags = mysettings["PORTAGE_USE"].split()
-                       try:
-                               alist = mydbapi.getFetchMap(mycpv, useflags=useflags,
-                                       mytree=mytree)
-                               aalist = mydbapi.getFetchMap(mycpv, mytree=mytree)
-                       except InvalidDependString as e:
-                               writemsg("!!! %s\n" % str(e), noiselevel=-1)
-                               writemsg(_("!!! Invalid SRC_URI for '%s'.\n") % mycpv,
-                                       noiselevel=-1)
-                               del e
-                               return 1
-                       mysettings.configdict["pkg"]["A"] = " ".join(alist)
-                       mysettings.configdict["pkg"]["AA"] = " ".join(aalist)
-
-                       if need_distfiles:
-                               if "mirror" in features or fetchall:
-                                       fetchme = aalist
-                               else:
-                                       fetchme = alist
-                               if not fetch(fetchme, mysettings, listonly=listonly,
-                                       fetchonly=fetchonly):
-                                       spawn_nofetch(mydbapi, myebuild, settings=mysettings)
-                                       return 1
+               alist = set(mysettings.configdict["pkg"].get("A", "").split())
+               aalist = set(mysettings.configdict["pkg"].get("AA", "").split())
+               if need_distfiles:
 
-               else:
-                       alist = set(alist.split())
-                       aalist = set(aalist.split())
+                       if "mirror" in features or fetchall:
+                               fetchme = aalist
+                       else:
+                               fetchme = alist
+                       if not fetch(fetchme, mysettings, listonly=listonly,
+                               fetchonly=fetchonly):
+                               spawn_nofetch(mydbapi, myebuild, settings=mysettings)
+                               return 1
 
                if mydo == "fetch":
                        # Files are already checked inside fetch(),