civodul pushed a commit to branch master
in repository guix.

commit e3dfed59d39ac60dd2e2b9ef9f4ef63a2a081f41
Author: Ludovic Courtès <[email protected]>
AuthorDate: Thu Jul 18 17:30:01 2024 +0200

    modules: ‘file-name->module-name’ strips leading “./”.
    
    Fixes <https://issues.guix.gnu.org/71979>.
    
    * guix/modules.scm (file-name->module-name): Strip leading “.” component
    from FILE.
    * tests/modules.scm ("file-name->module-name")
    ("file-name->module-name, leading dot"): New tests.
    
    Reported-by: Tomas Volf <[email protected]>
    Change-Id: I3d1b9f3f21448050cac4f3b1aed5f8f03758d4c9
---
 guix/modules.scm  |  6 ++++--
 tests/modules.scm | 10 +++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/guix/modules.scm b/guix/modules.scm
index 77e1c2b6f4..74400ffacc 100644
--- a/guix/modules.scm
+++ b/guix/modules.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2016-2019, 2021-2022 Ludovic Courtès <[email protected]>
+;;; Copyright © 2016-2019, 2021-2022, 2024 Ludovic Courtès <[email protected]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -104,7 +104,9 @@ depends on."
     (lambda (file)
       "Return the module name (a list of symbols) corresponding to FILE."
       (map string->symbol
-           (string-tokenize (string-drop-right file 4) not-slash)))))
+           (match (string-tokenize (string-drop-right file 4) not-slash)
+             (("." . rest) rest)                  ;strip the leading "."
+             (lst lst))))))
 
 (define (module-name->file-name module)
   "Return the file name for MODULE."
diff --git a/tests/modules.scm b/tests/modules.scm
index e70d2d9e08..bb2c70e287 100644
--- a/tests/modules.scm
+++ b/tests/modules.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2016, 2017 Ludovic Courtès <[email protected]>
+;;; Copyright © 2016-2017, 2024 Ludovic Courtès <[email protected]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -65,4 +65,12 @@
        (source-module-closure '((baz)) (list directory)
                               #:select? (const #t))))))
 
+(test-equal "file-name->module-name"
+  '(guix foo)
+  (file-name->module-name "guix/foo.scm"))
+
+(test-equal "file-name->module-name, leading dot"
+  '(guix foo)
+  (file-name->module-name "./guix/foo.scm"))
+
 (test-end)

Reply via email to