From patchwork Mon Mar 14 21:51:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 37796 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 6727D27BBEA; Mon, 14 Mar 2022 21:53:34 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, 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 8E04D27BBEB for ; Mon, 14 Mar 2022 21:53:32 +0000 (GMT) Received: from localhost ([::1]:59998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nTsd9-00057v-MQ for patchwork@mira.cbaines.net; Mon, 14 Mar 2022 17:53:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTscf-00055N-VL for guix-patches@gnu.org; Mon, 14 Mar 2022 17:53:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:52758) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nTscf-0001NN-Mk for guix-patches@gnu.org; Mon, 14 Mar 2022 17:53:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nTscf-00036e-Lk for guix-patches@gnu.org; Mon, 14 Mar 2022 17:53:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54393] [PATCH 1/2] packages: Add 'package-unique-version-prefix'. References: <20220314215015.24435-1-ludo@gnu.org> In-Reply-To: <20220314215015.24435-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 14 Mar 2022 21:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54393 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54393@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 54393-submit@debbugs.gnu.org id=B54393.164729472311849 (code B ref 54393); Mon, 14 Mar 2022 21:53:01 +0000 Received: (at 54393) by debbugs.gnu.org; 14 Mar 2022 21:52:03 +0000 Received: from localhost ([127.0.0.1]:46653 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nTsbi-00034t-HQ for submit@debbugs.gnu.org; Mon, 14 Mar 2022 17:52:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47878) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nTsbg-00034L-Ec for 54393@debbugs.gnu.org; Mon, 14 Mar 2022 17:52:00 -0400 Received: from [2001:470:142:3::e] (port=52430 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTsbb-000196-4l; Mon, 14 Mar 2022 17:51:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=VbmHdSNoON7ONn6RYGDw0+W9fSMQBHI6apFbj3QU7UM=; b=isxgfvCFXzIDLa mKGqrbFZA1uBR5iPQZ6oYO+ybbiyhdxEp18YtHUfquJ80hocYvTiUJz1kVXnFVvcD0aOM+LnDFiBV kuRUbhHWG0lgsuNcZtt1J+BecedDzLiLzI/m4pbQNeb4LXuHoF7X3O1nUA0FuW0rzS+aAcWAMEKze +dxATUjVxKQfYWo2CxDHEiaa3V9xIDK7Y13s2BzZYsY8m+jNpeg4YPiiH17Qww/jvi4Fv+GPkqn6G q8eTw+VZVtGLIbA2NveJ3tGfreBSYFmIBA5T4LclBxkEeTLfoV7izxH2ZjA/TEjSbMZnuH2+2OPYi lfUqGQ4VDOt+q61gl1zQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:62373 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nTsba-00006I-Oh; Mon, 14 Mar 2022 17:51:54 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 14 Mar 2022 22:51:45 +0100 Message-Id: <20220314215146.24490-1-ludo@gnu.org> X-Mailer: git-send-email 2.34.0 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 * gnu/packages.scm (package-unique-version-prefix): New procedure. * guix/scripts/package.scm (manifest-entry-version-prefix): Use it. * tests/packages.scm ("package-unique-version-prefix, gcc@8") ("package-unique-version-prefix, grep"): New tests. --- gnu/packages.scm | 21 +++++++++++++++++++++ guix/scripts/package.scm | 20 ++------------------ tests/packages.scm | 13 +++++++++++++ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/gnu/packages.scm b/gnu/packages.scm index 65ab7a7c1e..2ba838fd0a 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -66,6 +66,8 @@ (define-module (gnu packages) specification->location specifications->manifest + package-unique-version-prefix + generate-package-cache)) ;;; Commentary: @@ -559,3 +561,22 @@ (define (specifications->manifest specs) ;; fiddle with multiple-value returns. (packages->manifest (map (compose list specification->package+output) specs))) + +(define (package-unique-version-prefix name version) + "Search among all the versions of package NAME that are available, and +return the shortest unambiguous version prefix to designate VERSION. If only +one version of the package is available, return the empty string." + (match (map package-version (find-packages-by-name name)) + ((_) + ;; A single version of NAME is available, so do not specify the version + ;; number, even if the available version doesn't match VERSION. + "") + (versions + ;; If VERSION is the latest version, don't specify any version. + ;; Otherwise return the shortest unique version prefix. Note that this + ;; is based on the currently available packages so the result may vary + ;; over time. + (if (every (cut version>? version <>) + (delete version versions)) + "" + (version-unique-prefix version versions))))) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 9699c70c6d..22ee8a2485 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -334,24 +334,8 @@ (define (manifest-entry-version-prefix entry) "Search among all the versions of ENTRY's package that are available, and return the shortest unambiguous version prefix for this package. If only one version of ENTRY's package is available, return the empty string." - (let ((name (manifest-entry-name entry))) - (match (map package-version (find-packages-by-name name)) - ((_) - ;; A single version of NAME is available, so do not specify the - ;; version number, even if the available version doesn't match ENTRY. - "") - (versions - ;; If ENTRY uses the latest version, don't specify any version. - ;; Otherwise return the shortest unique version prefix. Note that - ;; this is based on the currently available packages, which could - ;; differ from the packages available in the revision that was used - ;; to build MANIFEST. - (let ((current (manifest-entry-version entry))) - (if (every (cut version>? current <>) - (delete current versions)) - "" - (version-unique-prefix (manifest-entry-version entry) - versions))))))) + (package-unique-version-prefix (manifest-entry-name entry) + (manifest-entry-version entry))) (define* (export-manifest manifest #:optional (port (current-output-port))) diff --git a/tests/packages.scm b/tests/packages.scm index 02bdba5f98..b228c9fc3b 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -1923,6 +1923,19 @@ (define (list->set* lst) (package-location (specification->package "guile@2")) (specification->location "guile@2")) +(test-equal "package-unique-version-prefix, gcc@8" + "8" + (let ((gcc (specification->package "gcc-toolchain@8"))) + (package-unique-version-prefix (package-name gcc) + (package-version gcc)))) + +(test-equal "package-unique-version-prefix, grep" + "" + (let ((grep (specification->package "grep"))) + (package-unique-version-prefix (package-name grep) + (package-version grep)))) + + (test-eq "this-package-input, exists" hello (package-arguments