From patchwork Sun Jun 12 06:31:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Lepiller X-Patchwork-Id: 39883 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id BEDC327BBEA; Sun, 12 Jun 2022 07:32:38 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3A79327BBE9 for ; Sun, 12 Jun 2022 07:32:38 +0100 (BST) Received: from localhost ([::1]:41832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0H9J-0003ot-C8 for patchwork@mira.cbaines.net; Sun, 12 Jun 2022 02:32:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0H8k-0003oj-7f for guix-patches@gnu.org; Sun, 12 Jun 2022 02:32:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:60571) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o0H8j-0002nz-VA for guix-patches@gnu.org; Sun, 12 Jun 2022 02:32:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o0H8j-0001Gq-Sq for guix-patches@gnu.org; Sun, 12 Jun 2022 02:32:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#53828] [PATCH v2] import: opam: Allow importing local files. References: <20220206224130.2220aae9@tachikoma.lepiller.eu> In-Reply-To: <20220206224130.2220aae9@tachikoma.lepiller.eu> Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 12 Jun 2022 06:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53828 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 53828@debbugs.gnu.org Received: via spool by 53828-submit@debbugs.gnu.org id=B53828.16550155024843 (code B ref 53828); Sun, 12 Jun 2022 06:32:01 +0000 Received: (at 53828) by debbugs.gnu.org; 12 Jun 2022 06:31:42 +0000 Received: from localhost ([127.0.0.1]:54465 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o0H8I-0001Fm-0S for submit@debbugs.gnu.org; Sun, 12 Jun 2022 02:31:41 -0400 Received: from lepiller.eu ([89.234.186.109]:40018) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o0H8G-0001Fc-00 for 53828@debbugs.gnu.org; Sun, 12 Jun 2022 02:31:33 -0400 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id 497d16a0 for <53828@debbugs.gnu.org>; Sun, 12 Jun 2022 06:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=from:to :subject:date:message-id:mime-version:content-transfer-encoding; s=dkim; bh=fYPzzNqWsNZfjWY2zqpk5ZcCRk0VO6Z0/vjA3vWQjd4=; b=Sjw9 ofaXimmDP84eaXGNWV9Piw0OCFCUDulooVWbyX7ka4dilBIMin0WKMTvHJTN2UsQ aHcZmbqEPDMCfOYqzSc4acFsg1orYJfkNFPKB2d3nqf7L3fBuuOBRYHvNjrMLTag 3wIlNKaSXtwukiYI/c6uhTL+BmmPVWbG8F9m0s4XFWqx9aTpoR9aPMq0JEE4Gp4V mh5cF0OS8y+KUpnKMPmIfPdOAS3w+10GO4SaG9RSZROmKxTWmg+7dF0y6J+Gi2L3 dcC3SOD34eX4eBp5I6SiuwGBxxzipP2fcRNj6J6s9Dw4rKSmRornt7xkLaIcxjR2 wOJoNLEAgSy3qCaNNA== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id def212aa (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for <53828@debbugs.gnu.org>; Sun, 12 Jun 2022 06:31:28 +0000 (UTC) From: Julien Lepiller Date: Sun, 12 Jun 2022 08:31:21 +0200 Message-Id: <20220612063121.26914-1-julien@lepiller.eu> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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)) @@ -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)