]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
package_deb: Enable multithreaded package creation
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 31 Mar 2017 14:06:39 +0000 (15:06 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 16 Jun 2017 09:58:25 +0000 (10:58 +0100)
Allow the creation of debs to happen in parallel, making best use of resources
on multiprocessor systems.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/package_deb.bbclass

index 04b91970c7b768a9ce3a90408313e927e16a45ad..23b449cbe053a05f64d9c8d0b59ce3354e035742 100644 (file)
@@ -51,6 +51,8 @@ def debian_arch_map(arch, tune):
 # INSTALL_TASK_DEB - task name
 
 python do_package_deb () {
+    from multiprocessing import Process
+
     oldcwd = os.getcwd()
 
     packages = d.getVar('PACKAGES')
@@ -62,11 +64,25 @@ python do_package_deb () {
     if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK):
         os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"))
 
-    for pkg in packages.split():
-        deb_write_pkg(pkg, d)
+    max_process = int(d.getVar("BB_NUMBER_THREADS") or os.cpu_count() or 1)
+    launched = []
+    pkgs = packages.split()
+    while pkgs:
+        if len(launched) < max_process:
+            p = Process(target=deb_write_pkg, args=(pkgs.pop(), d))
+            p.start()
+            launched.append(p)
+        for q in launched:
+            # The finished processes are joined when calling is_alive()
+            if not q.is_alive():
+                launched.remove(q)
+    for p in launched:
+        p.join()
 
     os.chdir(oldcwd)
 }
+do_package_deb[vardeps] += "deb_write_pkg"
+do_package_deb[vardepsexclude] = "BB_NUMBER_THREADS"
 
 def deb_write_pkg(pkg, d):
     import re, copy