From: Julien Lepiller <julien@lepiller.eu>
To: 33811@debbugs.gnu.org
Subject: [bug#33811] [PATCH 3/5] import: opam: Add updater.
Date: Thu, 20 Dec 2018 12:01:01 +0100 [thread overview]
Message-ID: <20181220110103.4219-3-julien@lepiller.eu> (raw)
In-Reply-To: <20181220110103.4219-1-julien@lepiller.eu>
* guix/import/opam.scm (%opam-updater): New variable.
---
guix/import/opam.scm | 59 ++++++++++++++++++++++++++++++++++++++++----
1 file changed, 54 insertions(+), 5 deletions(-)
diff --git a/guix/import/opam.scm b/guix/import/opam.scm
index cdf05e7d2..b30d28561 100644
--- a/guix/import/opam.scm
+++ b/guix/import/opam.scm
@@ -27,14 +27,19 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-2)
#:use-module (web uri)
+ #:use-module (guix build-system)
+ #:use-module (guix build-system ocaml)
#:use-module (guix http-client)
#:use-module (guix git)
#:use-module (guix ui)
+ #:use-module (guix packages)
+ #:use-module (guix upstream)
#:use-module (guix utils)
#:use-module (guix import utils)
#:use-module ((guix licenses) #:prefix license:)
#:export (opam->guix-package
- opam-recursive-import))
+ opam-recursive-import
+ %opam-updater))
;; Define a PEG parser for the opam format
(define-peg-pattern SP none (or " " "\n"))
@@ -205,11 +210,17 @@ path to the repository."
(list dependency (list 'unquote (string->symbol dependency))))
(ocaml-names->guix-names lst)))
-(define (opam->guix-package name)
+(define (opam-fetch name)
(and-let* ((repository (get-opam-repository))
(version (find-latest-version name repository))
- (file (string-append repository "/packages/" name "/" name "." version "/opam"))
- (opam-content (get-metadata file))
+ (file (string-append repository "/packages/" name "/" name "." version "/opam")))
+ `(("metadata" ,@(get-metadata file))
+ ("version" . ,version))))
+
+(define (opam->guix-package name)
+ (and-let* ((opam-file (opam-fetch name))
+ (version (assoc-ref opam-file "version"))
+ (opam-content (assoc-ref opam-file "metadata"))
(url-dict (metadata-ref opam-content "url"))
(source-url (metadata-ref url-dict "src"))
(requirements (metadata-ref opam-content "depends"))
@@ -222,7 +233,7 @@ path to the repository."
(values
`(package
(name ,(ocaml-name->guix-name name))
- (version ,(metadata-ref opam-content "version"))
+ (version ,version)
(source
(origin
(method url-fetch)
@@ -246,3 +257,41 @@ path to the repository."
#:repo->guix-package (lambda (name repo)
(opam->guix-package name))
#:guix-name ocaml-name->guix-name))
+
+(define (guix-package->opam-name package)
+ "Given an OCaml PACKAGE built from OPAM, return the name of the
+package in OPAM."
+ (let ((upstream-name (assoc-ref
+ (package-properties package)
+ 'upstream-name))
+ (name (package-name package)))
+ (cond
+ (upstream-name upstream-name)
+ ((string-prefix? "ocaml-" name) (substring name 6))
+ (else name))))
+
+(define (opam-package? package)
+ "Return true if PACKAGE is an OCaml package from OPAM"
+ (and
+ (equal? (build-system-name (package-build-system package)) 'ocaml)
+ (not (string-prefix? "ocaml4" (package-name package)))))
+
+(define (latest-release package)
+ "Return an <upstream-source> for the latest release of PACKAGE."
+ (and-let* ((opam-name (guix-package->opam-name package))
+ (opam-file (opam-fetch opam-name))
+ (version (assoc-ref opam-file "version"))
+ (opam-content (assoc-ref opam-file "metadata"))
+ (url-dict (metadata-ref opam-content "url"))
+ (source-url (metadata-ref url-dict "src")))
+ (upstream-source
+ (package (package-name package))
+ (version version)
+ (urls (list source-url)))))
+
+(define %opam-updater
+ (upstream-updater
+ (name 'opam)
+ (description "Updater for OPAM packages")
+ (pred opam-package?)
+ (latest latest-release)))
--
2.19.2
next prev parent reply other threads:[~2018-12-20 11:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-20 10:41 [bug#33811] [PATCH] Opam importer improvements Julien Lepiller
2018-12-20 11:00 ` [bug#33811] [PATCH 1/5] gnu: Move coq packages from ocaml to coq Julien Lepiller
2018-12-20 11:01 ` [bug#33811] [PATCH 2/5] import: opam: Add recursive option Julien Lepiller
2018-12-20 11:01 ` Julien Lepiller [this message]
2018-12-20 11:01 ` [bug#33811] [PATCH 4/5] gnu: ocaml-graph: Add upstream-name Julien Lepiller
2018-12-20 11:01 ` [bug#33811] [PATCH 5/5] import: opam: Parse comments Julien Lepiller
2018-12-27 8:30 ` [bug#33811] [PATCH] Opam importer improvements Julien Lepiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181220110103.4219-3-julien@lepiller.eu \
--to=julien@lepiller.eu \
--cc=33811@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.