From patchwork Fri Nov 19 01:16:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Julien Lepiller X-Patchwork-Id: 34629 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 AB79127BBE4; Fri, 19 Nov 2021 01:17:10 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 06B0827BBE3 for ; Fri, 19 Nov 2021 01:17:10 +0000 (GMT) Received: from localhost ([::1]:33192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnsWb-0008Tv-0N for patchwork@mira.cbaines.net; Thu, 18 Nov 2021 20:17:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnsWU-0008Tj-8d for guix-patches@gnu.org; Thu, 18 Nov 2021 20:17:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:54143) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mnsWT-0008H0-W9 for guix-patches@gnu.org; Thu, 18 Nov 2021 20:17:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mnsWT-00058h-Oh for guix-patches@gnu.org; Thu, 18 Nov 2021 20:17:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51091] [PATCH v3] guix: opam: Do not fail when refreshing. Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 19 Nov 2021 01:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51091 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?utf-8?q?Court=C3=A8s?= Cc: 51091@debbugs.gnu.org, Xinglu Chen Received: via spool by 51091-submit@debbugs.gnu.org id=B51091.163728461919745 (code B ref 51091); Fri, 19 Nov 2021 01:17:01 +0000 Received: (at 51091) by debbugs.gnu.org; 19 Nov 2021 01:16:59 +0000 Received: from localhost ([127.0.0.1]:37456 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mnsWR-00058O-1U for submit@debbugs.gnu.org; Thu, 18 Nov 2021 20:16:59 -0500 Received: from lepiller.eu ([89.234.186.109]:39228) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mnsWO-00058F-Lw for 51091@debbugs.gnu.org; Thu, 18 Nov 2021 20:16:58 -0500 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id 88bcd8df; Fri, 19 Nov 2021 01:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from :to:cc:subject:message-id:in-reply-to:references:mime-version :content-type; s=dkim; bh=XIysXKGC2J47Mb/oakq0yRTr+rnZVNnPdqMr0H n7jis=; b=Ye8R388KqbBXe3XKSKKB4IXouFsa3W9Jsz+g75k0zkCPO5QMFl/Toy aB+Rhb3w/ImDVTpWMHrp7JknI1FyO1mIA9CJ0QFc1+7CLTzulGbKPygqd37Y8Ozo FZ11VwIDBAQmlWtXgvzIxDAuT+JRx00Y1C1KeURTvfRdtlAGD6JhQwWxiw66maD2 OQTpQ7cSagHmUw537PsLQAepI9FNy2eQ0hKfo/xiPjx2KT3vi+Br6x6Mm4Lwgxkk L9ifHtemeHXaLT1j9igRWUqrkH+rsXeV7sk50IsLz2Rn9szFipPlL2uaswMFrlUV oh9O2HRYzBU/9F4YaNUd8Fn50Km9lzdA== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id d9fd23e1 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Fri, 19 Nov 2021 01:16:54 +0000 (UTC) Date: Fri, 19 Nov 2021 02:16:46 +0100 From: Julien Lepiller Message-ID: <20211119021646.03e85542@tachikoma.lepiller.eu> In-Reply-To: <87sfwybuc7.fsf@gnu.org> References: <20211008050310.407d6b23@tachikoma.lepiller.eu> <87y272lepg.fsf@yoctocell.xyz> <871r4nrc9t.fsf_-_@gnu.org> <20211016041009.5b4ddff0@tachikoma.lepiller.eu> <87sfwybuc7.fsf@gnu.org> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.24; x86_64-pc-linux-gnu) 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 Le Mon, 18 Oct 2021 10:39:04 +0200, Ludovic Courtès a écrit : > Hi! > > Julien Lepiller skribis: > > > Thanks for the reviews! I've managed to use conditions, which was > > not easy because I didn't notice there was already a "condition" > > defined, and that lead to weird error messages. Attached is the > > updated patch. > > Oh, I see. > > > From 0cadac6c3dabea8b986cd59d97c84beaf7a33325 Mon Sep 17 00:00:00 > > 2001 Message-Id: > > <0cadac6c3dabea8b986cd59d97c84beaf7a33325.1634350078.git.julien@lepiller.eu> > > From: Julien Lepiller Date: Fri, 8 Oct 2021 > > 04:58:27 +0200 Subject: [PATCH] import: opam: Do not fail when > > refreshing. > > > > Because we throw an error when a package is not in the opam > > repository, the updater would crash when encountering a package > > that is not in opam but uses the ocaml-build-system, such as opam > > itself. This catches the error and continues without updating said > > package, and lets us update the rest of the packages. > > > > * guix/scripts/import/opam.scm (guix-import-opam): Catch not-found > > condition and leave. > > * guix/import/opam.scm (&opam-not-found-error): New condition type. > > (opam-fetch): Raise condition instead of leaving. > > (latest-release): Catch not-found condition and warn. > > (conditional): Rename from `condition'. > > * tests/opam.scm (parse-conditions): Change accordingly. > > LGTM, thanks! > > Ludo’. I forgot to remove the catch #t around the whole body of the function. I noticed that guard* was raising &non-continuable so I tried to fix it by using raise-continuable from (ice-9 exceptions). Is this the correct solution? From a60e2ca645f4f8a6da72111d047f8cbb41ebe3e6 Mon Sep 17 00:00:00 2001 Message-Id: From: Julien Lepiller Date: Fri, 8 Oct 2021 04:58:27 +0200 Subject: [PATCH] import: opam: Do not fail when refreshing. Because we throw an error when a package is not in the opam repository, the updater would crash when encountering a package that is not in opam but uses the ocaml-build-system, such as opam itself. This catches the error and continues without updating said package, and lets us update the rest of the packages. * guix/scripts/import/opam.scm (guix-import-opam): Catch not-found condition and leave. * guix/import/opam.scm (&opam-not-found-error): New condition type. (opam-fetch): Raise condition instead of leaving. (latest-release): Catch not-found condition and warn. (conditional): Rename from `condition'. * tests/opam.scm (parse-conditions): Change accordingly. --- guix/import/opam.scm | 23 ++++++++++++++++++----- guix/scripts/import/opam.scm | 31 +++++++++++++++++-------------- tests/opam.scm | 2 +- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/guix/import/opam.scm b/guix/import/opam.scm index fe13d29f03..aeeab541c1 100644 --- a/guix/import/opam.scm +++ b/guix/import/opam.scm @@ -20,6 +20,7 @@ ;;; along with GNU Guix. If not, see . (define-module (guix import opam) + #:use-module (ice-9 exceptions) #:use-module (ice-9 ftw) #:use-module (ice-9 match) #:use-module (ice-9 peg) @@ -30,6 +31,8 @@ (define-module (guix import opam) #:use-module (srfi srfi-1) #:use-module (srfi srfi-2) #:use-module ((srfi srfi-26) #:select (cut)) + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) #: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-system) @@ -47,12 +50,16 @@ (define-module (guix import opam) opam-recursive-import %opam-updater + &opam-not-found-error + opam-not-found-error? + opam-not-found-error-package + ;; The following patterns are exported for testing purposes. string-pat multiline-string list-pat dict - condition)) + conditional)) ;; Define a PEG parser for the opam format (define-peg-pattern comment none (and "#" (* COMMCHR) "\n")) @@ -85,7 +92,7 @@ (define-peg-pattern group-pat all (and (or conditional-value ground-value) (* SP) (ignore "&") (* SP) (or group-pat conditional-value ground-value))) (define-peg-pattern ground-value body (and (or multiline-string string-pat choice-pat list-pat var) (* SP))) -(define-peg-pattern conditional-value all (and ground-value (* SP) condition)) +(define-peg-pattern conditional-value all (and ground-value (* SP) conditional)) (define-peg-pattern string-pat all (and QUOTE (* STRCHR) QUOTE)) (define-peg-pattern list-pat all (and (ignore "[") (* SP) (* (and value (* SP))) (ignore "]"))) (define-peg-pattern var all (+ (or (range #\a #\z) "-"))) @@ -96,7 +103,7 @@ (define-peg-pattern multiline-string all QUOTE QUOTE QUOTE)) (define-peg-pattern dict all (and (ignore "{") (* SP) records (* SP) (ignore "}"))) -(define-peg-pattern condition body (and (ignore "{") condition-form (ignore "}"))) +(define-peg-pattern conditional body (and (ignore "{") condition-form (ignore "}"))) (define-peg-pattern condition-form body (and @@ -310,6 +317,10 @@ (define (dependency-list->inputs lst) (list dependency (list 'unquote (string->symbol dependency)))) (ocaml-names->guix-names lst))) +(define-condition-type &opam-not-found-error &error + opam-not-found-error? + (package opam-not-found-error-package)) + (define* (opam-fetch name #:optional (repositories-specs '("opam"))) (or (fold (lambda (repository others) (match (find-latest-version name repository) @@ -318,7 +329,7 @@ (define* (opam-fetch name #:optional (repositories-specs '("opam"))) (_ others))) #f (filter-map get-opam-repository repositories-specs)) - (leave (G_ "package '~a' not found~%") name))) + (raise-continuable (condition (&opam-not-found-error (package name)))))) (define* (opam->guix-package name #:key (repo '()) version) "Import OPAM package NAME from REPOSITORIES (a list of names, URLs or local @@ -410,7 +421,9 @@ (define (opam-package? package) (define (latest-release package) "Return an for the latest release of PACKAGE." (and-let* ((opam-name (guix-package->opam-name package)) - (opam-file (opam-fetch opam-name)) + (opam-file (guard* (c ((opam-not-found-error? c) + #f)) + (opam-fetch opam-name))) (version (assoc-ref opam-file "version")) (opam-content (assoc-ref opam-file "metadata")) (url-dict (metadata-ref opam-content "url")) diff --git a/guix/scripts/import/opam.scm b/guix/scripts/import/opam.scm index 834ac34cb0..043d05d717 100644 --- a/guix/scripts/import/opam.scm +++ b/guix/scripts/import/opam.scm @@ -93,20 +93,23 @@ (define (guix-import-opam . args) (reverse opts)))) (match args ((package-name) - (if (assoc-ref opts 'recursive) - ;; Recursive import - (map (match-lambda - ((and ('package ('name name) . rest) pkg) - `(define-public ,(string->symbol name) - ,pkg)) - (_ #f)) - (opam-recursive-import package-name #:repo repo)) - ;; Single import - (let ((sexp (opam->guix-package package-name #:repo repo))) - (unless sexp - (leave (G_ "failed to download meta-data for package '~a'~%") - package-name)) - sexp))) + (guard* (c ((opam-not-found-error? c) + (leave (G_ "package '~a' not found~%") + (opam-not-found-error-package c)))) + (if (assoc-ref opts 'recursive) + ;; Recursive import + (map (match-lambda + ((and ('package ('name name) . rest) pkg) + `(define-public ,(string->symbol name) + ,pkg)) + (_ #f)) + (opam-recursive-import package-name #:repo repo)) + ;; Single import + (let ((sexp (opam->guix-package package-name #:repo repo))) + (unless sexp + (leave (G_ "failed to download meta-data for package '~a'~%") + package-name)) + sexp)))) (() (leave (G_ "too few arguments~%"))) ((many ...) diff --git a/tests/opam.scm b/tests/opam.scm index 31b4ea41ff..96b748bcd9 100644 --- a/tests/opam.scm +++ b/tests/opam.scm @@ -171,7 +171,7 @@ (define (test-opam-syntax name pattern test-cases) ("{a: \"b\"\nc: \"d\"}" . (dict (record "a" (string-pat "b")) (record "c" (string-pat "d")))))) (test-opam-syntax - "parse-conditions" condition + "parse-conditions" conditional '(("" . #f) ("{}" . #f) ("{build}" . (condition-var "build")) -- 2.33.1