diff options
author | Julien Lepiller <julien@lepiller.eu> | 2022-04-08 15:22:43 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2022-04-11 11:55:58 +0200 |
commit | d59abc336d4cd15675d6be2ecdace8f427fee28e (patch) | |
tree | 562d98ff9ebcfa072ad85fc442990415407de0d7 | |
parent | be7338d4000dece2a4a4c19b414c71b7206799eb (diff) | |
download | guix-d59abc336d4cd15675d6be2ecdace8f427fee28e.tar.gz |
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>
-rw-r--r-- | guix/import/opam.scm | 81 |
1 files changed, 43 insertions, 38 deletions
diff --git a/guix/import/opam.scm b/guix/import/opam.scm index f51d17dea4..b4b5a6eaad 100644 --- a/guix/import/opam.scm +++ b/guix/import/opam.scm @@ -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,41 +360,34 @@ 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))))) - (build-system ,(if use-dune? - 'dune-build-system - 'ocaml-build-system)) - ,@(if (null? inputs) - '() - `((propagated-inputs (list ,@inputs)))) - ,@(if (null? native-inputs) - '() - `((native-inputs (list ,@native-inputs)))) - ,@(if (equal? name (guix-name->opam-name (ocaml-name->guix-name name))) - '() - `((properties - ,(list 'quasiquote `((upstream-name . ,name)))))) - (home-page ,(metadata-ref opam-content "homepage")) - (synopsis ,(metadata-ref opam-content "synopsis")) - (description ,(beautify-description - (metadata-ref opam-content "description"))) - (license ,(spdx-string->license - (metadata-ref opam-content "license")))) - (filter - (lambda (name) - (not (member name '("dune" "jbuilder")))) - dependencies)))))))) + (values + `(package + (name ,(ocaml-name->guix-name name)) + (version ,version) + (source ,source) + (build-system ,(if use-dune? + 'dune-build-system + 'ocaml-build-system)) + ,@(if (null? inputs) + '() + `((propagated-inputs (list ,@inputs)))) + ,@(if (null? native-inputs) + '() + `((native-inputs (list ,@native-inputs)))) + ,@(if (equal? name (guix-name->opam-name (ocaml-name->guix-name name))) + '() + `((properties + ,(list 'quasiquote `((upstream-name . ,name)))))) + (home-page ,(metadata-ref opam-content "homepage")) + (synopsis ,(metadata-ref opam-content "synopsis")) + (description ,(beautify-description + (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) (recursive-import package-name |