Subject: [bug#34195] [PATCH] linux-modules: module-soft-dependencies: Partition the result and return it as two lists.

From: Danny Milosavljevic <[email-masked]>
Date: Sat, 26 Jan 2019 17:19:19 +0100

* gnu/build/linux-modules.scm (module-soft-dependencies): Partition the
result and return it as two lists.
---
 gnu/build/linux-modules.scm | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm
index d69bcbf5a..16c8fad28 100644
--- a/gnu/build/linux-modules.scm
+++ b/gnu/build/linux-modules.scm
@@ -25,6 +25,7 @@
   #:use-module (rnrs io ports)
   #:use-module (rnrs bytevectors)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-11)
   #:use-module (srfi srfi-26)
   #:use-module (ice-9 vlist)
   #:use-module (ice-9 match)
@@ -105,7 +106,8 @@ contains module names, not actual file names."
   (char-set-complement (char-set #\space #\tab)))
 
 (define (module-soft-dependencies file)
-  "Return a list of (cons section soft-dependency) of module FILE."
+  "Return the list of modules that can be preloaded, and then the list of
+modules that can be postloaded, of the soft dependencies of module FILE."
   ;; TEXT: "pre: baz blubb foo post: bax bar"
   (define (parse-softdep text)
     (let loop ((value '())
@@ -120,13 +122,19 @@ contains module names, not actual file names."
         value))))
 
   ;; Note: Multiple 'softdep sections are allowed.
-  (let ((info (modinfo-section-contents file)))
-    (concatenate
-     (filter-map (match-lambda
-                  (('softdep . value)
-                   (parse-softdep value))
-                  (_ #f))
-                 (modinfo-section-contents file)))))
+  (let* ((info (modinfo-section-contents file))
+         (entries (concatenate
+                   (filter-map (match-lambda
+                                (('softdep . value)
+                                 (parse-softdep value))
+                                (_ #f))
+                               (modinfo-section-contents file)))))
+    (let-values (((pres posts)
+                  (partition (match-lambda
+                              (("pre" . _) #t)
+                              (("post" . _) #f))
+                             entries)))
+      (values (map cdr pres) (map cdr posts)))))
 
 (define (module-aliases file)
   "Return the list of aliases of module FILE."