Unify ebuild spawing some more. All proper ebuild phases which execute
authorZac Medico <zmedico@gentoo.org>
Tue, 17 Aug 2010 13:39:17 +0000 (06:39 -0700)
committerZac Medico <zmedico@gentoo.org>
Tue, 17 Aug 2010 13:39:17 +0000 (06:39 -0700)
ebuild.sh are spawned via _doebuild_spawn() now. No exceptions.

pym/_emerge/EbuildProcess.py
pym/portage/package/ebuild/doebuild.py
pym/portage/package/ebuild/fetch.py

index 70c724314ab2362d9ff9e571656a67f4f8641f39..6a9c8df62ffa0111a3807307320f56f696be779b 100644 (file)
@@ -5,11 +5,9 @@ from _emerge.AbstractEbuildProcess import AbstractEbuildProcess
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
        'portage.package.ebuild.doebuild:_post_phase_userpriv_perms,' + \
-               '_spawn_actionmap,_unsandboxed_phases,spawn@doebuild_spawn'
+               '_spawn_actionmap,_doebuild_spawn'
 )
-from portage import _shell_quote
 from portage import os
-from portage.const import EBUILD_SH_BINARY
 
 class EbuildProcess(AbstractEbuildProcess):
 
@@ -24,30 +22,13 @@ class EbuildProcess(AbstractEbuildProcess):
                AbstractEbuildProcess._start(self)
 
        def _spawn(self, args, **kwargs):
-               self.settings["EBUILD_PHASE"] = self.phase
-               if self.phase in _unsandboxed_phases:
-                       kwargs['free'] = True
-               if self.phase == 'depend':
-                       kwargs['droppriv'] = 'userpriv' in self.settings.features
+
                actionmap = self.actionmap
                if actionmap is None:
                        actionmap = _spawn_actionmap(self.settings)
-               if self.phase in actionmap:
-                       kwargs.update(actionmap[self.phase]["args"])
-                       cmd = actionmap[self.phase]["cmd"] % self.phase
-               else:
-                       if self.phase == 'cleanrm':
-                               ebuild_sh_arg = 'clean'
-                       else:
-                               ebuild_sh_arg = self.phase
-
-                       cmd = "%s %s" % (_shell_quote(os.path.join(
-                               self.settings["PORTAGE_BIN_PATH"],
-                               os.path.basename(EBUILD_SH_BINARY))), ebuild_sh_arg)
-               try:
-                       return doebuild_spawn(cmd, self.settings, **kwargs)
-               finally:
-                       self.settings.pop("EBUILD_PHASE", None)
+
+               return _doebuild_spawn(self.phase, self.settings,
+                               actionmap, **kwargs)
 
        def _set_returncode(self, wait_retval):
                AbstractEbuildProcess._set_returncode(self, wait_retval)
index 355088036aa643bba5f7d0eafb873ce932aaa9e3..9c9450febd7d3116cd0cde7fc24a8923c4dc898e 100644 (file)
@@ -62,6 +62,50 @@ _unsandboxed_phases = frozenset([
        "prerm", "setup"
 ])
 
+def _doebuild_spawn(phase, settings, actionmap=None, **kwargs):
+       """
+       All proper ebuild phases which execute ebuild.sh are spawned
+       via this function. No exceptions.
+       """
+
+       if phase in _unsandboxed_phases:
+               kwargs['free'] = True
+
+       if phase == 'depend':
+               kwargs['droppriv'] = 'userpriv' in settings.features
+
+       if actionmap is not None and phase in actionmap:
+               kwargs.update(actionmap[phase]["args"])
+               cmd = actionmap[phase]["cmd"] % phase
+       else:
+               if phase == 'cleanrm':
+                       ebuild_sh_arg = 'clean'
+               else:
+                       ebuild_sh_arg = phase
+
+               cmd = "%s %s" % (_shell_quote(
+                       os.path.join(settings["PORTAGE_BIN_PATH"],
+                       os.path.basename(EBUILD_SH_BINARY))),
+                       ebuild_sh_arg)
+
+       settings['EBUILD_PHASE'] = phase
+       try:
+               return spawn(cmd, settings, **kwargs)
+       finally:
+               settings.pop('EBUILD_PHASE', None)
+
+def _spawn_phase(phase, settings, actionmap=None, **kwargs):
+       if kwargs.get('returnpid'):
+               return _doebuild_spawn(phase, settings, actionmap=actionmap, **kwargs)
+
+       task_scheduler = TaskScheduler()
+       ebuild_phase = EbuildPhase(background=False,
+               phase=phase, scheduler=task_scheduler.sched_iface,
+               settings=settings)
+       task_scheduler.add(ebuild_phase)
+       task_scheduler.run()
+       return ebuild_phase.returncode
+
 def doebuild_environment(myebuild, mydo, myroot, mysettings,
        debug, use_cache, mydbapi):
 
