import: opam: Factor out source import.
This also ensures a package can be imported even when it does not specify a URL. * guix/import/opam.scm (opam->guix-source): New procedure. (opam->guix-package): Use it. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
be7338d400
commit
d59abc336d
1 changed files with 43 additions and 38 deletions
|
@ -324,6 +324,20 @@ path to the repository."
|
||||||
(filter-map get-opam-repository repositories-specs))
|
(filter-map get-opam-repository repositories-specs))
|
||||||
(warning (G_ "opam: package '~a' not found~%") name)))
|
(warning (G_ "opam: package '~a' not found~%") name)))
|
||||||
|
|
||||||
|
(define (opam->guix-source url-dict)
|
||||||
|
(let ((source-url (and url-dict
|
||||||
|
(or (metadata-ref url-dict "src")
|
||||||
|
(metadata-ref url-dict "archive")))))
|
||||||
|
(if source-url
|
||||||
|
(call-with-temporary-output-file
|
||||||
|
(lambda (temp port)
|
||||||
|
(and (url-fetch source-url temp)
|
||||||
|
`(origin
|
||||||
|
(method url-fetch)
|
||||||
|
(uri ,source-url)
|
||||||
|
(sha256 (base32 ,(guix-hash-url temp)))))))
|
||||||
|
'no-source-information)))
|
||||||
|
|
||||||
(define* (opam->guix-package name #:key (repo 'opam) 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
|
||||||
|
@ -332,9 +346,7 @@ or #f on failure."
|
||||||
(opam-file (opam-fetch name with-opam))
|
(opam-file (opam-fetch name with-opam))
|
||||||
(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"))
|
(source (opam->guix-source (metadata-ref opam-content "url")))
|
||||||
(source-url (or (metadata-ref url-dict "src")
|
|
||||||
(metadata-ref url-dict "archive")))
|
|
||||||
(requirements (metadata-ref opam-content "depends"))
|
(requirements (metadata-ref opam-content "depends"))
|
||||||
(names (dependency-list->names requirements))
|
(names (dependency-list->names requirements))
|
||||||
(dependencies (filter-dependencies names))
|
(dependencies (filter-dependencies names))
|
||||||
|
@ -348,41 +360,34 @@ or #f on failure."
|
||||||
(not (member name '("dune" "jbuilder"))))
|
(not (member name '("dune" "jbuilder"))))
|
||||||
native-dependencies))))
|
native-dependencies))))
|
||||||
(let ((use-dune? (member "dune" names)))
|
(let ((use-dune? (member "dune" names)))
|
||||||
(call-with-temporary-output-file
|
(values
|
||||||
(lambda (temp port)
|
`(package
|
||||||
(and (url-fetch source-url temp)
|
(name ,(ocaml-name->guix-name name))
|
||||||
(values
|
(version ,version)
|
||||||
`(package
|
(source ,source)
|
||||||
(name ,(ocaml-name->guix-name name))
|
(build-system ,(if use-dune?
|
||||||
(version ,version)
|
'dune-build-system
|
||||||
(source
|
'ocaml-build-system))
|
||||||
(origin
|
,@(if (null? inputs)
|
||||||
(method url-fetch)
|
'()
|
||||||
(uri ,source-url)
|
`((propagated-inputs (list ,@inputs))))
|
||||||
(sha256 (base32 ,(guix-hash-url temp)))))
|
,@(if (null? native-inputs)
|
||||||
(build-system ,(if use-dune?
|
'()
|
||||||
'dune-build-system
|
`((native-inputs (list ,@native-inputs))))
|
||||||
'ocaml-build-system))
|
,@(if (equal? name (guix-name->opam-name (ocaml-name->guix-name name)))
|
||||||
,@(if (null? inputs)
|
'()
|
||||||
'()
|
`((properties
|
||||||
`((propagated-inputs (list ,@inputs))))
|
,(list 'quasiquote `((upstream-name . ,name))))))
|
||||||
,@(if (null? native-inputs)
|
(home-page ,(metadata-ref opam-content "homepage"))
|
||||||
'()
|
(synopsis ,(metadata-ref opam-content "synopsis"))
|
||||||
`((native-inputs (list ,@native-inputs))))
|
(description ,(beautify-description
|
||||||
,@(if (equal? name (guix-name->opam-name (ocaml-name->guix-name name)))
|
(metadata-ref opam-content "description")))
|
||||||
'()
|
(license ,(spdx-string->license
|
||||||
`((properties
|
(metadata-ref opam-content "license"))))
|
||||||
,(list 'quasiquote `((upstream-name . ,name))))))
|
(filter
|
||||||
(home-page ,(metadata-ref opam-content "homepage"))
|
(lambda (name)
|
||||||
(synopsis ,(metadata-ref opam-content "synopsis"))
|
(not (member name '("dune" "jbuilder"))))
|
||||||
(description ,(beautify-description
|
dependencies)))))
|
||||||
(metadata-ref opam-content "description")))
|
|
||||||
(license ,(spdx-string->license
|
|
||||||
(metadata-ref opam-content "license"))))
|
|
||||||
(filter
|
|
||||||
(lambda (name)
|
|
||||||
(not (member name '("dune" "jbuilder"))))
|
|
||||||
dependencies))))))))
|
|
||||||
|
|
||||||
(define* (opam-recursive-import package-name #:key repo)
|
(define* (opam-recursive-import package-name #:key repo)
|
||||||
(recursive-import package-name
|
(recursive-import package-name
|
||||||
|
|
Reference in a new issue