Skip to content

Commit

Permalink
AbstractEbuildProcess: add _async_start coroutine
Browse files Browse the repository at this point in the history
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@gentoo.org>
  • Loading branch information
zmedico committed Feb 17, 2020
1 parent d66e9ec commit a287c49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
33 changes: 9 additions & 24 deletions lib/_emerge/AbstractEbuildProcess.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,6 +19,7 @@
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

Expand All @@ -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',)
Expand All @@ -55,6 +56,10 @@ def __init__(self, **kwargs):
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

Expand All @@ -69,7 +74,7 @@ def _start(self):
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'
Expand Down Expand Up @@ -142,11 +147,7 @@ def _start(self):
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:
Expand All @@ -167,22 +168,6 @@ def _start(self):
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()
Expand Down
8 changes: 5 additions & 3 deletions lib/_emerge/MiscFunctionsProcess.py
Original file line number Diff line number Diff line change
@@ -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'
)
Expand All @@ -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,
Expand All @@ -26,7 +28,7 @@ def _start(self):
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,
Expand Down

0 comments on commit a287c49

Please sign in to comment.