From patchwork Mon Nov 16 19:07:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hartmut Goebel X-Patchwork-Id: 25165 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 78B3E27BBF6; Mon, 16 Nov 2020 19:31:46 +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.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable 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 A593527BBF5 for ; Mon, 16 Nov 2020 19:31:45 +0000 (GMT) Received: from localhost ([::1]:51430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kekE4-0006Nd-NB for patchwork@mira.cbaines.net; Mon, 16 Nov 2020 14:31:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kejrD-0001xl-Il for guix-patches@gnu.org; Mon, 16 Nov 2020 14:08:07 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:45727) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kejrB-0001FZ-L9 for guix-patches@gnu.org; Mon, 16 Nov 2020 14:08:07 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kejrB-0002tH-Gi for guix-patches@gnu.org; Mon, 16 Nov 2020 14:08:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#38408] [PATCH v17 7/8] import: crate: Trim version for names after left-most non-zero part. Resent-From: Hartmut Goebel Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 16 Nov 2020 19:08:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38408 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 38408@debbugs.gnu.org Received: via spool by 38408-submit@debbugs.gnu.org id=B38408.160555368011030 (code B ref 38408); Mon, 16 Nov 2020 19:08:05 +0000 Received: (at 38408) by debbugs.gnu.org; 16 Nov 2020 19:08:00 +0000 Received: from localhost ([127.0.0.1]:57261 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kejr6-0002rp-G4 for submit@debbugs.gnu.org; Mon, 16 Nov 2020 14:08:00 -0500 Received: from mail-out.m-online.net ([212.18.0.9]:57527) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kejr4-0002rh-Hb for 38408@debbugs.gnu.org; Mon, 16 Nov 2020 14:07:59 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4CZdrG0rDTz1qs3l for <38408@debbugs.gnu.org>; Mon, 16 Nov 2020 20:07:58 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4CZdrG0lwGz1qqkX for <38408@debbugs.gnu.org>; Mon, 16 Nov 2020 20:07:58 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id SVQJn9IQWF2K for <38408@debbugs.gnu.org>; Mon, 16 Nov 2020 20:07:56 +0100 (CET) Received: from hermia.goebel-consult.de (ppp-188-174-59-253.dynamic.mnet-online.de [188.174.59.253]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS for <38408@debbugs.gnu.org>; Mon, 16 Nov 2020 20:07:56 +0100 (CET) Received: from thisbe.fritz.box (thisbe.fritz.box [192.168.110.24]) by hermia.goebel-consult.de (Postfix) with ESMTP id D34E4604D9; Mon, 16 Nov 2020 20:08:28 +0100 (CET) From: Hartmut Goebel Date: Mon, 16 Nov 2020 20:07:27 +0100 Message-Id: <2e2f414b859139f6f41d7106b3fbcd6ae5d17649.1605552418.git.h.goebel@crazy-compilers.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: References: 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 This complies to how versions are matched for caret requirements in crates: An update is allowed if the new version number does not modify the left-most non-zero digit in the major, minor, patch grouping. * guix/import/crate.scm (version->semver-prefix): New function. (make-crate-sexp)[format-inputs]: Use it. (make-crate-sexp): Use it to pass shorter version to package->definition. * guix/import/utils.scm (package->definition): Change optional parameter APPEND-VERSION? into APPEND-VERSION?/STRING. If it is a string, append its value to name. * tests/crate.scm: Adjust tests accordingly. --- guix/import/crate.scm | 10 ++++++++-- guix/import/utils.scm | 13 +++++++++---- tests/crate.scm | 25 ++++++++++++------------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/guix/import/crate.scm b/guix/import/crate.scm index 20efa131d5..b133529ba7 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -150,6 +150,12 @@ record or #f if it was not found." ((args ...) `((arguments (,'quasiquote ,args)))))) +(define (version->semver-prefix version) + "Return the version up to and including the first non-zero part" + (first + (map match:substring + (list-matches "^(0+\\.){,2}[0-9]+" version)))) + (define* (make-crate-sexp #:key name version cargo-inputs cargo-development-inputs home-page synopsis description license build?) "Return the `package' s-expression for a rust package with the given NAME, @@ -160,7 +166,7 @@ and LICENSE." (match-lambda ((name version) (list (crate-name->package-name name) - (version-major+minor version)))) + (version->semver-prefix version)))) inputs)) (let* ((port (http-fetch (crate-uri name version))) @@ -194,7 +200,7 @@ and LICENSE." ((license) license) (_ `(list ,@license))))))) (close-port port) - (package->definition pkg #t))) + (package->definition pkg (version->semver-prefix version)))) (define (string->license string) (filter-map (lambda (license) diff --git a/guix/import/utils.scm b/guix/import/utils.scm index b74393e617..7de95349cd 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -263,16 +263,21 @@ package definition." ((package-inputs ...) `((native-inputs (,'quasiquote ,package-inputs)))))) -(define* (package->definition guix-package #:optional append-version?) +(define* (package->definition guix-package #:optional append-version?/string) + "If APPEND-VERSION?/STRING is #t, append the package's major+minor +version. If APPEND-VERSION?/string is a string, append this string." (match guix-package ((or ('package ('name name) ('version version) . rest) ('let _ ('package ('name name) ('version version) . rest))) `(define-public ,(string->symbol - (if append-version? - (string-append name "-" (version-major+minor version)) - version)) + (cond + ((string? append-version?/string) + (string-append name "-" append-version?/string)) + ((= append-version?/string #t) + (string-append name "-" (version-major+minor version))) + ((#t) version))) ,guix-package)))) (define (build-system-modules) diff --git a/tests/crate.scm b/tests/crate.scm index 3fbf6762c5..1506daeadd 100644 --- a/tests/crate.scm +++ b/tests/crate.scm @@ -352,7 +352,7 @@ (_ (error "Unexpected URL: " url))))) (match (crate->guix-package "foo") - ((define-public 'rust-foo-1.0 + ((define-public 'rust-foo-1 (package (name "rust-foo") (version "1.0.3") (source @@ -368,8 +368,7 @@ ('quasiquote (#:skip-build? #t #:cargo-inputs - (("rust-leaf-alice" - ('unquote 'rust-leaf-alice-0.7)))))) + (("rust-leaf-alice" ('unquote 'rust-leaf-alice-0.7)))))) (home-page "http://example.com") (synopsis "summary") (description "summary") @@ -452,7 +451,7 @@ (synopsis "summary") (description "summary") (license (list license:expat license:asl2.0)))) - (define-public 'rust-leaf-bob-3.0 + (define-public 'rust-leaf-bob-3 (package (name "rust-leaf-bob") (version "3.0.1") @@ -471,7 +470,7 @@ (synopsis "summary") (description "summary") (license (list license:expat license:asl2.0)))) - (define-public 'rust-intermediate-b-1.2 + (define-public 'rust-intermediate-b-1 (package (name "rust-intermediate-b") (version "1.2.3") @@ -489,12 +488,12 @@ ('quasiquote (#:skip-build? #t #:cargo-inputs (("rust-leaf-bob" - ('unquote 'rust-leaf-bob-3.0)))))) + ('unquote rust-leaf-bob-3)))))) (home-page "http://example.com") (synopsis "summary") (description "summary") (license (list license:expat license:asl2.0)))) - (define-public 'rust-intermediate-a-1.0 + (define-public 'rust-intermediate-a-1 (package (name "rust-intermediate-a") (version "1.0.42") @@ -512,16 +511,16 @@ ('quasiquote (#:skip-build? #t #:cargo-inputs (("rust-intermediate-b" - ('unquote 'rust-intermediate-b-1.2)) + ('unquote rust-intermediate-b-1)) ("rust-leaf-alice" ('unquote 'rust-leaf-alice-0.7)) ("rust-leaf-bob" - ('unquote 'rust-leaf-bob-3.0)))))) + ('unquote rust-leaf-bob-3)))))) (home-page "http://example.com") (synopsis "summary") (description "summary") (license (list license:expat license:asl2.0)))) - (define-public 'rust-root-1.0 + (define-public 'rust-root-1 (package (name "rust-root") (version "1.0.4") @@ -538,13 +537,13 @@ (arguments ('quasiquote (#:cargo-inputs (("rust-intermediate-a" - ('unquote 'rust-intermediate-a-1.0)) + ('unquote rust-intermediate-a-1)) ("rust-intermediate-b" - ('unquote 'rust-intermediate-b-1.2)) + ('unquote rust-intermediate-b-1)) ("rust-leaf-alice" ('unquote 'rust-leaf-alice-0.7)) ("rust-leaf-bob" - ('unquote 'rust-leaf-bob-3.0)))))) + ('unquote rust-leaf-bob-3)))))) (home-page "http://example.com") (synopsis "summary") (description "summary")