all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#50335: Inheritance vs. ‘this-package’
@ 2021-09-02 13:48 Ludovic Courtès
  2023-03-04 15:15 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Ludovic Courtès @ 2021-09-02 13:48 UTC (permalink / raw)
  To: 50335; +Cc: philippe.swartvagher

Hi!

We stumbled upon an idiom for package arguments that, combined with
package inheritance, would not work as expected.  It goes like this
(taken from <https://gitlab.inria.fr/guix-hpc/guix-hpc/>):

--8<---------------cut here---------------start------------->8---
(define-public starpu
  (package
    ;; …
    (arguments
      (substitute-keyword-arguments (package-arguments starpu-1.2)
        ((#:configure-flags flags '())
         (match (assoc "mpi" (package-propagated-inputs this-package))
           (("mpi" mpi)
            (if (string=? (package-name mpi) "nmad")
                `(cons "--enable-nmad" ,flags)
                flags))))))
    (propagated-inputs `(("mpi" ,openmpi)))))

(define-public starpu+fxt
  (package
    (inherit starpu)
    ;; …
    (arguments
     (substitute-keyword-arguments (package-arguments starpu)
       ((#:configure-flags flags '())
        `(cons "--with-fxt" ,flags))))))
--8<---------------cut here---------------end--------------->8---

The first package, ‘starpu’, has its arguments depend on:

  (package-propagated-inputs this-package)

This is smart because if you inherit from it without changing the
‘arguments’ field (for instance by doing ‘--with-input=openmpi=nmad’),
it’ll adjust its configure flags based on the MPI package it actually
depends on.

However, this trick doesn’t work with the second package, ‘starpu-fxt’:
if you do:

  guix build starpu-fxt --with-input=openmpi=nmad

the ‘--enable-nmad’ configure flag will not be passed.  This is because
‘starpu-fxt’ calls:

  (package-arguments starpu)

which returns the original arguments of ‘starpu’.


Still here?  :-)

This is admittedly a pretty far-fetched example and there are ways to
work around it¹.  Still, I wonder if we could up with a linguistic
device (ah ha!) to address that.

We don’t want to (package-arguments this-package) here: that would
naturally lead to an infinite loop.  But we want something close to it,
in spirit: (package-arguments parent), where ‘parent’ is the package we
inherit from.

(package-arguments parent) could call the ‘arguments’ thunk of the
parent, but it would pass it the child as its argument.

Or something like that.

Thoughts?

Ludo’.

¹ https://gitlab.inria.fr/guix-hpc/guix-hpc/-/commit/761cfe97d5bb42dbbde538593cef93e803086e3b




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

* bug#50335: Inheritance vs. ‘this-package’
  2021-09-02 13:48 bug#50335: Inheritance vs. ‘this-package’ Ludovic Courtès
@ 2023-03-04 15:15 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2023-03-04 15:15 UTC (permalink / raw)
  To: 50335; +Cc: philippe.swartvagher

Ludovic Courtès <ludovic.courtes@inria.fr> skribis:

> We stumbled upon an idiom for package arguments that, combined with
> package inheritance, would not work as expected.

[...]

> We don’t want to (package-arguments this-package) here: that would
> naturally lead to an infinite loop.  But we want something close to it,
> in spirit: (package-arguments parent), where ‘parent’ is the package we
> inherit from.
>
> (package-arguments parent) could call the ‘arguments’ thunk of the
> parent, but it would pass it the child as its argument.

Here’s an example where I ended up manually defining ‘parent’:

  https://git.savannah.gnu.org/cgit/guix.git/commit/?h=core-updates&id=0aed5bf5120bd434e53be0cea3f96547f95837d6

Ludo’.




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

end of thread, other threads:[~2023-03-04 15:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-02 13:48 bug#50335: Inheritance vs. ‘this-package’ Ludovic Courtès
2023-03-04 15:15 ` 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.