Subject: [PATCH v2] linux-modules: Add modules-soft-dependencies.

From: Danny Milosavljevic <[email-masked]>
Date: Fri, 25 Jan 2019 12:48:38 +0100

* gnu/build/linux-modules.scm (not-softdep-whitespace): New variable.
(module-soft-dependencies): New procedure.
---
 gnu/build/linux-modules.scm | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm
index 2d8117504..1632f20d5 100644
--- a/gnu/build/linux-modules.scm
+++ b/gnu/build/linux-modules.scm
@@ -33,6 +33,7 @@
             ensure-dot-ko
             module-aliases
             module-dependencies
+            module-soft-dependencies
             normalize-module-name
             file-name->module-name
             find-module-file
@@ -100,6 +101,37 @@ contains module names, not actual file names."
       (('depends . what)
        (string-tokenize what %not-comma)))))
 
+(define not-softdep-whitespace
+  (char-set-complement (char-set #\space #\tab)))
+
+(define (module-soft-dependencies file)
+  "Return a list of (cons mode soft-dependency) of module FILE."
+  ;; TEXT: "pre: baz blubb foo post: bax bar"
+  (define (parse-softdep text)
+    (let loop ((value '())
+               (tokens (string-tokenize text not-softdep-whitespace))
+               (section #f))
+      (match tokens
+       ((token _ ...)
+        (if (string=? (string-take-right token 1) ":") ; section
+            (loop value
+                  (cdr tokens)
+                  (string-trim-both token))
+            (loop (cons (cons section token) value)
+                  (cdr tokens)
+                  section)))
+       (()
+        value))))
+
+  ;; Note: Multiple 'softdep sections are allowed.
+  (let ((info (modinfo-section-contents file)))
+    (apply append
+     (filter-map (match-lambda
+                  (('softdep . value)
+                   (parse-softdep value))
+                  (_ #f))
+                 (modinfo-section-contents file)))))
+
 (define (module-aliases file)
   "Return the list of aliases of module FILE."
   (let ((info (modinfo-section-contents file)))