unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Attila Lendvai <attila@lendvai.name>
To: Reza Housseini <reza.housseini@gmail.com>
Cc: guix-devel@gnu.org
Subject: Re: Version from file in a package
Date: Sat, 23 Sep 2023 12:22:15 +0000	[thread overview]
Message-ID: <sMSoEtO29aVvzTJcaElsNbCxikrglvdtisE9oKIFuqbRrYPn0aTekpDozUmYMBdOn0WFUMEGinTCr8A9AQDPO03TOAio31SZTdePeU-yEXM=@lendvai.name> (raw)
In-Reply-To: <1d2a4522-3844-403b-1c09-aeb423bf4d28@gmail.com>

this may be related (also see the discussion):

(current-filename) is #f when guix pull'ing
https://issues.guix.gnu.org/55464

i haven't yet double-checked Ludo's recommendation to use INCLUDE, which should work, but it didn't for me. my current solution is this:

(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))
    (lambda _
      (values (read)     ; version
              (read))))) ; hashes

(define-syntax read-hashes-file
  (lambda (syn)
    (syntax-case syn ()
      ((_ filename)
       (with-syntax
           ;; Reads the file at compile time and macroexpands to the first form in it.
           ((form (call-with-values
                      (lambda _
                        (%read-module-relative-file (current-module)
                                                    (string-append "hashes/"
                                                                   (syntax->datum #'filename)
                                                                   ".hashes")))
                    (lambda (version hashes)
                      #`(values '#,version '#,hashes)))))
         #'form)))))

HTH,

-- 
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“Never argue with someone whose TV is bigger than their bookshelf.”
	— Emilia Clarke



      parent reply	other threads:[~2023-09-23 12:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22 12:20 Version from file in a package Reza Housseini
2023-09-22 13:11 ` paul
2023-09-23 12:22 ` Attila Lendvai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='sMSoEtO29aVvzTJcaElsNbCxikrglvdtisE9oKIFuqbRrYPn0aTekpDozUmYMBdOn0WFUMEGinTCr8A9AQDPO03TOAio31SZTdePeU-yEXM=@lendvai.name' \
    --to=attila@lendvai.name \
    --cc=guix-devel@gnu.org \
    --cc=reza.housseini@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).