Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH 2/2] EbuildBuild: use async_unlock (bug 614108)
Date: Thu, 19 Apr 2018 17:03:12
Message-Id: 20180419170244.14451-3-zmedico@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 0/2] EbuildBuildDir: add async_unlock method (bug 614108) by Zac Medico
1 This adds an _async_unlock_builddir method which accepts a
2 returncode parameter for cases where it should set the
3 returncode and notify exit listeners.
4
5 Bug: https://bugs.gentoo.org/614108
6 ---
7 pym/_emerge/EbuildBuild.py | 52 ++++++++++++++++++++++++++++------------------
8 1 file changed, 32 insertions(+), 20 deletions(-)
9
10 diff --git a/pym/_emerge/EbuildBuild.py b/pym/_emerge/EbuildBuild.py
11 index 48f470483..833996c37 100644
12 --- a/pym/_emerge/EbuildBuild.py
13 +++ b/pym/_emerge/EbuildBuild.py
14 @@ -3,6 +3,7 @@
15
16 from __future__ import unicode_literals
17
18 +import functools
19 import io
20
21 import _emerge.emergelog
22 @@ -23,6 +24,8 @@ from portage import _encodings, _unicode_decode, _unicode_encode, os
23 from portage.package.ebuild.digestcheck import digestcheck
24 from portage.package.ebuild.doebuild import _check_temp_dir
25 from portage.package.ebuild._spawn_nofetch import SpawnNofetchWithoutBuilddir
26 +from portage.util._async.AsyncTaskFuture import AsyncTaskFuture
27 +
28
29 class EbuildBuild(CompositeTask):
30
31 @@ -185,8 +188,7 @@ class EbuildBuild(CompositeTask):
32
33 def _pre_clean_exit(self, pre_clean_phase):
34 if self._default_exit(pre_clean_phase) != os.EX_OK:
35 - self._unlock_builddir()
36 - self.wait()
37 + self._async_unlock_builddir(returncode=self.returncode)
38 return
39
40 # for log handling
41 @@ -209,10 +211,7 @@ class EbuildBuild(CompositeTask):
42 msg_lines.append(msg)
43 fetcher._eerror(msg_lines)
44 portage.elog.elog_process(self.pkg.cpv, self.settings)
45 - self.returncode = 1
46 - self._current_task = None
47 - self._unlock_builddir()
48 - self.wait()
49 + self._async_unlock_builddir(returncode=1)
50 return
51
52 if already_fetched:
53 @@ -283,8 +282,7 @@ class EbuildBuild(CompositeTask):
54
55 if 'fetch' not in self.pkg.restrict and \
56 'nofetch' not in self.pkg.defined_phases:
57 - self._unlock_builddir()
58 - self.wait()
59 + self._async_unlock_builddir(returncode=self.returncode)
60 return
61
62 self.returncode = None
63 @@ -294,18 +292,32 @@ class EbuildBuild(CompositeTask):
64
65 def _nofetch_exit(self, nofetch_phase):
66 self._final_exit(nofetch_phase)
67 - self._unlock_builddir()
68 - self.returncode = 1
69 - self.wait()
70 + self._async_unlock_builddir(returncode=1)
71
72 - def _unlock_builddir(self):
73 + def _async_unlock_builddir(self, returncode=None):
74 + """
75 + Release the lock asynchronously, and if a returncode parameter
76 + is given then set self.returncode and notify exit listeners.
77 + """
78 + if returncode is not None:
79 + # The returncode will be set after unlock is complete.
80 + self.returncode = None
81 portage.elog.elog_process(self.pkg.cpv, self.settings)
82 - self._build_dir.unlock()
83 + self._start_task(
84 + AsyncTaskFuture(future=self._build_dir.async_unlock()),
85 + functools.partial(self._unlock_builddir_exit, returncode=returncode))
86 +
87 + def _unlock_builddir_exit(self, unlock_task, returncode=None):
88 + self._assert_current(unlock_task)
89 + # Normally, async_unlock should not raise an exception here.
90 + unlock_task.future.result()
91 + if returncode is not None:
92 + self.returncode = returncode
93 + self.wait()
94
95 def _build_exit(self, build):
96 if self._default_exit(build) != os.EX_OK:
97 - self._unlock_builddir()
98 - self.wait()
99 + self._async_unlock_builddir(returncode=self.returncode)
100 return
101
102 buildpkg = self._buildpkg
103 @@ -370,8 +382,7 @@ class EbuildBuild(CompositeTask):
104 """
105
106 if self._default_exit(packager) != os.EX_OK:
107 - self._unlock_builddir()
108 - self.wait()
109 + self._async_unlock_builddir(returncode=self.returncode)
110 return
111
112 if self.opts.buildpkgonly:
113 @@ -425,8 +436,9 @@ class EbuildBuild(CompositeTask):
114 def _clean_exit(self, clean_phase):
115 if self._final_exit(clean_phase) != os.EX_OK or \
116 self.opts.buildpkgonly:
117 - self._unlock_builddir()
118 - self.wait()
119 + self._async_unlock_builddir(returncode=self.returncode)
120 + else:
121 + self.wait()
122
123 def create_install_task(self):
124 """
125 @@ -461,4 +473,4 @@ class EbuildBuild(CompositeTask):
126 return task
127
128 def _install_exit(self, task):
129 - self._unlock_builddir()
130 + self._async_unlock_builddir()
131 --
132 2.13.6