guix import json: GUIX_PACKAGE_PATH -- no code for module

  • Open
  • quality assurance status badge
Details
2 participants
  • itd
  • Ludovic Courtès
Owner
unassigned
Submitted by
itd
Severity
normal
I
(address . bug-guix@gnu.org)
871qrqfgiq.fsf@localhost
Hi,

I'm having an issue with the JSON importer. The following example
attempts to illustrate the problem:

Toggle quote (18 lines)
> $ cd $(mktemp -d) # -> /tmp/tmp.J3f9qsyDIL
> /tmp/tmp.J3f9qsyDIL$ cat myhello.json
> {
> "name": "myhello",
> "version": "2.10",
> "source": "mirror://gnu/hello/hello-2.10.tar.gz",
> "build-system": "gnu",
> "license": "GPL-3.0+",
> "native-inputs": ["gettext", "myotherhello"]
> }
> /tmp/tmp.J3f9qsyDIL$ cat non-gnu.scm
> (define-module (non-gnu)
> #:use-module (gnu packages base)
> #:use-module (guix packages))
>
> (define-public myotherhello
> (package (inherit hello) (name "myotherhello")))

As expected, both `hello` and `myotherhello` are found by `guix search
-L /tmp/tmp.J3f9qsyDIL hello`:

Toggle quote (8 lines)
> name: hello
> ...
> location: gnu/packages/base.scm:86:2
> ...
> name: myotherhello
> ...
> location: /tmp/tmp.J3f9qsyDIL/non-gnu.scm:6:2

But importing `myhello` fails:

Toggle quote (37 lines)
> /tmp/tmp.J3f9qsyDIL$ export GUIX_PACKAGE_PATH=/tmp/tmp.J3f9qsyDIL/
> /tmp/tmp.J3f9qsyDIL$ guix import json myhello.json
>
> Starting download of /tmp/guix-file.bQ5VSS
> From https://ftpmirror.gnu.org/gnu/hello/hello-2.10.tar.gz...
> following redirection to `https://gnu.askapache.com/hello/hello-2.10.tar.gz'...
> …10.tar.gz 709KiB 671KiB/s 00:01 [##################] 100.0%
> Backtrace:
> 14 (primitive-load "/home/itd/.config/guix/current/bin/…")
> In guix/ui.scm:
> 2263:7 13 (run-guix . _)
> 2226:10 12 (run-guix-command _ . _)
> In guix/scripts/import.scm:
> 92:11 11 (guix-import . _)
> In ice-9/boot-9.scm:
> 1747:15 10 (with-exception-handler #<procedure 7efce407acf0 at ic…> …)
> In guix/scripts/import/json.scm:
> 91:16 9 (_)
> In ice-9/boot-9.scm:
> 1747:15 8 (with-exception-handler #<procedure 7efce407acc0 at ic…> …)
> In guix/import/json.scm:
> 86:18 7 (_)
> In guix/import/print.scm:
> 220:37 6 (package->code _)
> 161:17 5 (inputs->code (("gettext" #<package gettext@0.21 g…>) #))
> In srfi/srfi-1.scm:
> 586:29 4 (map1 (("gettext" #<package gettext@0.21 gnu/packa…>) #))
> 586:17 3 (map1 (("myotherhello" #<package myotherhello@2.12.1…>)))
> In guix/import/print.scm:
> 164:40 2 (_ _)
> 60:31 1 (variable-name _ (#{}# tmp tmp.J3f9qsyDIL non-gnu))
> In ice-9/boot-9.scm:
> 3330:6 0 (resolve-interface (#{}# tmp tmp.J3f9qsyDIL non-gnu) # _ …)
>
> ice-9/boot-9.scm:3330:6: In procedure resolve-interface:
> no code for module (#{}# tmp tmp.J3f9qsyDIL non-gnu)

One can influence the name of the mentioned module via
GUIX_PACKAGE_PATH, e.g.:

Toggle quote (6 lines)
> /tmp/tmp.J3f9qsyDIL$ export GUIX_PACKAGE_PATH=.
> /tmp/tmp.J3f9qsyDIL$ guix import json myhello.json
> ...
> ice-9/boot-9.scm:3330:6: In procedure resolve-interface:
> no code for module (#{.}# non-gnu)

But the issue remains.

Suspected cause: the value of GUIX_PACKAGE_PATH is considered part of
the module name but shouldn't. This results in an unexpected module
name / missing module. Idea: when constructing the module name from the
file name, this prefix should be removed.

Regards
itd
I
[PATCH 1/2] modules: Remove load path prefix from module name.
(address . 58250@debbugs.gnu.org)
87y1tye1je.fsf@localhost
* guix/modules.scm (file-name->module-name): Ignore load path prefix
when building module name.
---
It was mentioned on IRC, that (guix modules)'s file-name->module-name
might be function to be used by the JSON importer (and fixed if needed).
This patch attempts to implement the idea from the bug report.

guix/modules.scm | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

Toggle diff (34 lines)
diff --git a/guix/modules.scm b/guix/modules.scm
index 61bc8e1978..269d52ae1e 100644
--- a/guix/modules.scm
+++ b/guix/modules.scm
@@ -100,11 +100,23 @@ (define module-file-dependencies
'()))))))
(define file-name->module-name
- (let ((not-slash (char-set-complement (char-set #\/))))
+ (let ((not-slash (char-set-complement (char-set #\/)))
+ (load-path-prefix-length
+ (lambda (file)
+ ;; Length of the longest prefix among all given load paths.
+ (apply max (map
+ (lambda (path) (if (string-prefix? path file)
+ (string-length path)
+ 0))
+ %load-path)))))
(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)))))
+ (string-tokenize
+ (string-drop
+ (string-drop-right file 4)
+ (load-path-prefix-length file))
+ not-slash)))))
(define (module-name->file-name module)
"Return the file name for MODULE."

base-commit: ae221813745783ef1b7eee47561a2208cd5ad512
--
2.37.3
I
[PATCH 2/2] import: print: Use file-name->module-name.
(address . 58250@debbugs.gnu.org)
87v8p2e1f2.fsf@localhost
* guix/import/print.scm (package->code)[package-module-name]: Use
file-name->module-name to build the package module name.
---
This patch updates the JSON importer to use (guix modules)'s
file-name->module-name to determine the module name.

guix/import/print.scm | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

Toggle diff (26 lines)
diff --git a/guix/import/print.scm b/guix/import/print.scm
index 2f54adbd8c..04e6b0a7b1 100644
--- a/guix/import/print.scm
+++ b/guix/import/print.scm
@@ -21,6 +21,7 @@ (define-module (guix import print)
#:use-module (guix base32)
#:use-module (guix utils)
#:use-module (guix licenses)
+ #:use-module (guix modules)
#:use-module (guix packages)
#:use-module (guix search-paths)
#:use-module (guix build-system)
@@ -45,10 +46,7 @@ (define (package->code package)
when evaluated."
;; The module in which the package PKG is defined
(define (package-module-name pkg)
- (map string->symbol
- (string-split (string-drop-right
- (location-file (package-location pkg)) 4)
- #\/)))
+ (file-name->module-name (location-file (package-location pkg))))
;; Return the first candidate variable name that is bound to VAL.
(define (variable-name val mod)
--
2.37.3
L
L
Ludovic Courtès wrote on 23 Dec 2022 14:49
Re: bug#58250: guix import json: GUIX_PACKAGE_PATH -- no code for module
(name . itd)(address . itd@net.in.tum.de)(address . 58250@debbugs.gnu.org)
87r0wqz0uj.fsf_-_@gnu.org
Hi,

itd <itd@net.in.tum.de> skribis:

Toggle quote (7 lines)
> * guix/modules.scm (file-name->module-name): Ignore load path prefix
> when building module name.
> ---
> It was mentioned on IRC, that (guix modules)'s file-name->module-name
> might be function to be used by the JSON importer (and fixed if needed).
> This patch attempts to implement the idea from the bug report.

At first sight I believe the fix should be in ‘package->code’, not in
(guix modules).

(guix modules) is quite sensitive so in general we should refrain from
changing the semantics of its procedures. In this case,
‘file-name->module-name’ expects a file name relative to a search path
entry.

HTH,
Ludo’.
L
L
Ludovic Courtès wrote on 23 Dec 2022 14:50
(name . itd)(address . itd@net.in.tum.de)(address . 58250@debbugs.gnu.org)
87mt7ez0sp.fsf_-_@gnu.org
itd <itd@net.in.tum.de> skribis:

Toggle quote (31 lines)
> * guix/import/print.scm (package->code)[package-module-name]: Use
> file-name->module-name to build the package module name.
> ---
> This patch updates the JSON importer to use (guix modules)'s
> file-name->module-name to determine the module name.
>
> guix/import/print.scm | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/guix/import/print.scm b/guix/import/print.scm
> index 2f54adbd8c..04e6b0a7b1 100644
> --- a/guix/import/print.scm
> +++ b/guix/import/print.scm
> @@ -21,6 +21,7 @@ (define-module (guix import print)
> #:use-module (guix base32)
> #:use-module (guix utils)
> #:use-module (guix licenses)
> + #:use-module (guix modules)
> #:use-module (guix packages)
> #:use-module (guix search-paths)
> #:use-module (guix build-system)
> @@ -45,10 +46,7 @@ (define (package->code package)
> when evaluated."
> ;; The module in which the package PKG is defined
> (define (package-module-name pkg)
> - (map string->symbol
> - (string-split (string-drop-right
> - (location-file (package-location pkg)) 4)
> - #\/)))
> + (file-name->module-name (location-file (package-location pkg))))

LGTM!

Ludo'.
?