From: Zac Medico Date: Tue, 17 Aug 2010 03:59:24 +0000 (-0700) Subject: Make spawnebuild() use EbuildPhase to eliminate duplicate code. X-Git-Tag: v2.2_rc68~141 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2f508a0f40252ad00b8055d27818647d0d0f5970;p=portage.git Make spawnebuild() use EbuildPhase to eliminate duplicate code. --- diff --git a/pym/_emerge/EbuildPhase.py b/pym/_emerge/EbuildPhase.py index 55f50b3db..5680925e4 100644 --- a/pym/_emerge/EbuildPhase.py +++ b/pym/_emerge/EbuildPhase.py @@ -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) diff --git a/pym/_emerge/EbuildProcess.py b/pym/_emerge/EbuildProcess.py index c60c2bda9..84a8d1b61 100644 --- a/pym/_emerge/EbuildProcess.py +++ b/pym/_emerge/EbuildProcess.py @@ -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 diff --git a/pym/_emerge/MiscFunctionsProcess.py b/pym/_emerge/MiscFunctionsProcess.py index 270da4277..d7119037e 100644 --- a/pym/_emerge/MiscFunctionsProcess.py +++ b/pym/_emerge/MiscFunctionsProcess.py @@ -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): """ diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py index 2451cea19..ad51bfa54 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -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