commit:     a287c49f84ad3af7c8e20bebd116ea972f318e04
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Feb 17 21:39:21 2020 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Feb 17 22:49:32 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=a287c49f

AbstractEbuildProcess: add _async_start coroutine

Convert the _start method to an _async_start coroutine, since
eventually this method will need to be a coroutine in order to write
messages to the build log as discussed in bug 709746.

Bug: https://bugs.gentoo.org/709746
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/_emerge/AbstractEbuildProcess.py | 33 +++++++++------------------------
 lib/_emerge/MiscFunctionsProcess.py  |  8 +++++---
 2 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/lib/_emerge/AbstractEbuildProcess.py 
b/lib/_emerge/AbstractEbuildProcess.py
index ddf04e9b3..7eb5dfd1b 100644
--- a/lib/_emerge/AbstractEbuildProcess.py
+++ b/lib/_emerge/AbstractEbuildProcess.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2019 Gentoo Foundation
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import errno
@@ -19,6 +19,7 @@ from portage.package.ebuild._ipc.ExitCommand import 
ExitCommand
 from portage.package.ebuild._ipc.QueryCommand import QueryCommand
 from portage import shutil, os
 from portage.util.futures import asyncio
+from portage.util.futures.compat_coroutine import coroutine, coroutine_return
 from portage.util._pty import _create_pty_or_pipe
 from portage.util import apply_secpass_permissions
 
@@ -30,7 +31,7 @@ class AbstractEbuildProcess(SpawnProcess):
 
        __slots__ = ('phase', 'settings',) + \
                ('_build_dir', '_build_dir_unlock', '_ipc_daemon',
-               '_exit_command', '_exit_timeout_id', '_start_future')
+               '_exit_command', '_exit_timeout_id')
 
        _phases_without_builddir = ('clean', 'cleanrm', 'depend', 'help',)
        _phases_interactive_whitelist = ('config',)
@@ -55,6 +56,10 @@ class AbstractEbuildProcess(SpawnProcess):
                        self.phase = phase
 
        def _start(self):
+               self.scheduler.run_until_complete(self._async_start())
+
+       @coroutine
+       def _async_start(self):
 
                need_builddir = self.phase not in self._phases_without_builddir
 
@@ -69,7 +74,7 @@ class AbstractEbuildProcess(SpawnProcess):
                        self._eerror(textwrap.wrap(msg, 72))
                        self.returncode = 1
                        self._async_wait()
-                       return
+                       coroutine_return()
 
                # Check if the cgroup hierarchy is in place. If it's not, mount 
it.
                if (os.geteuid() == 0 and platform.system() == 'Linux'
@@ -142,11 +147,7 @@ class AbstractEbuildProcess(SpawnProcess):
                                if 'PORTAGE_BUILDDIR_LOCKED' not in 
self.settings:
                                        self._build_dir = EbuildBuildDir(
                                                scheduler=self.scheduler, 
settings=self.settings)
-                                       self._start_future = 
self._build_dir.async_lock()
-                                       self._start_future.add_done_callback(
-                                               
functools.partial(self._start_post_builddir_lock,
-                                               
start_ipc_daemon=start_ipc_daemon))
-                                       return
+                                       yield self._build_dir.async_lock()
                        else:
                                self.settings.pop('PORTAGE_IPC_DAEMON', None)
                else:
@@ -167,22 +168,6 @@ class AbstractEbuildProcess(SpawnProcess):
                        else:
                                self.settings.pop('PORTAGE_EBUILD_EXIT_FILE', 
None)
 
-               
self._start_post_builddir_lock(start_ipc_daemon=start_ipc_daemon)
-
-       def _start_post_builddir_lock(self, lock_future=None, 
start_ipc_daemon=False):
-               if lock_future is not None:
-                       if lock_future is not self._start_future:
-                               raise AssertionError('lock_future is not 
self._start_future')
-                       self._start_future = None
-                       if lock_future.cancelled():
-                               self._build_dir = None
-                               self.cancelled = True
-                               self._was_cancelled()
-                               self._async_wait()
-                               return
-
-                       lock_future.result()
-
                if start_ipc_daemon:
                        self.settings['PORTAGE_IPC_DAEMON'] = "1"
                        self._start_ipc_daemon()

diff --git a/lib/_emerge/MiscFunctionsProcess.py 
b/lib/_emerge/MiscFunctionsProcess.py
index 89fd22635..cb0363820 100644
--- a/lib/_emerge/MiscFunctionsProcess.py
+++ b/lib/_emerge/MiscFunctionsProcess.py
@@ -1,8 +1,9 @@
-# Copyright 1999-2013 Gentoo Foundation
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 from _emerge.AbstractEbuildProcess import AbstractEbuildProcess
 import portage
+from portage.util.futures.compat_coroutine import coroutine
 portage.proxy.lazyimport.lazyimport(globals(),
        'portage.package.ebuild.doebuild:spawn'
 )
@@ -15,7 +16,8 @@ class MiscFunctionsProcess(AbstractEbuildProcess):
 
        __slots__ = ('commands', 'ld_preload_sandbox')
 
-       def _start(self):
+       @coroutine
+       def _async_start(self):
                settings = self.settings
                portage_bin_path = settings["PORTAGE_BIN_PATH"]
                misc_sh_binary = os.path.join(portage_bin_path,
@@ -26,7 +28,7 @@ class MiscFunctionsProcess(AbstractEbuildProcess):
                        self.settings.get("PORTAGE_BACKGROUND") != "subprocess":
                        self.logfile = settings.get("PORTAGE_LOG_FILE")
 
-               AbstractEbuildProcess._start(self)
+               yield AbstractEbuildProcess._async_start(self)
 
        def _spawn(self, args, **kwargs):
                # If self.ld_preload_sandbox is None, default to free=False,

Reply via email to