@@ -574,7 +618,7 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
                if mydo in ("config", "help", "info", "postinst",
                        "preinst", "pretend", "postrm", "prerm", "setup"):
                        return _spawn_phase(mydo, mysettings,
-                               fd_pipes=fd_pipes, returnpid=returnpid)
+                               fd_pipes=fd_pipes, logfile=logfile, returnpid=returnpid)
 
                mycpv = "/".join((mysettings["CATEGORY"], mysettings["PF"]))
 
@@ -1079,30 +1123,6 @@ def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, fakero
 
        return proc.returncode
 
-def _spawn_phase(phase, settings, **kwargs):
-       if kwargs.get('returnpid'):
-               if phase in _unsandboxed_phases:
-                       kwargs['free'] = True
-               portage_bin_path = settings["PORTAGE_BIN_PATH"]
-               ebuild_sh_binary = os.path.join(portage_bin_path,
-                       os.path.basename(EBUILD_SH_BINARY))
-               if phase == 'cleanrm':
-                       ebuild_sh_arg = 'clean'
-               else:
-                       ebuild_sh_arg = phase
-               if phase == 'depend':
-                       kwargs['droppriv'] = 'userpriv' in settings.features
-               return spawn("%s %s" % (_shell_quote(ebuild_sh_binary), ebuild_sh_arg),
-                       settings, **kwargs)
-
-       task_scheduler = TaskScheduler()
-       ebuild_phase = EbuildPhase(background=False,
-               phase=phase, scheduler=task_scheduler.sched_iface,
-               settings=settings)
-       task_scheduler.add(ebuild_phase)
-       task_scheduler.run()
-       return ebuild_phase.returncode
-
 # parse actionmap to spawn ebuild with the appropriate args
 def spawnebuild(mydo, actionmap, mysettings, debug, alwaysdep=0,
        logfile=None, fd_pipes=None, returnpid=False):
@@ -1124,23 +1144,9 @@ def spawnebuild(mydo, actionmap, mysettings, debug, alwaysdep=0,
        if mydo == "pretend" and not eapi_has_pkg_pretend(eapi):
                return os.EX_OK
 
-       if returnpid:
-               kwargs = actionmap[mydo]["args"]
-               mysettings["EBUILD_PHASE"] = mydo
-               try:
-                       return spawn(actionmap[mydo]["cmd"] % mydo,
-                               mysettings, debug=debug, logfile=logfile,
-                               fd_pipes=fd_pipes, returnpid=returnpid, **kwargs)
-               finally:
-                       mysettings["EBUILD_PHASE"] = ""
-
-       task_scheduler = TaskScheduler()
-       ebuild_phase = EbuildPhase(actionmap=actionmap, background=False,
-               phase=mydo, scheduler=task_scheduler.sched_iface,
-               settings=mysettings)
-       task_scheduler.add(ebuild_phase)
-       task_scheduler.run()
-       return ebuild_phase.returncode
+       return _spawn_phase(mydo, mysettings,
+               actionmap=actionmap, logfile=logfile,
+               fd_pipes=fd_pipes, returnpid=returnpid)
 
 _post_phase_cmds = {
 
index 0481ed2b093ffe2de2a735075fe3775a3750358b..86d4db96d8126b3b68767f517f877e9c50ad1732 100644 (file)
@@ -20,7 +20,7 @@ import portage
 portage.proxy.lazyimport.lazyimport(globals(),
        'portage.package.ebuild.config:check_config_instance,config',
        'portage.package.ebuild.doebuild:doebuild_environment,' + \
-               'spawn@doebuild_spawn',
+               '_doebuild_spawn',
        'portage.package.ebuild.prepare_build_dirs:prepare_build_dirs',
 )
 
@@ -1091,18 +1091,12 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                                2 : sys.stderr.fileno(),
                                        }
 
-                                       ebuild_phase = mysettings.get("EBUILD_PHASE")
                                        try:
-                                               mysettings["EBUILD_PHASE"] = "nofetch"
-                                               doebuild_spawn(_shell_quote(EBUILD_SH_BINARY) + \
-                                                       " nofetch", mysettings, fd_pipes=fd_pipes)
+                                               _doebuild_spawn("nofetch", mysettings, fd_pipes=fd_pipes)
                                        finally:
-                                               if ebuild_phase is None:
-                                                       mysettings.pop("EBUILD_PHASE", None)
-                                               else:
-                                                       mysettings["EBUILD_PHASE"] = ebuild_phase
                                                if private_tmpdir is not None:
                                                        shutil.rmtree(private_tmpdir)
+                                                       private_tmpdir = None
 
                        elif restrict_fetch:
                                pass