Make spawnebuild() use EbuildPhase to eliminate duplicate code.
authorZac Medico <zmedico@gentoo.org>
Tue, 17 Aug 2010 03:59:24 +0000 (20:59 -0700)
committerZac Medico <zmedico@gentoo.org>
Tue, 17 Aug 2010 03:59:24 +0000 (20:59 -0700)
pym/_emerge/EbuildPhase.py
pym/_emerge/EbuildProcess.py
pym/_emerge/MiscFunctionsProcess.py
pym/portage/package/ebuild/doebuild.py

index 55f50b3dbbde23d214dcca5270ccda0354d7c52d..5680925e44cdd71c1529a18cb33eb38d8a021f39 100644 (file)
@@ -4,11 +4,13 @@
 from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
 from _emerge.EbuildProcess import EbuildProcess
 from _emerge.CompositeTask import CompositeTask
-from portage.package.ebuild.doebuild import _check_build_log, \
-       _post_phase_cmds, _post_src_install_chost_fix, \
-       _post_src_install_uid_fix
 from portage.util import writemsg, writemsg_stdout
 import portage
+portage.proxy.lazyimport.lazyimport(globals(),
+       'portage.package.ebuild.doebuild:_check_build_log,' + \
+               '_post_phase_cmds,_post_src_install_chost_fix,' + \
+               '_post_src_install_uid_fix'
+)
 from portage import os
 from portage import _encodings
 from portage import _unicode_decode
@@ -17,12 +19,13 @@ import codecs
 
 class EbuildPhase(CompositeTask):
 
