all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#58250: guix import json: GUIX_PACKAGE_PATH -- no code for module
@ 2022-10-02 14:26 itd
       [not found] ` <handler.58250.B.16647208196976.ack@debbugs.gnu.org>
  0 siblings, 1 reply; 5+ messages in thread
From: itd @ 2022-10-02 14:26 UTC (permalink / raw)
  To: 58250

Hi,

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

> $ 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`:

> name: hello
> ...
> location: gnu/packages/base.scm:86:2
> ...
> name: myotherhello
> ...
> location: /tmp/tmp.J3f9qsyDIL/non-gnu.scm:6:2

But importing `myhello` fails:

> /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.:

> /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




^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#58250: [PATCH 1/2] modules: Remove load path prefix from module name.
       [not found] ` <handler.58250.B.16647208196976.ack@debbugs.gnu.org>
@ 2022-10-02 14:35   ` itd
  2022-12-23 13:49     ` bug#58250: guix import json: GUIX_PACKAGE_PATH -- no code for module Ludovic Courtès
  2022-10-02 14:38   ` bug#58250: [PATCH 2/2] import: print: Use file-name->module-name itd
  1 sibling, 1 reply; 5+ messages in thread
From: itd @ 2022-10-02 14:35 UTC (permalink / raw)
  To: 58250


* 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(-)

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





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#58250: [PATCH 2/2] import: print: Use file-name->module-name.
       [not found] ` <handler.58250.B.16647208196976.ack@debbugs.gnu.org>
  2022-10-02 14:35   ` bug#58250: [PATCH 1/2] modules: Remove load path prefix from module name itd
@ 2022-10-02 14:38   ` itd
  2022-12-23 13:50     ` bug#58250: guix import json: GUIX_PACKAGE_PATH -- no code for module Ludovic Courtès
  1 sibling, 1 reply; 5+ messages in thread
From: itd @ 2022-10-02 14:38 UTC (permalink / raw)
  To: 58250


* 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))))
 
   ;; Return the first candidate variable name that is bound to VAL.
   (define (variable-name val mod)
-- 
2.37.3





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#58250: guix import json: GUIX_PACKAGE_PATH -- no code for module
  2022-10-02 14:35   ` bug#58250: [PATCH 1/2] modules: Remove load path prefix from module name itd
@ 2022-12-23 13:49     ` Ludovic Courtès
  0 siblings, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2022-12-23 13:49 UTC (permalink / raw)
  To: itd; +Cc: 58250

Hi,

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

> * 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’.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#58250: guix import json: GUIX_PACKAGE_PATH -- no code for module
  2022-10-02 14:38   ` bug#58250: [PATCH 2/2] import: print: Use file-name->module-name itd
@ 2022-12-23 13:50     ` Ludovic Courtès
  0 siblings, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2022-12-23 13:50 UTC (permalink / raw)
  To: itd; +Cc: 58250

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

> * 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'.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-23 13:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-02 14:26 bug#58250: guix import json: GUIX_PACKAGE_PATH -- no code for module itd
     [not found] ` <handler.58250.B.16647208196976.ack@debbugs.gnu.org>
2022-10-02 14:35   ` bug#58250: [PATCH 1/2] modules: Remove load path prefix from module name itd
2022-12-23 13:49     ` bug#58250: guix import json: GUIX_PACKAGE_PATH -- no code for module Ludovic Courtès
2022-10-02 14:38   ` bug#58250: [PATCH 2/2] import: print: Use file-name->module-name itd
2022-12-23 13:50     ` bug#58250: guix import json: GUIX_PACKAGE_PATH -- no code for module Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.