From: Ulf Herrman <striness@tilde.club>
To: 66510@debbugs.gnu.org
Subject: bug#66510: `this-package' references reintroduce pre-transformation packages.
Date: Thu, 12 Oct 2023 22:57:14 -0500 [thread overview]
Message-ID: <87sf6fdvj9.fsf@tilde.club> (raw)
[-- Attachment #1: Type: text/plain, Size: 2927 bytes --]
Suppose you have a package that is using a gexp in its argument list
and, like a good citizen of the gexp world, it uses this-package-input
to refer to its own input packages. In fact, let's suppose that it's
the model citizen depicted in
https://guix.gnu.org/en/blog/2021/the-big-change/ under the
"G-expressions and self-referential records" heading:
(define hello
(package
(name "hello")
;; …
(arguments
(list #:configure-flags
#~(list (string-append "--with-gawk="
#$(this-package-input "gawk")))))
(inputs `(("gawk" ,gawk)))))
If we define a variant like so:
(define hello-variant
(package
(inherit hello)
(name "hello-variant")
(inputs `(("gawk" ,gawk-4.0)))))
it will work just fine. But if we define a variant like SO:
(define hello-variant
(package
(inherit hello)
(name "hello-variant")
(inputs `(("gawk" ,gawk-4.0)))
(arguments
(substitute-keyword-arguments (package-arguments hello)
((#:configure-flags flags #~'())
#~(cons "--with-hospitality=ice-cream"
#$flags))))))
it will NOT work just fine. When (package-arguments hello) is
evaluated, it will execute the field definition for `hello' with
`this-package' bound to `hello', rather than `hello-variant'.
Consequently, `this-package-input' will return gawk rather than
gawk-4.0. We need a way to access the "parent" package's fields while
keeping `this-package' bound to its current value. The most general
form of this would look something like this:
(define (package-arguments-with-package p0 p)
(match p0
(($ <package> _ _ _ _ arguments-proc)
(arguments-proc p))))
Then hello-variant could be changed to use
(package-arguments-with-package hello this-package)
instead of (package-arguments hello). This may be needlessly general,
though; the problem could also be solved with an interface more along
the lines of
(parent-package-arguments hello)
which expands into the aforementioned package-arguments-with-package
call.
Another option would be to, yet again, extend the record syntax. It's
always bugged me a bit to have to explicitly reference the original
record in more than one place when using derived fields, so this might
be generally useful as well:
(define hello-variant
(package
(inherit hello
(arguments hello-arguments))
(name "hello-variant")
(inputs `(("gawk" ,gawk-4.0)))
(arguments
(substitute-keyword-arguments hello-arguments
((#:configure-flags flags #~'())
#~(cons "--with-hospitality=ice-cream"
#$flags))))))
This would create a macro named `hello-arguments' within the scope of
the (package ...) form which expands into something equivalent to a
`parent-package-arguments' call. Adjust syntax to taste.
Thoughts?
- Ulf
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]
next reply other threads:[~2023-10-13 3:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-13 3:57 Ulf Herrman [this message]
2024-04-09 14:06 ` bug#66510: Unexpected `this-package(-native)-input` Jake
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=87sf6fdvj9.fsf@tilde.club \
--to=striness@tilde.club \
--cc=66510@debbugs.gnu.org \
/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).