unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55464: (current-filename) is #f when guix pull'ing
@ 2022-05-16 21:04 Attila Lendvai
  2022-05-17  0:09 ` bug#55464: alternative way Attila Lendvai
  2022-05-18  9:14 ` bug#55464: (current-filename) is #f when guix pull'ing Ludovic Courtès
  0 siblings, 2 replies; 5+ messages in thread
From: Attila Lendvai @ 2022-05-16 21:04 UTC (permalink / raw)
  To: 55464

the actual context where i'm encountering this is a package definition where i want to load some hashes from a file relative the to the .scm file:

(define-public foo
  (let ((hashes
    (with-input-from-file
        (string-append (dirname (current-filename))
                       "/foo.hashes")
      read)))
    (package ...)))

this works fine in a `./pre-inst-env build foo`, but i think there's something special in how `guix pull` compiles the scm files, and (c-f) expands to #f. guix pull works, but afterwards:

$ guix system --on-error=backtrace reconfigure --allow-downgrades /etc/guix/config.scm
guix system: error: failed to load '/etc/guix/config.scm':
guix-crypto/packages/ethereum.scm:47:36: In procedure scm_to_utf8_stringn: Wrong type argument in position 1 (expecting string): #f

In ice-9/boot-9.scm:
   222:29 19 (map1 (((gnu)) ((gnu system)) ((gnu system #)) ((# …)) …))
   222:29 18 (map1 (((gnu system)) ((gnu system file-systems)) (#) …))
   222:29 17 (map1 (((gnu system file-systems)) ((oop goops)) ((…)) …))
   222:29 16 (map1 (((oop goops)) ((shepherd service)) ((nongnu …)) …))
   222:29 15 (map1 (((shepherd service)) ((nongnu packages linux)) …))
   222:29 14 (map1 (((nongnu packages linux)) ((guix-crypto # #)) # …))
   222:17 13 (map1 (((guix-crypto packages ethereum)) ((# # #)) (#) …))
  3936:31 12 (_ ((guix-crypto packages ethereum)))
  3327:17 11 (resolve-interface (guix-crypto packages ethereum) # _ # …)
In ice-9/threads.scm:
    390:8 10 (_ _)
In ice-9/boot-9.scm:
  3253:13  9 (_)
In ice-9/threads.scm:
    390:8  8 (_ _)
In ice-9/boot-9.scm:
  3544:20  7 (_)
   2836:4  6 (save-module-excursion #<procedure 7f056144d810 at ice-…>)
  3564:26  5 (_)
In unknown file:
           4 (primitive-load-path "guix-crypto/packages/ethereum" #<…>)
In guix-crypto/packages/ethereum.scm:
    47:36  3 (_)
In unknown file:
           2 (dirname #f)
In ice-9/boot-9.scm:
  1685:16  1 (raise-exception _ #:continuable? _)
  1780:13  0 (_ #<&compound-exception components: (#<&assertion-fail…>)

i would be happy to avoid using (c-f), but i failed to find a way in Guile's module reflection API.

--
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“People who have never gone to school have never developed negative attitudes toward exploring their world.”
	— Grace Llewellyn





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

* bug#55464: alternative way
  2022-05-16 21:04 bug#55464: (current-filename) is #f when guix pull'ing Attila Lendvai
@ 2022-05-17  0:09 ` Attila Lendvai
  2022-05-18  9:14 ` bug#55464: (current-filename) is #f when guix pull'ing Ludovic Courtès
  1 sibling, 0 replies; 5+ messages in thread
From: Attila Lendvai @ 2022-05-17  0:09 UTC (permalink / raw)
  To: 55464@debbugs.gnu.org

as Ludovic kindly pointed out on IRC, i can use this instead:

(module-filename (current-module))

unfortunately, this returns a relative path, which is only useful using (search-path %load-path ...), which introduces some uncertainty about what actually gets loaded depending on the runtime value of %load-path... :|

therefore, i decided to read the file at macroexpand-time. after some struggle with hygienic macros:

(define-syntax read-module-relative-file
  (lambda (syn)
    (syntax-case syn ()
      ((_ filename)
       (with-syntax
           ;; Read the file at compile time and macroexpand to the first form.
           ((form (%read-module-relative-file (current-module)
                                              (syntax->datum #'filename))))
         #''form)))))

(define (%read-module-relative-file module filename)
  (with-input-from-file
      (or (search-path %load-path
                       (string-append (dirname (module-filename module))
                                      "/" filename))
          (error "%read-module-relative-file failed for" filename))
    read))

not beautiful, but works.

--
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“It is just as difficult and dangerous to try to free a people that wants to remain servile as it is to enslave a people that wants to remain free.”
	— Niccolò Machiavelli (1469–1527)





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

* bug#55464: (current-filename) is #f when guix pull'ing
  2022-05-16 21:04 bug#55464: (current-filename) is #f when guix pull'ing Attila Lendvai
  2022-05-17  0:09 ` bug#55464: alternative way Attila Lendvai
@ 2022-05-18  9:14 ` Ludovic Courtès
  2022-05-19 13:32   ` Attila Lendvai
  1 sibling, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2022-05-18  9:14 UTC (permalink / raw)
  To: Attila Lendvai; +Cc: 55464

Hi,

Attila Lendvai <attila@lendvai.name> skribis:

> the actual context where i'm encountering this is a package definition where i want to load some hashes from a file relative the to the .scm file:
>
> (define-public foo
>   (let ((hashes
>     (with-input-from-file
>         (string-append (dirname (current-filename))
>                        "/foo.hashes")
>       read)))
>     (package ...)))

Not fully answering your question, but if “foo.hashes” contains hashes
for origins and similar, you could make “foo.hashes” contain something
like:

  (list (base32 …) …)

and, in the .scm, write:

  (include "foo.hashes")

The ‘include’ directive includes the file at macro-expansion time,
similar to #include in C.

Back to the original issue, I suppose ‘current-filename’ return #f when
this .scm is first loaded, before it’s compiled.  Anyway, it’s probably
best to load it at macro-expansion time as you suggested.

HTH,
Ludo’.




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

* bug#55464: (current-filename) is #f when guix pull'ing
  2022-05-18  9:14 ` bug#55464: (current-filename) is #f when guix pull'ing Ludovic Courtès
@ 2022-05-19 13:32   ` Attila Lendvai
  2022-05-21 16:39     ` Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Attila Lendvai @ 2022-05-19 13:32 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 55464

[-- Attachment #1: Type: text/plain, Size: 2212 bytes --]

> > (define-public foo
> > (let ((hashes
> > (with-input-from-file
> > (string-append (dirname (current-filename))
> > "/foo.hashes")
> > read)))
> > (package ...)))
>
>
> Not fully answering your question, but if “foo.hashes” contains hashes
> for origins and similar, you could make “foo.hashes” contain something
> like:
>
> (list (base32 …) …)
>
> and, in the .scm, write:
>
> (include "foo.hashes")
>
> The ‘include’ directive includes the file at macro-expansion time,
> similar to #include in C.


i did find guile's INCLUDE and tried to use it, but it also didn't work when guix pull'ing it. see the attached, now abandoned commit.

IIRC the issue is that the implementation of INCLUDE tries to load the file relative to the cwd, but cwd is not changed by the code that is driving the compilation when guix pull'ing the code. (does each thread has its own cwd at all...?)

it works when i build it using `./pre-inst-env guix build foo`. i briefly tried to analyse what's the difference between the two situations, but i ran out of steam.

it is the same reason i need to call READ like below in my current implementation:

(define (%read-module-relative-file module filename)
  (with-input-from-file
      (or (search-path
           %load-path
           (string-append (dirname (module-filename module))
                          "/" filename))
          (error "%read-module-relative-file failed for" filename))
    read))


...which is not beautiful.


> Back to the original issue, I suppose ‘current-filename’ return #f when
> this .scm is first loaded, before it’s compiled. Anyway, it’s probably
> best to load it at macro-expansion time as you suggested.


is my analysis is correct, namely that cwd is not (always?) changed at macroexpand time, and thus the implementation of INCLUDE is broken for relative paths? is this a bug to be fixed in guile? if so, shall i try to add a test case for this somewhere?

--
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom.”
	— Isaac Asimov (1920–1992)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: use-guile-include.patch --]
[-- Type: text/x-patch; name=use-guile-include.patch, Size: 6936 bytes --]

From 20f815592708862a336f1937aa792e5dc356b1b4 Mon Sep 17 00:00:00 2001
From: Attila Lendvai <attila@lendvai.name>
Date: Tue, 17 May 2022 14:35:01 +0200
Subject: use guile's INCLUDE instead of our own way to read a file


diff --git a/bin/release-update-helper.scm b/bin/release-update-helper.scm
index 6545630..3c8eddb 100755
--- a/bin/release-update-helper.scm
+++ b/bin/release-update-helper.scm
@@ -129,7 +129,7 @@
                   (false-if-exception (delete-file db-file))
                   (with-output-to-file db-file
                     (lambda ()
-                      (format #t ";; This file was generated by the ~A script~%"
+                      (format #t ";; This file was generated by the ~A script~%'"
                               (basename (current-filename)))
                       (write db)))))
               (format #t "Finished successfully~%")))
diff --git a/src/guix-crypto/package-utils.scm b/src/guix-crypto/package-utils.scm
index 1877890..680d591 100644
--- a/src/guix-crypto/package-utils.scm
+++ b/src/guix-crypto/package-utils.scm
@@ -21,26 +21,7 @@
   #:use-module (guix diagnostics)
   #:use-module (guix packages)
   #:use-module (guix ui)
-  #:use-module (ice-9 match)
-  #:export (read-module-relative-file))
-
-(define (%read-module-relative-file module filename)
-  (with-input-from-file
-      (or (search-path %load-path
-                       (string-append (dirname (module-filename module))
-                                      "/" filename))
-          (error "%read-module-relative-file failed for" filename))
-    read))
-
-(define-syntax read-module-relative-file
-  (lambda (syn)
-    (syntax-case syn ()
-      ((_ filename)
-       (with-syntax
-           ;; Read the file at compile time and macroexpand to the first form.
-           ((form (%read-module-relative-file (current-module)
-                                              (syntax->datum #'filename))))
-         #''form)))))
+  #:use-module (ice-9 match))
 
 (define-public (unsupported-arch package-name system)
   (raise (formatted-message
diff --git a/src/guix-crypto/packages/bee-binary.hashes b/src/guix-crypto/packages/bee-binary.hashes
index 6ddc1c0..382d2c9 100644
--- a/src/guix-crypto/packages/bee-binary.hashes
+++ b/src/guix-crypto/packages/bee-binary.hashes
@@ -1,2 +1,2 @@
 ;; This file was generated by the release-update-helper.scm script
-(("aarch64-linux" . "1fjx9hw23dg20k4iz0imd33wsnlwxkjs9z39b4kakzpf4h89wrnl") ("x86_64-linux" . "18hs1mx50hdgqy1xzppfl0mcf7y2h23qs8qr74jzk5f34ixqhg4d") ("i686-linux" . "0fs5wqjh7qvdcmbbnl34m1j4ja7rl831dixaz3bznb4ys7lmlsjr"))
\ No newline at end of file
+'(("aarch64-linux" . "1fjx9hw23dg20k4iz0imd33wsnlwxkjs9z39b4kakzpf4h89wrnl") ("x86_64-linux" . "18hs1mx50hdgqy1xzppfl0mcf7y2h23qs8qr74jzk5f34ixqhg4d") ("i686-linux" . "0fs5wqjh7qvdcmbbnl34m1j4ja7rl831dixaz3bznb4ys7lmlsjr"))
\ No newline at end of file
diff --git a/src/guix-crypto/packages/ethereum.scm b/src/guix-crypto/packages/ethereum.scm
index 04b5b76..2e8f6e4 100644
--- a/src/guix-crypto/packages/ethereum.scm
+++ b/src/guix-crypto/packages/ethereum.scm
@@ -43,7 +43,7 @@
   (let* ((commit-hash "25c9b49f") ; first 8 digits of the tagged commit's hash
          (version "1.10.17")
          ;; Note: use bin/geth-update-helper.scm to update the hashes
-         (hashes (read-module-relative-file "geth-binary.hashes")))
+         (hashes (include "geth-binary.hashes")))
     (package
       (name "geth-binary")
       (version version)
@@ -150,7 +150,7 @@ programming language.")
   (let* ((version "1.12.8")
          (commit "2d3dd48")
          ;; Note: use bin/geth-update-helper.scm to update the hashes
-         (hashes (read-module-relative-file "nethermind-binary.hashes")))
+         (hashes (include "nethermind-binary.hashes")))
     (package
       (name "nethermind-binary")
       (version version)
diff --git a/src/guix-crypto/packages/geth-binary.hashes b/src/guix-crypto/packages/geth-binary.hashes
index 090f8ae..61c919f 100644
--- a/src/guix-crypto/packages/geth-binary.hashes
+++ b/src/guix-crypto/packages/geth-binary.hashes
@@ -1,2 +1,2 @@
 ;; This file was generated by the release-update-helper.scm script
-(("aarch64-linux" . "19100yqrd7z8f9cga4a52hygv93wn3syhi7ix4hi9km34v1qi89d") ("x86_64-linux" . "1kljbr3ks2dn6jd87k7l0xaasbk82rrxmaxjkm2vy7cvaxwaq0cw") ("i686-linux" . "05pbyc2wwqla262r09iwv506mfwih31i7ln5zyiy82hkvbdv8d4n"))
\ No newline at end of file
+'(("aarch64-linux" . "19100yqrd7z8f9cga4a52hygv93wn3syhi7ix4hi9km34v1qi89d") ("x86_64-linux" . "1kljbr3ks2dn6jd87k7l0xaasbk82rrxmaxjkm2vy7cvaxwaq0cw") ("i686-linux" . "05pbyc2wwqla262r09iwv506mfwih31i7ln5zyiy82hkvbdv8d4n"))
\ No newline at end of file
diff --git a/src/guix-crypto/packages/nethermind-binary.hashes b/src/guix-crypto/packages/nethermind-binary.hashes
index 1f72dc9..e020b79 100644
--- a/src/guix-crypto/packages/nethermind-binary.hashes
+++ b/src/guix-crypto/packages/nethermind-binary.hashes
@@ -1,2 +1,2 @@
 ;; This file was generated by the release-update-helper.scm script
-(("aarch64-linux" . "1mshp5pqmfn02l6n9v8qj8f6nn6q88jb9rh469mnmbswmr5zsq61") ("x86_64-linux" . "1fzs12c24a38a6xjl94mq2b8q7h6hmf3waw4jacl1xvfqv3w49rw"))
\ No newline at end of file
+'(("aarch64-linux" . "1mshp5pqmfn02l6n9v8qj8f6nn6q88jb9rh469mnmbswmr5zsq61") ("x86_64-linux" . "1fzs12c24a38a6xjl94mq2b8q7h6hmf3waw4jacl1xvfqv3w49rw"))
\ No newline at end of file
diff --git a/src/guix-crypto/packages/swarm.scm b/src/guix-crypto/packages/swarm.scm
index fb49359..8b33adf 100644
--- a/src/guix-crypto/packages/swarm.scm
+++ b/src/guix-crypto/packages/swarm.scm
@@ -37,7 +37,7 @@
 (define-public bee-binary
   (let ((version "1.6.0")
         ;; Note: use bin/geth-update-helper.scm to update the hashes
-        (hashes (read-module-relative-file "bee-binary.hashes")))
+        (hashes (include "bee-binary.hashes")))
     (package
       (name "bee-binary")
       (version version)
diff --git a/src/guix-crypto/packages/zcash-binary.hashes b/src/guix-crypto/packages/zcash-binary.hashes
index 267fc7e..51ba55c 100644
--- a/src/guix-crypto/packages/zcash-binary.hashes
+++ b/src/guix-crypto/packages/zcash-binary.hashes
@@ -1,2 +1,2 @@
 ;; This file was generated by the release-update-helper.scm script
-(("x86_64-linux" . "1c6hfli4wbdw2im51ak1yfg59xnsv33qsiilr24nygbxdp6p1awm"))
\ No newline at end of file
+'(("x86_64-linux" . "1c6hfli4wbdw2im51ak1yfg59xnsv33qsiilr24nygbxdp6p1awm"))
\ No newline at end of file
diff --git a/src/guix-crypto/packages/zcash.scm b/src/guix-crypto/packages/zcash.scm
index 40ef90e..1ca4732 100644
--- a/src/guix-crypto/packages/zcash.scm
+++ b/src/guix-crypto/packages/zcash.scm
@@ -40,7 +40,7 @@
 
 (define-public zcash-binary
   ;; Note: use bin/geth-update-helper.scm to update the hashes
-  (let ((hashes (read-module-relative-file "zcash-binary.hashes")))
+  (let ((hashes (include "zcash-binary.hashes")))
     (package
       (name "zcash-binary")
       (version "4.7.0")

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

* bug#55464: (current-filename) is #f when guix pull'ing
  2022-05-19 13:32   ` Attila Lendvai
@ 2022-05-21 16:39     ` Ludovic Courtès
  0 siblings, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2022-05-21 16:39 UTC (permalink / raw)
  To: Attila Lendvai; +Cc: 55464

Hi,

Attila Lendvai <attila@lendvai.name> skribis:

> is my analysis is correct, namely that cwd is not (always?) changed at macroexpand time, and thus the implementation of INCLUDE is broken for relative paths? is this a bug to be fixed in guile? if so, shall i try to add a test case for this somewhere?

‘include’ does all its work at macro-expansion time.  It’s documented
like so (info "(guile) Local Inclusion"):

 -- Scheme Syntax: include file-name
     Open FILE-NAME, at expansion-time, and read the Scheme forms that
     it contains, splicing them into the location of the ‘include’,
     within a ‘begin’.

     If FILE-NAME is a relative path, it is searched for relative to the
     path that contains the file that the ‘include’ form appears in.

And I believe that’s what it does—see ‘psyntax.scm’ for the actual code.

Now, if source location info were to be missing, it wouldn’t be able to
work for relative file names because it wouldn’t know the name of the
source file that contains the ‘include’ form.

HTH!

Ludo’.




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

end of thread, other threads:[~2022-05-21 16:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 21:04 bug#55464: (current-filename) is #f when guix pull'ing Attila Lendvai
2022-05-17  0:09 ` bug#55464: alternative way Attila Lendvai
2022-05-18  9:14 ` bug#55464: (current-filename) is #f when guix pull'ing Ludovic Courtès
2022-05-19 13:32   ` Attila Lendvai
2022-05-21 16:39     ` Ludovic Courtès

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).