me
/
guix
Archived
1
0
Fork 0

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>
master
Julien Lepiller 2022-04-08 15:22:43 +02:00 committed by Ludovic Courtès
parent be7338d400
commit d59abc336d
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 43 additions and 38 deletions

View File

@ -324,6 +324,20 @@ path to the repository."
(filter-map get-opam-repository repositories-specs))
(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)
"Import OPAM package NAME from REPOSITORY (a directory name) or, if
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))
(version (assoc-ref opam-file "version"))
(opam-content (assoc-ref opam-file "metadata"))
(url-dict (metadata-ref opam-content "url"))
(source-url (or (metadata-ref url-dict "src")
(metadata-ref url-dict "archive")))
(source (opam->guix-source (metadata-ref opam-content "url")))
(requirements (metadata-ref opam-content "depends"))
(names (dependency-list->names requirements))
(dependencies (filter-dependencies names))
@ -348,18 +360,11 @@ or #f on failure."
(not (member name '("dune" "jbuilder"))))
native-dependencies))))
(let ((use-dune? (member "dune" names)))
(call-with-temporary-output-file
(lambda (temp port)
(and (url-fetch source-url temp)
(values
`(package
(name ,(ocaml-name->guix-name name))
(version ,version)
(source
(origin
(method url-fetch)
(uri ,source-url)
(sha256 (base32 ,(guix-hash-url temp)))))
(source ,source)
(build-system ,(if use-dune?
'dune-build-system
'ocaml-build-system))
@ -382,7 +387,7 @@ or #f on failure."
(filter
(lambda (name)
(not (member name '("dune" "jbuilder"))))
dependencies))))))))
dependencies)))))
(define* (opam-recursive-import package-name #:key repo)
(recursive-import package-name