From 003366fc96080abcd07a8573a58e784ca837dbb9 Mon Sep 17 00:00:00 2001 From: Nicolas Graves Date: Mon, 7 Oct 2024 01:56:00 +0200 Subject: [PATCH] import: composer: Implement recursive package refresh. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/import/composer.scm (guix-package->composer-name): Simplify. (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. Change-Id: I8f629b4d1da866f5986d39b4e159f2b44af9ee49 Signed-off-by: Ludovic Courtès --- guix/import/composer.scm | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/guix/import/composer.scm b/guix/import/composer.scm index 75419ca63e..abc9023be4 100644 --- a/guix/import/composer.scm +++ b/guix/import/composer.scm @@ -19,12 +19,14 @@ (define-module (guix import composer) #:use-module (ice-9 match) #:use-module (json) - #:use-module (guix hash) #:use-module (guix base32) #:use-module (guix build git) #:use-module (guix build utils) #:use-module (guix build-system) #:use-module (guix build-system composer) + #:use-module ((guix diagnostics) #:select (warning)) + #:use-module (guix hash) + #:use-module (guix i18n) #:use-module (guix import json) #:use-module (guix import utils) #:use-module ((guix licenses) #:prefix license:) @@ -113,7 +115,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) @@ -217,13 +219,8 @@ (define (guix-name->composer-name name) (define (guix-package->composer-name package) "Given a Composer PACKAGE built from Packagist, return the name of the package in Packagist." - (let ((upstream-name (assoc-ref - (package-properties package) - 'upstream-name)) - (name (package-name package))) - (if upstream-name - upstream-name - (guix-name->composer-name name)))) + (or (assoc-ref (package-properties package) 'upstream-name) + (guix-name->composer-name (package-name package)))) (define (string->license str) "Convert the string STR into a license object." @@ -243,8 +240,14 @@ (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 for the latest release of PACKAGE." +(define (dependency->input dependency type) + (upstream-input + (name dependency) + (downstream-name (php-package-name dependency)) + (type type))) + +(define* (import-release package #:key (version #f)) + "Return an 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 @@ -252,7 +255,12 @@ (define* (latest-release package #:key (version #f)) (package (composer-package-name composer-package)) (version (composer-package-version composer-package)) (urls (list (composer-source-url - (composer-package-source composer-package))))) + (composer-package-source composer-package)))) + (inputs (append + (map (cut dependency->input <> 'regular) + (composer-package-require composer-package)) + (map (cut dependency->input <> 'native) + (composer-package-dev-require composer-package))))) (begin (warning (G_ "failed to parse ~a~%") php-name) #f)))) @@ -262,7 +270,7 @@ (define %composer-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