summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2018-07-19 20:32:44 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-07-24 11:52:27 +0100
commit3fa835d9bcc6802390cefda266b25856178c553f (patch)
tree42e4952c2b7bae4903255f4f0aff230a32b20d93 /meta/classes
parent2245a94bb87ec1e13c542f2074d4b9e531ffeaf1 (diff)
downloadpoky-3fa835d9bcc6802390cefda266b25856178c553f.tar.gz
package_ipk|deb: Use oe.utils.multiprocess_launch
The current code had broken exception handling due to the use of a "traceback" variable as well as an import. Use the new library code for this instead which reduces code duplication and has fixed/improved exception handling. The chdir code can be dropped since any directory changes are in other processes now so there is no need for it here and the code no longer changes directory. (From OE-Core rev: bcd47389f4b1fc69d2bb4da01933bfa1fdcae092) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/package_deb.bbclass51
-rw-r--r--meta/classes/package_ipk.bbclass51
2 files changed, 2 insertions, 100 deletions
diff --git a/meta/classes/package_deb.bbclass b/meta/classes/package_deb.bbclass
index 2e8d17d3c7..6f81591653 100644
--- a/meta/classes/package_deb.bbclass
+++ b/meta/classes/package_deb.bbclass
@@ -41,32 +41,6 @@ def debian_arch_map(arch, tune):
41 return arch 41 return arch
42 42
43python do_package_deb () { 43python do_package_deb () {
44
45 import multiprocessing
46 import traceback
47
48 class DebianWritePkgProcess(multiprocessing.Process):
49 def __init__(self, *args, **kwargs):
50 multiprocessing.Process.__init__(self, *args, **kwargs)
51 self._pconn, self._cconn = multiprocessing.Pipe()
52 self._exception = None
53
54 def run(self):
55 try:
56 multiprocessing.Process.run(self)
57 self._cconn.send(None)
58 except Exception as e:
59 tb = traceback.format_exc()
60 self._cconn.send((e, tb))
61
62 @property
63 def exception(self):
64 if self._pconn.poll():
65 self._exception = self._pconn.recv()
66 return self._exception
67
68 oldcwd = os.getcwd()
69
70 packages = d.getVar('PACKAGES') 44 packages = d.getVar('PACKAGES')
71 if not packages: 45 if not packages:
72 bb.debug(1, "PACKAGES not defined, nothing to package") 46 bb.debug(1, "PACKAGES not defined, nothing to package")
@@ -76,30 +50,7 @@ python do_package_deb () {
76 if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK): 50 if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK):
77 os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN")) 51 os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"))
78 52
79 max_process = int(d.getVar("BB_NUMBER_THREADS") or os.cpu_count() or 1) 53 oe.utils.multiprocess_launch(deb_write_pkg, packages.split(), d, extraargs=(d,))
80 launched = []
81 error = None
82 pkgs = packages.split()
83 while not error and pkgs:
84 if len(launched) < max_process:
85 p = DebianWritePkgProcess(target=deb_write_pkg, args=(pkgs.pop(), d))
86 p.start()
87 launched.append(p)
88 for q in launched:
89 # The finished processes are joined when calling is_alive()
90 if not q.is_alive():
91 launched.remove(q)
92 if q.exception:
93 error, traceback = q.exception
94 break
95
96 for p in launched:
97 p.join()
98
99 os.chdir(oldcwd)
100
101 if error:
102 raise error
103} 54}
104do_package_deb[vardeps] += "deb_write_pkg" 55do_package_deb[vardeps] += "deb_write_pkg"
105do_package_deb[vardepsexclude] = "BB_NUMBER_THREADS" 56do_package_deb[vardepsexclude] = "BB_NUMBER_THREADS"
diff --git a/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass
index a0b34fa7a5..5eb910ca31 100644
--- a/meta/classes/package_ipk.bbclass
+++ b/meta/classes/package_ipk.bbclass
@@ -17,32 +17,6 @@ OPKG_ARGS += "${@['', '--add-exclude ' + ' --add-exclude '.join((d.getVar('PACKA
17OPKGLIBDIR = "${localstatedir}/lib" 17OPKGLIBDIR = "${localstatedir}/lib"
18 18
19python do_package_ipk () { 19python do_package_ipk () {
20 import multiprocessing
21 import traceback
22
23 class IPKWritePkgProcess(multiprocessing.Process):
24 def __init__(self, *args, **kwargs):
25 multiprocessing.Process.__init__(self, *args, **kwargs)
26 self._pconn, self._cconn = multiprocessing.Pipe()
27 self._exception = None
28
29 def run(self):
30 try:
31 multiprocessing.Process.run(self)
32 self._cconn.send(None)
33 except Exception as e:
34 tb = traceback.format_exc()
35 self._cconn.send((e, tb))
36
37 @property
38 def exception(self):
39 if self._pconn.poll():
40 self._exception = self._pconn.recv()
41 return self._exception
42
43
44 oldcwd = os.getcwd()
45
46 workdir = d.getVar('WORKDIR') 20 workdir = d.getVar('WORKDIR')
47 outdir = d.getVar('PKGWRITEDIRIPK') 21 outdir = d.getVar('PKGWRITEDIRIPK')
48 tmpdir = d.getVar('TMPDIR') 22 tmpdir = d.getVar('TMPDIR')
@@ -61,30 +35,7 @@ python do_package_ipk () {
61 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK): 35 if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
62 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN")) 36 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
63 37
64 max_process = int(d.getVar("BB_NUMBER_THREADS") or os.cpu_count() or 1) 38 oe.utils.multiprocess_launch(ipk_write_pkg, packages.split(), d, extraargs=(d,))
65 launched = []
66 error = None
67 pkgs = packages.split()
68 while not error and pkgs:
69 if len(launched) < max_process:
70 p = IPKWritePkgProcess(target=ipk_write_pkg, args=(pkgs.pop(), d))
71 p.start()
72 launched.append(p)
73 for q in launched:
74 # The finished processes are joined when calling is_alive()
75 if not q.is_alive():
76 launched.remove(q)
77 if q.exception:
78 error, traceback = q.exception
79 break
80
81 for p in launched:
82 p.join()
83
84 os.chdir(oldcwd)
85
86 if error:
87 raise error
88} 39}
89do_package_ipk[vardeps] += "ipk_write_pkg" 40do_package_ipk[vardeps] += "ipk_write_pkg"
90do_package_ipk[vardepsexclude] = "BB_NUMBER_THREADS" 41do_package_ipk[vardepsexclude] = "BB_NUMBER_THREADS"