import: opam: Add recursive option.
* guix/script/import/opam.scm: Add recursive option. * guix/import/opam.scm (opam->guix-package): return two values. (opam-recursive-import): New variable.
This commit is contained in:
parent
33af92dd99
commit
6090b0beb0
|
@ -33,7 +33,8 @@
|
||||||
#:use-module (guix utils)
|
#:use-module (guix utils)
|
||||||
#:use-module (guix import utils)
|
#:use-module (guix import utils)
|
||||||
#:use-module ((guix licenses) #:prefix license:)
|
#:use-module ((guix licenses) #:prefix license:)
|
||||||
#:export (opam->guix-package))
|
#:export (opam->guix-package
|
||||||
|
opam-recursive-import))
|
||||||
|
|
||||||
;; Define a PEG parser for the opam format
|
;; Define a PEG parser for the opam format
|
||||||
(define-peg-pattern SP none (or " " "\n"))
|
(define-peg-pattern SP none (or " " "\n"))
|
||||||
|
@ -128,7 +129,6 @@ path to the repository."
|
||||||
(else (string-append "ocaml-" name))))
|
(else (string-append "ocaml-" name))))
|
||||||
|
|
||||||
(define (metadata-ref file lookup)
|
(define (metadata-ref file lookup)
|
||||||
(pk 'file file 'lookup lookup)
|
|
||||||
(fold (lambda (record acc)
|
(fold (lambda (record acc)
|
||||||
(match record
|
(match record
|
||||||
((record key val)
|
((record key val)
|
||||||
|
@ -166,6 +166,21 @@ path to the repository."
|
||||||
(('conditional-value val condition)
|
(('conditional-value val condition)
|
||||||
(if (native? condition) (dependency->input val) ""))))
|
(if (native? condition) (dependency->input val) ""))))
|
||||||
|
|
||||||
|
(define (dependency->name dependency)
|
||||||
|
(match dependency
|
||||||
|
(('string-pat str) str)
|
||||||
|
(('conditional-value val condition)
|
||||||
|
(dependency->name val))))
|
||||||
|
|
||||||
|
(define (dependency-list->names lst)
|
||||||
|
(filter
|
||||||
|
(lambda (name)
|
||||||
|
(not (or
|
||||||
|
(string-prefix? "conf-" name)
|
||||||
|
(equal? name "ocaml")
|
||||||
|
(equal? name "findlib"))))
|
||||||
|
(map dependency->name lst)))
|
||||||
|
|
||||||
(define (ocaml-names->guix-names names)
|
(define (ocaml-names->guix-names names)
|
||||||
(map ocaml-name->guix-name
|
(map ocaml-name->guix-name
|
||||||
(remove (lambda (name)
|
(remove (lambda (name)
|
||||||
|
@ -193,32 +208,41 @@ path to the repository."
|
||||||
(define (opam->guix-package name)
|
(define (opam->guix-package name)
|
||||||
(and-let* ((repository (get-opam-repository))
|
(and-let* ((repository (get-opam-repository))
|
||||||
(version (find-latest-version name repository))
|
(version (find-latest-version name repository))
|
||||||
(file (string-append repository "/packages/" name "/" name "." (pk 'version version) "/opam"))
|
(file (string-append repository "/packages/" name "/" name "." version "/opam"))
|
||||||
(opam-content (get-metadata file))
|
(opam-content (get-metadata file))
|
||||||
(url-dict (metadata-ref (pk 'metadata opam-content) "url"))
|
(url-dict (metadata-ref opam-content "url"))
|
||||||
(source-url (metadata-ref url-dict "src"))
|
(source-url (metadata-ref url-dict "src"))
|
||||||
(requirements (metadata-ref opam-content "depends"))
|
(requirements (metadata-ref opam-content "depends"))
|
||||||
|
(dependencies (dependency-list->names requirements))
|
||||||
(inputs (dependency-list->inputs (depends->inputs requirements)))
|
(inputs (dependency-list->inputs (depends->inputs requirements)))
|
||||||
(native-inputs (dependency-list->inputs (depends->native-inputs requirements))))
|
(native-inputs (dependency-list->inputs (depends->native-inputs requirements))))
|
||||||
(call-with-temporary-output-file
|
(call-with-temporary-output-file
|
||||||
(lambda (temp port)
|
(lambda (temp port)
|
||||||
(and (url-fetch source-url temp)
|
(and (url-fetch source-url temp)
|
||||||
`(package
|
(values
|
||||||
(name ,(ocaml-name->guix-name name))
|
`(package
|
||||||
(version ,(metadata-ref opam-content "version"))
|
(name ,(ocaml-name->guix-name name))
|
||||||
(source
|
(version ,(metadata-ref opam-content "version"))
|
||||||
(origin
|
(source
|
||||||
(method url-fetch)
|
(origin
|
||||||
(uri ,source-url)
|
(method url-fetch)
|
||||||
(sha256 (base32 ,(guix-hash-url temp)))))
|
(uri ,source-url)
|
||||||
(build-system ocaml-build-system)
|
(sha256 (base32 ,(guix-hash-url temp)))))
|
||||||
,@(if (null? inputs)
|
(build-system ocaml-build-system)
|
||||||
'()
|
,@(if (null? inputs)
|
||||||
`((inputs ,(list 'quasiquote inputs))))
|
'()
|
||||||
,@(if (null? native-inputs)
|
`((inputs ,(list 'quasiquote inputs))))
|
||||||
'()
|
,@(if (null? native-inputs)
|
||||||
`((native-inputs ,(list 'quasiquote native-inputs))))
|
'()
|
||||||
(home-page ,(metadata-ref opam-content "homepage"))
|
`((native-inputs ,(list 'quasiquote native-inputs))))
|
||||||
(synopsis ,(metadata-ref opam-content "synopsis"))
|
(home-page ,(metadata-ref opam-content "homepage"))
|
||||||
(description ,(metadata-ref opam-content "description"))
|
(synopsis ,(metadata-ref opam-content "synopsis"))
|
||||||
(license #f)))))))
|
(description ,(metadata-ref opam-content "description"))
|
||||||
|
(license #f))
|
||||||
|
dependencies))))))
|
||||||
|
|
||||||
|
(define (opam-recursive-import package-name)
|
||||||
|
(recursive-import package-name #f
|
||||||
|
#:repo->guix-package (lambda (name repo)
|
||||||
|
(opam->guix-package name))
|
||||||
|
#:guix-name ocaml-name->guix-name))
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
#:use-module (srfi srfi-11)
|
#:use-module (srfi srfi-11)
|
||||||
#:use-module (srfi srfi-37)
|
#:use-module (srfi srfi-37)
|
||||||
|
#:use-module (srfi srfi-41)
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (ice-9 format)
|
#:use-module (ice-9 format)
|
||||||
#:export (guix-import-opam))
|
#:export (guix-import-opam))
|
||||||
|
@ -43,6 +44,8 @@ Import and convert the opam package for PACKAGE-NAME.\n"))
|
||||||
(display (G_ "
|
(display (G_ "
|
||||||
-h, --help display this help and exit"))
|
-h, --help display this help and exit"))
|
||||||
(display (G_ "
|
(display (G_ "
|
||||||
|
-r, --recursive import packages recursively"))
|
||||||
|
(display (G_ "
|
||||||
-V, --version display version information and exit"))
|
-V, --version display version information and exit"))
|
||||||
(newline)
|
(newline)
|
||||||
(show-bug-report-information))
|
(show-bug-report-information))
|
||||||
|
@ -56,6 +59,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 '(#\r "recursive") #f #f
|
||||||
|
(lambda (opt name arg result)
|
||||||
|
(alist-cons 'recursive #t result)))
|
||||||
%standard-import-options))
|
%standard-import-options))
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,11 +87,22 @@ Import and convert the opam package for PACKAGE-NAME.\n"))
|
||||||
(reverse opts))))
|
(reverse opts))))
|
||||||
(match args
|
(match args
|
||||||
((package-name)
|
((package-name)
|
||||||
(let ((sexp (opam->guix-package package-name)))
|
(if (assoc-ref opts 'recursive)
|
||||||
(unless sexp
|
;; Recursive import
|
||||||
(leave (G_ "failed to download meta-data for package '~a'~%")
|
(map (match-lambda
|
||||||
package-name))
|
((and ('package ('name name) . rest) pkg)
|
||||||
sexp))
|
`(define-public ,(string->symbol name)
|
||||||
|
,pkg))
|
||||||
|
(_ #f))
|
||||||
|
(reverse
|
||||||
|
(stream->list
|
||||||
|
(opam-recursive-import package-name))))
|
||||||
|
;; Single import
|
||||||
|
(let ((sexp (opam->guix-package package-name)))
|
||||||
|
(unless sexp
|
||||||
|
(leave (G_ "failed to download meta-data for package '~a'~%")
|
||||||
|
package-name))
|
||||||
|
sexp)))
|
||||||
(()
|
(()
|
||||||
(leave (G_ "too few arguments~%")))
|
(leave (G_ "too few arguments~%")))
|
||||||
((many ...)
|
((many ...)
|
||||||
|
|
Loading…
Reference in New Issue