Subject: [PATCH] guix: import: composer: Implement recursive package refresh.

From: Nicolas Graves <[email-masked]>
Date: Tue, 19 Dec 2023 17:53:28 +0100

* 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.
---
 guix/import/composer.scm | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/guix/import/composer.scm b/guix/import/composer.scm
index b23af1b91f..26229e3ad0 100644
--- a/guix/import/composer.scm
+++ b/guix/import/composer.scm
@@ -113,7 +113,7 @@ (define* (composer-fetch name #:key (version #f))
          (if version
              (assoc-ref packages version)
              (cdr
-              (reduce
+              (fold
                (lambda (new cur-max)
                  (match new
                    (((? valid-version? version) . tail)
@@ -243,8 +243,8 @@ (define (php-package? package)
    (eq? (package-build-system package) composer-build-system)
    (string-prefix? "php-" (package-name package))))
 
-(define* (latest-release package #:key (version #f))
-  "Return an <upstream-source> for the latest release of PACKAGE."
+(define* (import-release package #:key (version #f))
+  "Return an <upstream-source> for the VERSION or latest release of PACKAGE."
   (let* ((php-name (guix-package->composer-name package))
          (composer-package (composer-fetch php-name #:version version)))
     (match composer-package
@@ -254,18 +254,34 @@ (define* (latest-release package #:key (version #f))
                php-name)
        #f)
       (_
-       (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)))
+                     (composer-package-dev-require composer-package)))))
+         (upstream-source
+          (package guix-name)
+          (version (composer-package-version composer-package))
+          (urls (list (composer-source-url
+                       (composer-package-source composer-package))))
+          (inputs inputs)))))))
 
 (define %composer-updater
   (upstream-updater
    (name 'composer)
    (description "Updater for Composer packages")
    (pred php-package?)
-   (import latest-release)))
+   (import import-release)))
 
 (define* (composer-recursive-import package-name #:optional version)
   (recursive-import package-name
-- 
2.41.0