From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esIAB-0005yc-WE for guix-patches@gnu.org; Sat, 03 Mar 2018 20:10:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esIA8-0003rQ-5k for guix-patches@gnu.org; Sat, 03 Mar 2018 20:10:07 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:35470) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1esIA8-0003rM-1y for guix-patches@gnu.org; Sat, 03 Mar 2018 20:10:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1esIA7-0002d0-QP for guix-patches@gnu.org; Sat, 03 Mar 2018 20:10:03 -0500 Subject: [bug#30604] [PATCH v9 2/7] linux-modules: Add module-aliases->module-file-names. Resent-Message-ID: From: Danny Milosavljevic Date: Sun, 4 Mar 2018 02:09:09 +0100 Message-Id: <20180304010914.1322-3-dannym@scratchpost.org> In-Reply-To: <20180304010914.1322-1-dannym@scratchpost.org> References: <20180303135533.6112-1-dannym@scratchpost.org> <20180304010914.1322-1-dannym@scratchpost.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 30604@debbugs.gnu.org * gnu/build/linux-modules.scm (module-aliases->module-file-names): New procedure. --- gnu/build/linux-modules.scm | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm index 0aaf2ff6f..f6bb0512b 100644 --- a/gnu/build/linux-modules.scm +++ b/gnu/build/linux-modules.scm @@ -21,6 +21,7 @@ #:use-module (guix elf) #:use-module (guix glob) #:use-module (guix build syscalls) + #:use-module (guix build utils) ; find-files #:use-module (rnrs io ports) #:use-module (rnrs bytevectors) #:use-module (srfi srfi-1) @@ -28,9 +29,12 @@ #:use-module (ice-9 vlist) #:use-module (ice-9 match) #:use-module (ice-9 rdelim) + #:use-module (ice-9 regex) + #:use-module (ice-9 ftw) #:export (dot-ko ensure-dot-ko module-aliases + module-aliases->module-file-names module-dependencies recursive-module-dependencies modules-loaded @@ -438,4 +442,55 @@ ALIAS is a string like \"scsi:t-0x00\" as returned by (format port "~a ~a ~a~a:~a\n" module devname "b" major minor)))))))) aliases)))) +(define (module-aliases->module-file-names linux aliases) + "Resolve ALIASES to module file names, including their dependencies (which will appear +first). Each alias will map to a list of module file names. +LINUX is the directory containing \"lib\"." + (define (string->regexp str) + ;; Return a regexp that matches STR exactly. + (string-append "^" (regexp-quote str) "$")) + + (define module-dir + (string-append linux "/lib/modules")) + + (define (find-only-entry directory) + (match (scandir directory) + (("." ".." basename) + (string-append directory "/" basename)))) + + (define linux-release-module-directory + (find-only-entry module-dir)) + + (define known-module-aliases* + (known-module-aliases + (string-append linux-release-module-directory + "/modules.alias"))) + (define (resolve-alias alias) + "If possible, resolve ALIAS to a list of module names. +Otherwise return just ALIAS as possible module names." + (match (delete-duplicates (matching-modules alias + known-module-aliases*)) + (() + (list alias)) + (items + items))) + + (define (lookup module) + (let ((name (ensure-dot-ko module))) + (match (find-files module-dir (string->regexp name)) + ((file) + file) + (() + (error "module not found" name module-dir)) + ((_ ...) + (error "several modules by that name" + name module-dir))))) + (append-map (lambda (alias) + (let ((modules (map lookup (resolve-alias alias)))) + (append (recursive-module-dependencies modules + #:lookup-module + lookup) + modules))) + aliases)) + ;;; linux-modules.scm ends here