-       __slots__ = ("background", "phase",
+       __slots__ = ("actionmap", "background", "phase",
                "scheduler", "settings")
 
        def _start(self):
 
-               ebuild_process = EbuildProcess(background=self.background,
+               ebuild_process = EbuildProcess(actionmap=self.actionmap,
+                       background=self.background,
                        phase=self.phase, scheduler=self.scheduler,
                        settings=self.settings)
 
index c60c2bda9c22931890e6dbaecf01a456ffb60c1e..84a8d1b61a32b0a9bb2b397371152ad7bda97d2b 100644 (file)
@@ -2,16 +2,18 @@
 # Distributed under the terms of the GNU General Public License v2
 
 from _emerge.AbstractEbuildProcess import AbstractEbuildProcess
+import portage
+portage.proxy.lazyimport.lazyimport(globals(),
+       'portage.package.ebuild.doebuild:_post_phase_userpriv_perms,' + \
+               '_spawn_actionmap,spawn@doebuild_spawn'
+)
 from portage import _shell_quote
 from portage import os
 from portage.const import EBUILD_SH_BINARY
-from portage.package.ebuild.doebuild import  _post_phase_userpriv_perms
-from portage.package.ebuild.doebuild import spawn as doebuild_spawn
-from portage.package.ebuild.doebuild import _spawn_actionmap
 
 class EbuildProcess(AbstractEbuildProcess):
 
-       __slots__ = ()
+       __slots__ = ('actionmap',)
 
        def _start(self):
                # Don't open the log file during the clean phase since the
@@ -23,7 +25,9 @@ class EbuildProcess(AbstractEbuildProcess):
 
        def _spawn(self, args, **kwargs):
                self.settings["EBUILD_PHASE"] = self.phase
-               actionmap = _spawn_actionmap(self.settings)
+               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
index 270da427737b026b62c5aecb0835b9d2967c9192..d7119037e949803688fb4f6c739765af8cc3f5a9 100644 (file)
@@ -3,8 +3,10 @@
 
 from _emerge.AbstractEbuildProcess import AbstractEbuildProcess
 import portage
+portage.proxy.lazyimport.lazyimport(globals(),
+       'portage.package.ebuild.doebuild:spawn'
+)
 from portage import os
-from portage.package.ebuild.doebuild import spawn
 
 class MiscFunctionsProcess(AbstractEbuildProcess):
        """
index 2451cea196cba8f4765905d7a9513149eacbdbf4..ad51bfa54803e8f6b22a55011cb52fc448901830 100644 (file)
@@ -26,7 +26,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
 )
 
 from portage import auxdbkeys, bsd_chflags, dep_check, \
-       eapi_is_supported, merge, os, selinux, StringIO, \
+       eapi_is_supported, merge, os, selinux, \
        unmerge, _encodings, _parse_eapi_ebuild_head, _os_merge, \
        _shell_quote, _unicode_decode, _unicode_encode
 from portage.const import EBUILD_SH_ENV_FILE, EBUILD_SH_ENV_DIR, \
@@ -51,6 +51,7 @@ from portage.util import apply_recursive_permissions, \
        writemsg, writemsg_stdout, write_atomic
 from portage.util.lafilefixer import rewrite_lafile    
 from portage.versions import _pkgsplit
+from _emerge.EbuildPhase import EbuildPhase
 from _emerge.EbuildSpawnProcess import EbuildSpawnProcess
 from _emerge.TaskScheduler import TaskScheduler
 
@@ -1163,47 +1164,23 @@ def spawnebuild(mydo, actionmap, mysettings, debug, alwaysdep=0,
        if mydo == "pretend" and not eapi_has_pkg_pretend(eapi):
                return os.EX_OK
 
-       kwargs = actionmap[mydo]["args"]
-       mysettings["EBUILD_PHASE"] = mydo
-
-       try:
-               phase_retval = spawn(actionmap[mydo]["cmd"] % mydo,
-                       mysettings, debug=debug, logfile=logfile,
-                       fd_pipes=fd_pipes, returnpid=returnpid, **kwargs)
-       finally:
-               mysettings["EBUILD_PHASE"] = ""
-
        if returnpid:
-               return phase_retval
-
-       _post_phase_userpriv_perms(mysettings)
-       if mydo == "install":
-               out = StringIO()
-               _check_build_log(mysettings, out=out)
-               msg = _unicode_decode(out.getvalue(),
-                       encoding=_encodings['content'], errors='replace')
-               if msg:
-                       writemsg_stdout(msg, noiselevel=-1)
-                       if logfile is not None:
-                               try:
-                                       f = codecs.open(_unicode_encode(logfile,
-                                               encoding=_encodings['fs'], errors='strict'),
-                                               mode='a', encoding=_encodings['content'],
-                                               errors='replace')
-                               except EnvironmentError:
-                                       pass
-                               else:
-                                       f.write(msg)
-                                       f.close()
-               if phase_retval == os.EX_OK:
-                       _post_src_install_chost_fix(mysettings)
-                       phase_retval = _post_src_install_checks(mysettings)
-
-       if mydo == "test" and phase_retval != os.EX_OK and \
-               "test-fail-continue" in mysettings.features:
-               phase_retval = os.EX_OK
-
-       return phase_retval
+               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
 
 _post_phase_cmds = {
 
@@ -1230,30 +1207,6 @@ def _post_phase_userpriv_perms(mysettings):
                        uid=portage_uid, gid=portage_gid, dirmode=0o70, dirmask=0,
                        filemode=0o60, filemask=0)
 
-def _post_src_install_checks(mysettings):
-       out = portage.StringIO()
-       _post_src_install_uid_fix(mysettings, out)
-       global _post_phase_cmds
-       retval = _spawn_misc_sh(mysettings, _post_phase_cmds["install"],
-               phase='internal_post_src_install')
-       if retval != os.EX_OK:
-               writemsg(_("!!! install_qa_check failed; exiting.\n"),
-                       fd=out, noiselevel=-1)
-
-       msg = _unicode_decode(out.getvalue(),
-               encoding=_encodings['content'], errors='replace')
-       if msg:
-               writemsg_stdout(msg, noiselevel=-1)
-               log_path = mysettings.get("PORTAGE_LOG_FILE")
-               if log_path is not None:
-                       log_file = codecs.open(_unicode_encode(log_path,
-                               encoding=_encodings['fs'], errors='strict'),
-                               mode='a', encoding=_encodings['content'], errors='replace')
-                       log_file.write(msg)
-                       log_file.close()
-
-       return retval
-
 def _check_build_log(mysettings, out=None):
        """
        Search the content of $PORTAGE_LOG_FILE if it exists