all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Julien Lepiller <julien@lepiller.eu>
To: 53828@debbugs.gnu.org
Subject: [bug#53828] [PATCH v2] import: opam: Allow importing local files.
Date: Sun, 12 Jun 2022 08:31:21 +0200	[thread overview]
Message-ID: <20220612063121.26914-1-julien@lepiller.eu> (raw)
In-Reply-To: <20220206224130.2220aae9@tachikoma.lepiller.eu>

* guix/scripts/import/opam.scm (guix-import-opam): Support `--scan-project` flag.
* guix/import/opam.scm (opam-scan-projects): New procedure.
---
 guix/import/opam.scm         | 32 ++++++++++++++++++++++++++++++--
 guix/scripts/import/opam.scm | 11 +++++++++++
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/guix/import/opam.scm b/guix/import/opam.scm
index b4b5a6eaad..3989dff58e 100644
--- a/guix/import/opam.scm
+++ b/guix/import/opam.scm
@@ -32,9 +32,11 @@ (define-module (guix import opam)
   #:use-module (srfi srfi-2)
   #:use-module ((srfi srfi-26) #:select (cut))
   #:use-module ((web uri) #:select (string->uri uri->string))
-  #:use-module ((guix build utils) #:select (dump-port find-files mkdir-p))
+  #:use-module ((guix build utils) #:select (dump-port find-files mkdir-p
+                                             delete-file-recursively))
   #:use-module (guix build-system)
   #:use-module (guix build-system ocaml)
+  #:use-module (guix git)
   #:use-module (guix http-client)
   #:use-module (guix ui)
   #:use-module (guix packages)
@@ -48,7 +50,8 @@ (define-module (guix import opam)
                                               spdx-string->license
                                               url-fetch))
   #:use-module ((guix licenses) #:prefix license:)
-  #:export (opam->guix-package
+  #:export (opam-scan-projects
+            opam->guix-package
             opam-recursive-import
             %opam-updater
 
@@ -178,6 +181,31 @@ (define* (get-opam-repository #:optional (repo "opam"))
 ;; Prevent Guile 3 from inlining this procedure so we can mock it in tests.
 (set! get-opam-repository get-opam-repository)
 
+(define (opam-scan-dir dir)
+  (let* ((opam-files (find-files dir "\\.opam$"))
+         (dir (opam-cache-directory dir))
+         (packages (string-append dir "/packages")))
+    (when (file-exists? dir)
+      (delete-file-recursively dir))
+    (mkdir-p packages)
+    (for-each
+      (lambda (package)
+        (let* ((name (basename package ".opam"))
+               (version (metadata-ref (get-metadata package) "version"))
+               (file (string-append packages "/" name "." version "/opam")))
+          (mkdir-p (dirname file))
+          (copy-file package file)))
+      opam-files)
+    dir))
+
+(define (opam-scan-project project)
+  (if (file-exists? project)
+    (opam-scan-dir project)
+    (opam-scan-dir (update-cached-checkout project))))
+
+(define (opam-scan-projects projects)
+  (map opam-scan-project projects))
+
 (define (get-version-and-file path)
   "Analyse a candidate path and return an list containing information for proper
   version comparison as well as the source path for metadata."
diff --git a/guix/scripts/import/opam.scm b/guix/scripts/import/opam.scm
index 834ac34cb0..0b15a81541 100644
--- a/guix/scripts/import/opam.scm
+++ b/guix/scripts/import/opam.scm
@@ -50,6 +50,10 @@ (define (show-help)
       --repo             import packages from this opam repository (name, URL or local path)
                          can be used more than once"))
   (display (G_ "
+  -p, --scan-project     import packages from this OCaml project (URL of a
+                         Git repository or local path).  Can be used more
+                         than once."))
+  (display (G_ "
   -V, --version          display version information and exit"))
   (newline)
   (show-bug-report-information))
@@ -69,6 +73,9 @@ (define %options
          (option '(#\r "recursive") #f #f
                  (lambda (opt name arg result)
                    (alist-cons 'recursive #t result)))
+         (option '(#\p "scan-project") #t #f
+                 (lambda (opt name arg result)
+                   (alist-cons 'project arg result)))
          %standard-import-options))
 
 \f
@@ -86,6 +93,10 @@ (define (parse-options)
          (repo (filter-map (match-lambda
                              (('repo . name) name)
                              (_ #f)) opts))
+         (projects (filter-map (match-lambda
+                                 (('project . name) name)
+                                 (_ #f)) opts))
+         (repo (append repo (opam-scan-projects projects)))
          (args (filter-map (match-lambda
                             (('argument . value)
                              value)
-- 
2.35.1





  parent reply	other threads:[~2022-06-12  6:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-06 21:41 [bug#53828] [PATCH] guix: opam: Allow importing local files Julien Lepiller
2022-02-06 21:58 ` Maxime Devos
2022-02-07  8:27 ` Xinglu Chen
2022-02-07  8:46   ` Julien Lepiller
2022-02-09 13:34     ` Xinglu Chen
2022-06-12  6:31 ` Julien Lepiller [this message]
2022-06-12  6:37   ` [bug#53828] [PATCH v2] import: " 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=20220612063121.26914-1-julien@lepiller.eu \
    --to=julien@lepiller.eu \
    --cc=53828@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.