Subject: [bug#39862] [PATCH v2 6/6] gnu: define dune-*-openmpi packages

From: Ludovic Courtès <[email-masked]>
Date: Thu, 12 Mar 2020 13:42:37 +0100

Hi again,

Felix Gruber <[email-masked]> skribis:

> +(define add-openmpi-to-dune-package
> +  (let ((transformed-packages '()))
> +   (lambda (p)
> +    (let* ((p-name (package-name p))
> +           (replace-package
> +             (lambda (mapping)
> +               (let* ((name (car mapping))
> +                      (p (cadr mapping))
> +                      (new-p
> +                        (match (assoc-ref transformed-packages name)
> +                          (#f
> +                           (if (string-prefix? "dune-" name)
> +                               (raise (condition
> +                                 (&message
> +                                  (message
> +                                   (format #f "Need to call \
> +add-openmpi-to-dune-package on '~a' before '~a'."
> +                                           name p-name)))))
> +                               p))
> +                          (transformed-p transformed-p))))
> +                `(,name ,new-p))))
> +           (substitute-mpi-packages (lambda (inputs)
> +                                      (map replace-package inputs)))
> +           (mpi-p
> +             (package (inherit p)
> +               (name (string-append p-name "-openmpi"))
> +               (inputs `(,@(substitute-mpi-packages (package-inputs p))
> +                         ("openmpi" ,openmpi)))
> +               (propagated-inputs
> +                 (substitute-mpi-packages (package-propagated-inputs p)))
> +               (arguments
> +                (substitute-keyword-arguments (package-arguments p)
> +                  ((#:phases phases '%standard-phases)
> +                   `(modify-phases ,phases
> +                      (add-before 'check 'mpi-setup
> +                        ,%openmpi-setup)))))
> +               (synopsis (string-append (package-synopsis p) " (with MPI support)")))))
> +     (begin
> +      (set! transformed-packages
> +            (acons p-name mpi-p transformed-packages))
> +      mpi-p)))))

I think it’s a good idea to add those “-openmpi” packages.  However, I
have suggestions regarding the code above.  :-)

A general note: set!, car, cdr, etc. are frowned upon in Guix:

  https://guix.gnu.org/manual/en/html_node/Coding-Style.html

It seems to me that ‘replace-package’ above is overly generic: since
it’s an internal procedure, we don’t need to add error cases, messages,
etc.

Last, could it be written in terms of ‘package-mapping’?  That takes
care of graph traversal and memoization.

Thanks,
Ludo’.