1 |
commit: a287c49f84ad3af7c8e20bebd116ea972f318e04 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Feb 17 21:39:21 2020 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Feb 17 22:49:32 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a287c49f |
7 |
|
8 |
AbstractEbuildProcess: add _async_start coroutine |
9 |
|
10 |
Convert the _start method to an _async_start coroutine, since |
11 |
eventually this method will need to be a coroutine in order to write |
12 |
messages to the build log as discussed in bug 709746. |
13 |
|
14 |
Bug: https://bugs.gentoo.org/709746 |
15 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
16 |
|
17 |
lib/_emerge/AbstractEbuildProcess.py | 33 +++++++++------------------------ |
18 |
lib/_emerge/MiscFunctionsProcess.py | 8 +++++--- |
19 |
2 files changed, 14 insertions(+), 27 deletions(-) |
20 |
|
21 |
diff --git a/lib/_emerge/AbstractEbuildProcess.py b/lib/_emerge/AbstractEbuildProcess.py |
22 |
index ddf04e9b3..7eb5dfd1b 100644 |
23 |
--- a/lib/_emerge/AbstractEbuildProcess.py |
24 |
+++ b/lib/_emerge/AbstractEbuildProcess.py |
25 |
@@ -1,4 +1,4 @@ |
26 |
-# Copyright 1999-2019 Gentoo Foundation |
27 |
+# Copyright 1999-2020 Gentoo Authors |
28 |
# Distributed under the terms of the GNU General Public License v2 |
29 |
|
30 |
import errno |
31 |
@@ -19,6 +19,7 @@ from portage.package.ebuild._ipc.ExitCommand import ExitCommand |
32 |
from portage.package.ebuild._ipc.QueryCommand import QueryCommand |
33 |
from portage import shutil, os |
34 |
from portage.util.futures import asyncio |
35 |
+from portage.util.futures.compat_coroutine import coroutine, coroutine_return |
36 |
from portage.util._pty import _create_pty_or_pipe |
37 |
from portage.util import apply_secpass_permissions |
38 |
|
39 |
@@ -30,7 +31,7 @@ class AbstractEbuildProcess(SpawnProcess): |
40 |
|
41 |
__slots__ = ('phase', 'settings',) + \ |
42 |
('_build_dir', '_build_dir_unlock', '_ipc_daemon', |
43 |
- '_exit_command', '_exit_timeout_id', '_start_future') |
44 |
+ '_exit_command', '_exit_timeout_id') |
45 |
|
46 |
_phases_without_builddir = ('clean', 'cleanrm', 'depend', 'help',) |
47 |
_phases_interactive_whitelist = ('config',) |
48 |
@@ -55,6 +56,10 @@ class AbstractEbuildProcess(SpawnProcess): |
49 |
self.phase = phase |
50 |
|
51 |
def _start(self): |
52 |
+ self.scheduler.run_until_complete(self._async_start()) |
53 |
+ |
54 |
+ @coroutine |
55 |
+ def _async_start(self): |
56 |
|
57 |
need_builddir = self.phase not in self._phases_without_builddir |
58 |
|
59 |
@@ -69,7 +74,7 @@ class AbstractEbuildProcess(SpawnProcess): |
60 |
self._eerror(textwrap.wrap(msg, 72)) |
61 |
self.returncode = 1 |
62 |
self._async_wait() |
63 |
- return |
64 |
+ coroutine_return() |
65 |
|
66 |
# Check if the cgroup hierarchy is in place. If it's not, mount it. |
67 |
if (os.geteuid() == 0 and platform.system() == 'Linux' |
68 |
@@ -142,11 +147,7 @@ class AbstractEbuildProcess(SpawnProcess): |
69 |
if 'PORTAGE_BUILDDIR_LOCKED' not in self.settings: |
70 |
self._build_dir = EbuildBuildDir( |
71 |
scheduler=self.scheduler, settings=self.settings) |
72 |
- self._start_future = self._build_dir.async_lock() |
73 |
- self._start_future.add_done_callback( |
74 |
- functools.partial(self._start_post_builddir_lock, |
75 |
- start_ipc_daemon=start_ipc_daemon)) |
76 |
- return |
77 |
+ yield self._build_dir.async_lock() |
78 |
else: |
79 |
self.settings.pop('PORTAGE_IPC_DAEMON', None) |
80 |
else: |
81 |
@@ -167,22 +168,6 @@ class AbstractEbuildProcess(SpawnProcess): |
82 |
else: |
83 |
self.settings.pop('PORTAGE_EBUILD_EXIT_FILE', None) |
84 |
|
85 |
- self._start_post_builddir_lock(start_ipc_daemon=start_ipc_daemon) |
86 |
- |
87 |
- def _start_post_builddir_lock(self, lock_future=None, start_ipc_daemon=False): |
88 |
- if lock_future is not None: |
89 |
- if lock_future is not self._start_future: |
90 |
- raise AssertionError('lock_future is not self._start_future') |
91 |
- self._start_future = None |
92 |
- if lock_future.cancelled(): |
93 |
- self._build_dir = None |
94 |
- self.cancelled = True |
95 |
- self._was_cancelled() |
96 |
- self._async_wait() |
97 |
- return |
98 |
- |
99 |
- lock_future.result() |
100 |
- |
101 |
if start_ipc_daemon: |
102 |
self.settings['PORTAGE_IPC_DAEMON'] = "1" |
103 |
self._start_ipc_daemon() |
104 |
|
105 |
diff --git a/lib/_emerge/MiscFunctionsProcess.py b/lib/_emerge/MiscFunctionsProcess.py |
106 |
index 89fd22635..cb0363820 100644 |
107 |
--- a/lib/_emerge/MiscFunctionsProcess.py |
108 |
+++ b/lib/_emerge/MiscFunctionsProcess.py |
109 |
@@ -1,8 +1,9 @@ |
110 |
-# Copyright 1999-2013 Gentoo Foundation |
111 |
+# Copyright 1999-2020 Gentoo Authors |
112 |
# Distributed under the terms of the GNU General Public License v2 |
113 |
|
114 |
from _emerge.AbstractEbuildProcess import AbstractEbuildProcess |
115 |
import portage |
116 |
+from portage.util.futures.compat_coroutine import coroutine |
117 |
portage.proxy.lazyimport.lazyimport(globals(), |
118 |
'portage.package.ebuild.doebuild:spawn' |
119 |
) |
120 |
@@ -15,7 +16,8 @@ class MiscFunctionsProcess(AbstractEbuildProcess): |
121 |
|
122 |
__slots__ = ('commands', 'ld_preload_sandbox') |
123 |
|
124 |
- def _start(self): |
125 |
+ @coroutine |
126 |
+ def _async_start(self): |
127 |
settings = self.settings |
128 |
portage_bin_path = settings["PORTAGE_BIN_PATH"] |
129 |
misc_sh_binary = os.path.join(portage_bin_path, |
130 |
@@ -26,7 +28,7 @@ class MiscFunctionsProcess(AbstractEbuildProcess): |
131 |
self.settings.get("PORTAGE_BACKGROUND") != "subprocess": |
132 |
self.logfile = settings.get("PORTAGE_LOG_FILE") |
133 |
|
134 |
- AbstractEbuildProcess._start(self) |
135 |
+ yield AbstractEbuildProcess._async_start(self) |
136 |
|
137 |
def _spawn(self, args, **kwargs): |
138 |
# If self.ld_preload_sandbox is None, default to free=False, |