Archived
1
0
Fork 0

guix: opam: Add --repo argument to importer.

* guix/scripts/import/opam.scm (guix-import-opam): Pass --repo argument
to recursive and non-recursive importers.
* guix/import/opam.scm (get-opam-repository): Select proper repository
location depending on a new repo argument.
(opam->guix-package): Use get-opam-repository in the procedure body.
This commit is contained in:
Julien Lepiller 2020-12-08 14:58:39 +01:00
parent 15ee1b8317
commit a8dccd4bdc
No known key found for this signature in database
GPG key ID: 53D457B2D636EE82
2 changed files with 22 additions and 9 deletions

View file

@ -120,12 +120,19 @@
(define-peg-pattern condition-string all (and QUOTE (* STRCHR) QUOTE)) (define-peg-pattern condition-string all (and QUOTE (* STRCHR) QUOTE))
(define-peg-pattern condition-var all (+ (or (range #\a #\z) "-" ":"))) (define-peg-pattern condition-var all (+ (or (range #\a #\z) "-" ":")))
(define (get-opam-repository) (define* (get-opam-repository #:optional repo)
"Update or fetch the latest version of the opam repository and return the "Update or fetch the latest version of the opam repository and return the
path to the repository." path to the repository."
(let ((url (cond
((or (not repo) (equal? repo 'opam))
"https://github.com/ocaml/opam-repository")
(else (throw 'unknown-repository repo)))))
(receive (location commit _) (receive (location commit _)
(update-cached-checkout "https://github.com/ocaml/opam-repository") (update-cached-checkout url)
location)) (cond
((or (not repo) (equal? repo 'opam))
location)
(else location)))))
(define (latest-version versions) (define (latest-version versions)
"Find the most recent version from a list of versions." "Find the most recent version from a list of versions."
@ -264,11 +271,11 @@ path to the repository."
(substring version 1) (substring version 1)
version))))) version)))))
(define* (opam->guix-package name #:key (repo (get-opam-repository)) version) (define* (opam->guix-package name #:key (repo 'opam) version)
"Import OPAM package NAME from REPOSITORY (a directory name) or, if "Import OPAM package NAME from REPOSITORY (a directory name) or, if
REPOSITORY is #f, from the official OPAM repository. Return a 'package' sexp REPOSITORY is #f, from the official OPAM repository. Return a 'package' sexp
or #f on failure." or #f on failure."
(and-let* ((opam-file (opam-fetch name repo)) (and-let* ((opam-file (opam-fetch name (get-opam-repository repo)))
(version (assoc-ref opam-file "version")) (version (assoc-ref opam-file "version"))
(opam-content (assoc-ref opam-file "metadata")) (opam-content (assoc-ref opam-file "metadata"))
(url-dict (metadata-ref opam-content "url")) (url-dict (metadata-ref opam-content "url"))
@ -323,7 +330,7 @@ or #f on failure."
(not (member name '("dune" "jbuilder")))) (not (member name '("dune" "jbuilder"))))
dependencies)))))))) dependencies))))))))
(define* (opam-recursive-import package-name #:repo (get-opam-repository)) (define* (opam-recursive-import package-name #:key repo)
(recursive-import package-name (recursive-import package-name
#:repo->guix-package opam->guix-package #:repo->guix-package opam->guix-package
#:guix-name ocaml-name->guix-name #:guix-name ocaml-name->guix-name

View file

@ -44,6 +44,8 @@ Import and convert the opam package for PACKAGE-NAME.\n"))
-h, --help display this help and exit")) -h, --help display this help and exit"))
(display (G_ " (display (G_ "
-r, --recursive import packages recursively")) -r, --recursive import packages recursively"))
(display (G_ "
--repo import packages from this opam repository"))
(display (G_ " (display (G_ "
-V, --version display version information and exit")) -V, --version display version information and exit"))
(newline) (newline)
@ -58,6 +60,9 @@ Import and convert the opam package for PACKAGE-NAME.\n"))
(option '(#\V "version") #f #f (option '(#\V "version") #f #f
(lambda args (lambda args
(show-version-and-exit "guix import opam"))) (show-version-and-exit "guix import opam")))
(option '(#f "repo") #t #f
(lambda (opt name arg result)
(alist-cons 'repo arg result)))
(option '(#\r "recursive") #f #f (option '(#\r "recursive") #f #f
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'recursive #t result))) (alist-cons 'recursive #t result)))
@ -79,6 +84,7 @@ Import and convert the opam package for PACKAGE-NAME.\n"))
%default-options)) %default-options))
(let* ((opts (parse-options)) (let* ((opts (parse-options))
(repo (and=> (assoc-ref opts 'repo) string->symbol))
(args (filter-map (match-lambda (args (filter-map (match-lambda
(('argument . value) (('argument . value)
value) value)
@ -93,9 +99,9 @@ Import and convert the opam package for PACKAGE-NAME.\n"))
`(define-public ,(string->symbol name) `(define-public ,(string->symbol name)
,pkg)) ,pkg))
(_ #f)) (_ #f))
(opam-recursive-import package-name)) (opam-recursive-import package-name #:repo repo))
;; Single import ;; Single import
(let ((sexp (opam->guix-package package-name))) (let ((sexp (opam->guix-package package-name #:repo repo)))
(unless sexp (unless sexp
(leave (G_ "failed to download meta-data for package '~a'~%") (leave (G_ "failed to download meta-data for package '~a'~%")
package-name)) package-name))