diff options
author | zero@fedora <zero@fedora> | 2024-01-10 04:29:56 +0300 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2024-11-23 16:23:19 +0100 |
commit | 2d3bf6a2a33fae685c03320f289d73ba3e7275f6 (patch) | |
tree | 485b1c0f6ab90cbd39b5458abc1049a1ac9f1e02 | |
parent | ea5ee89274d47d06d05feed927c0eb50ae316db3 (diff) |
import: cpan: Support recursive imports.
* guix/import/cpan.scm (cpan-module->sexp): Return two values.
(cpan->guix-package): Add #:version. Return two values.
(cpan-recursive-import): New procedure.
* guix/scripts/import/cpan.scm (show-help, %options): Add ‘-r’.
(guix-import-cpan): Adjust accordingly.
Change-Id: Id167c7ddd079f4e04650ce7cc1692a9de36cd8fe
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
-rw-r--r-- | doc/guix.texi | 11 | ||||
-rw-r--r-- | guix/import/cpan.scm | 61 | ||||
-rw-r--r-- | guix/scripts/import/cpan.scm | 24 |
3 files changed, 66 insertions, 30 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 454dd66c18..8297ad2ca6 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -14207,6 +14207,17 @@ The command below imports metadata for the Acme::Boolean Perl module: guix import cpan Acme::Boolean @end example +Like many other importers, the @code{cpan} importer supports recursive +imports: + +@table @code +@item --recursive +@itemx -r +Traverse the dependency graph of the given upstream package recursively +and generate package expressions for all those packages that are not yet +in Guix. +@end table + @item cran @cindex CRAN @cindex Bioconductor diff --git a/guix/import/cpan.scm b/guix/import/cpan.scm index b87736eef6..85e5e69098 100644 --- a/guix/import/cpan.scm +++ b/guix/import/cpan.scm @@ -37,12 +37,14 @@ #:use-module (guix utils) #:use-module (guix base32) #:use-module ((guix download) #:select (download-to-store url-fetch)) - #:use-module ((guix import utils) #:select (factorize-uri)) + #:use-module ((guix import utils) + #:select (factorize-uri recursive-import)) #:use-module (guix import json) #:use-module (guix packages) #:use-module (guix upstream) #:use-module (guix derivations) #:export (cpan->guix-package + cpan-recursive-import metacpan-url->mirror-url %cpan-updater @@ -284,35 +286,39 @@ in RELEASE, a <cpan-release> record." upstream-input-downstream-name) inputs))))))) - (let ((tarball (with-store store + (let* ((tarball (with-store store (download-to-store store source-url))) - (inputs (cpan-module-inputs release))) - `(package - (name ,(cpan-name->downstream-name name)) - (version ,version) - (source (origin - (method url-fetch) - (uri (string-append ,@(factorize-uri source-url version))) - (sha256 - (base32 - ,(bytevector->nix-base32-string (file-sha256 tarball)))))) - (build-system perl-build-system) - ,@(maybe-inputs 'native-inputs - (filter (upstream-input-type-predicate 'native) - inputs)) - ,@(maybe-inputs 'propagated-inputs - (filter (upstream-input-type-predicate 'propagated) - inputs)) - (home-page ,(cpan-home name)) - (synopsis ,(cpan-release-abstract release)) - (description fill-in-yourself!) - (license ,(string->license (cpan-release-license release)))))) + (inputs (cpan-module-inputs release)) + (sexp + `(package + (name ,(cpan-name->downstream-name name)) + (version ,version) + (source (origin + (method url-fetch) + (uri (string-append ,@(factorize-uri source-url version))) + (sha256 + (base32 + ,(bytevector->nix-base32-string (file-sha256 tarball)))))) + (build-system perl-build-system) + ,@(maybe-inputs 'native-inputs + (filter (upstream-input-type-predicate 'native) + inputs)) + ,@(maybe-inputs 'propagated-inputs + (filter (upstream-input-type-predicate 'propagated) + inputs)) + (home-page ,(cpan-home name)) + (synopsis ,(cpan-release-abstract release)) + (description fill-in-yourself!) + (license ,(string->license (cpan-release-license release)))))) + (values sexp (map upstream-input-name inputs)))) -(define (cpan->guix-package module-name) +(define* (cpan->guix-package module-name #:key version #:allow-other-keys) "Fetch the metadata for PACKAGE-NAME from metacpan.org, and return the `package' s-expression corresponding to that package, or #f on failure." (let ((release (cpan-fetch (module->name module-name)))) - (and=> release cpan-module->sexp))) + (if release + (cpan-module->sexp release) + (values #f '())))) (define cpan-package? (let ((cpan-rx (make-regexp (string-append "(" @@ -357,6 +363,11 @@ in RELEASE, a <cpan-release> record." (urls (list url)) (inputs (cpan-module-inputs release))))))) +(define* (cpan-recursive-import package-name) + (recursive-import package-name + #:repo->guix-package cpan->guix-package + #:guix-name (compose cpan-name->downstream-name module->name))) + (define %cpan-updater (upstream-updater (name 'cpan) diff --git a/guix/scripts/import/cpan.scm b/guix/scripts/import/cpan.scm index bdf5a1e423..4ddd85ee57 100644 --- a/guix/scripts/import/cpan.scm +++ b/guix/scripts/import/cpan.scm @@ -44,6 +44,8 @@ Import and convert the CPAN package for PACKAGE-NAME.\n")) (display (G_ " -h, --help display this help and exit")) (display (G_ " + -r, --recursive import missing packages recursively")) + (display (G_ " -V, --version display version information and exit")) (newline) (show-bug-report-information)) @@ -54,6 +56,9 @@ Import and convert the CPAN package for PACKAGE-NAME.\n")) (lambda args (show-help) (exit 0))) + (option '(#\r "recursive") #f #f + (lambda (opt name arg result) + (alist-cons 'recursive #t result))) (option '(#\V "version") #f #f (lambda args (show-version-and-exit "guix import cpan"))) @@ -78,11 +83,20 @@ Import and convert the CPAN package for PACKAGE-NAME.\n")) (reverse opts)))) (match args ((package-name) - (let ((sexp (cpan->guix-package package-name))) - (unless sexp - (leave (G_ "failed to download meta-data for package '~a'~%") - package-name)) - sexp)) + (let ((sexp + (if (assoc-ref opts 'recursive) + (map (match-lambda + ((and ('package ('name name) . rest) pkg) + `(define-public ,(string->symbol name) + ,pkg)) + (_ #f)) + (cpan-recursive-import package-name)) + (let ((sexp (cpan->guix-package package-name))) + sexp)))) + (unless sexp + (leave (G_ "failed to download meta-data for package '~a'~%") + package-name)) + sexp)) (() (leave (G_ "too few arguments~%"))) ((many ...) |