Subject: [bug#70227] [PATCH 2/2] guix: import: composer: Implement recursive package refresh.

From: Ludovic Courtès <[email-masked]>
Date: Mon, 29 Apr 2024 23:29:44 +0200

Hi!

Nicolas Graves <[email-masked]> skribis:

> * guix/import/composer.scm
>  (composer-fetch): Replace reduce by fold to correct version selection
>  logic.
>  (latest-release): Implement recursive package refresh. Rename to
>  import-release.
>  (import-release): New function, formerly known as latest-release.

Nice, glad to see this feature put to good use.  :-)

[...]

> +(define* (import-release package #:key (version #f))
> +  "Return an <upstream-source> for VERSION or the latest release of PACKAGE."
>    (let* ((php-name (guix-package->composer-name package))
>           (composer-package (composer-fetch php-name #:version version)))
>      (if composer-package
> -        (upstream-source
> -         (package (composer-package-name composer-package))
> -         (version (composer-package-version composer-package))
> -         (urls (list (composer-source-url
> -                      (composer-package-source composer-package)))))
> +        (let* ((guix-name (composer-package-name composer-package))
> +               (inputs
> +                (append
> +                 (map (lambda (dep)
> +                        (upstream-input
> +                         (name php-name)
> +                         (downstream-name guix-name)
> +                         (type 'regular)))
> +                      (composer-package-require composer-package))
> +                 (map (lambda (dep)
> +                        (upstream-input
> +                         (name php-name)
> +                         (downstream-name guix-name)
> +                         (type 'native)))

Shouldn’t it be:

  (upstream-input
    (name dep)
    (downstream-name (php-package-name dep))
    (type …))

?

As a slight improvement, since the ‘inputs’ field of <upstream-source>
is delayed (wrapped in a promise, so that its computation only happens
when it’s needed), you could arrange to replace the ‘inputs’ variable
above like so:

  (define (dependency->input dependency type)
    (upstream-input …))

  (upstream-source
    ;; …
    (inputs (append (map (cut dependency->input <> 'regular) …)
                    (map (cut dependency->input <> 'native) …))))

I hope this makes sense.

Thanks!

Ludo’.