`this-package' references reintroduce pre-transformation packages.

  • Open
  • quality assurance status badge
Details
2 participants
  • Jake
  • Ulf Herrman
Owner
unassigned
Submitted by
Ulf Herrman
Severity
normal
Merged with
U
U
Ulf Herrman wrote on 13 Oct 2023 05:57
(address . bug-guix@gnu.org)
87sf6fdvj9.fsf@tilde.club
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
"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
-----BEGIN PGP SIGNATURE-----

iQHIBAEBCAAyFiEEn6BUn0yca1D9JsMa1lV76sJM9mgFAmUowBoUHHN0cmluZXNz
QHRpbGRlLmNsdWIACgkQ1lV76sJM9mhMggv+KB3jA1cTdS9iUoGC2tJWHNvWYAjp
tq6kaKJgop/2hgxcdPuhB37Lcx3TOCTJoVFzL7Mpni6o4k2UolgERYMy9hUCzXul
XZhqoLrSvDWfQEpoKzFNMZaVGC6PSirFdFb3XteyrfiWyjH/INgL/IX+V91g93Si
/ZR7Ks6CiRuQ5MReW2LzyhiDx64KXEnE3oUCnqKUfDJgLtHD/bFqqK3ZqjIPeIir
4pPDfq2pyH8MqQAx5cQjfmQwVoX1RNKITISHlvIAZvTVsp7oCJV0Rvg/Pg+8kpFI
P6eKyzsJJbZx4NYVRpXAXXpfcn5D02CjGErOYrFolK+HLT5KlyNc6FYFQstOyoB2
vAu/WYaSBD4rfaT6iSL4m9zH4kMb6pl2sLkgMP5QPYK2i0zsnvjAqBc+2SPOwpvE
n52+uq7w/WtqzcZCYzmezunTK9VvGy50+HkfC2aVDpckpC3HSklotkDhJkn8PHwy
bxxxDRP9nfcG9YirGPJrJ+Y5G0UmBvAniMkR
=8Su+
-----END PGP SIGNATURE-----

U
U
Ulf Herrman wrote on 22 Oct 2023 00:33
Merge new duplicate
(address . control@debbugs.gnu.org)
87y1fvppvp.fsf@tilde.club
forcemerge 50335 66510
J
Unexpected `this-package(-native)-input`
(address . 66510@debbugs.gnu.org)
CAJqVjv-xvBoWYJtoaNvvk5py_c=UCen+KYnzskJ+dmocLuGhbQ@mail.gmail.com
Hi Ulf

Has any progress been made on this?

I ran into the same thing, except with native-inputs instead of inputs.
I spent a fair amount of time trying to pin it down, since I don't know
much guile and it requires a combination of conditions to manifest.
Is it worth documenting this behaviour? Or do we expect a solution will be
implemented soon enough?

For now, is the following guideline accurate enough to avoid these
surprises?

If we inherit a package that uses (either directly or through inheritance)
this-package-native-input (or this-package-input), we should not modify the
native inputs (or inputs) via replace if substitute-keyword-arguments is
used anywhere in the inheritance chain.

Thanks
Jake
Attachment: file
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 66510@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 66510
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch