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 <~@wolfsden.cz>
Change-Id: I3d1b9f3f21448050cac4f3b1aed5f8f03758d4c9
This commit is contained in:
Ludovic Courtès 2024-07-18 17:30:01 +02:00
parent 589c5e2546
commit e3dfed59d3
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 13 additions and 3 deletions

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016-2019, 2021-2022 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2016-2019, 2021-2022, 2024 Ludovic Courtès <ludo@gnu.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -104,7 +104,9 @@ (define file-name->module-name
(lambda (file) (lambda (file)
"Return the module name (a list of symbols) corresponding to FILE." "Return the module name (a list of symbols) corresponding to FILE."
(map string->symbol (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) (define (module-name->file-name module)
"Return the file name for MODULE." "Return the file name for MODULE."

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2016-2017, 2024 Ludovic Courtès <ludo@gnu.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -65,4 +65,12 @@ (define-module (test-modules)
(source-module-closure '((baz)) (list directory) (source-module-closure '((baz)) (list directory)
#:select? (const #t)))))) #: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) (test-end)