bug-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#27284: [PATCH 2/8] build: Honor make's '-j' flag.


From: Ludovic Courtès
Subject: bug#27284: [PATCH 2/8] build: Honor make's '-j' flag.
Date: Fri, 20 Oct 2017 18:05:51 +0200

* build-aux/compile-all.scm (parallel-job-count): New procedure.
<top level>: Pass it to 'compile-files' as #:workers.
---
 build-aux/compile-all.scm | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/build-aux/compile-all.scm b/build-aux/compile-all.scm
index 2fc3102da..4aa4ac9b9 100644
--- a/build-aux/compile-all.scm
+++ b/build-aux/compile-all.scm
@@ -44,6 +44,31 @@
     (or (not (file-exists? go))
         (file-mtime<? go file))))
 
+(define* (parallel-job-count #:optional (flags (getenv "MAKEFLAGS")))
+  "Return the number of parallel jobs as determined by FLAGS, the flags passed
+to 'make'."
+  (match flags
+    (#f (current-processor-count))
+    (flags
+     (let loop ((flags (string-tokenize flags)))
+       (match flags
+         (()
+          1)
+         (("-j" (= string->number count) _ ...)
+          (if (integer? count)
+              count
+              (current-processor-count)))
+         ((head tail ...)
+          (if (string-prefix? "-j" head)
+              (match (string-drop head 2)
+                (""
+                 (current-processor-count))
+                ((= string->number count)
+                 (if (integer? count)
+                     count
+                     (current-processor-count))))
+              (loop tail))))))))
+
 ;; Install a SIGINT handler to give unwind handlers in 'compile-file' an
 ;; opportunity to run upon SIGINT and to remove temporary output files.
 (sigaction SIGINT
@@ -54,6 +79,7 @@
   ((_ . files)
    (compile-files srcdir (getcwd)
                   (filter file-needs-compilation? files)
+                  #:workers (parallel-job-count)
                   #:host host
                   #:report-load (lambda (file total completed)
                                   (when file
-- 
2.14.2






reply via email to

[Prev in Thread] Current Thread [Next in Thread]