From patchwork Thu Mar 31 11:09:55 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: 38247 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 0844727BBEA; Thu, 31 Mar 2022 12:15:12 +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 7AC5F27BBE9 for ; Thu, 31 Mar 2022 12:15:11 +0100 (BST) Received: from localhost ([::1]:43302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZsli-0006bn-LI for patchwork@mira.cbaines.net; Thu, 31 Mar 2022 07:15:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZshi-0001e0-KB for guix-patches@gnu.org; Thu, 31 Mar 2022 07:11:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44129) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nZshi-0003UZ-AK for guix-patches@gnu.org; Thu, 31 Mar 2022 07:11:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nZshi-0002DX-3a for guix-patches@gnu.org; Thu, 31 Mar 2022 07:11:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54393] [PATCH v2 1/3] packages: Add 'package-unique-version-prefix'. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 31 Mar 2022 11:11:02 +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.16487250428395 (code B ref 54393); Thu, 31 Mar 2022 11:11:02 +0000 Received: (at 54393) by debbugs.gnu.org; 31 Mar 2022 11:10:42 +0000 Received: from localhost ([127.0.0.1]:38018 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nZshB-00029q-Pm for submit@debbugs.gnu.org; Thu, 31 Mar 2022 07:10:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48994) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nZsh9-00029W-Qn for 54393@debbugs.gnu.org; Thu, 31 Mar 2022 07:10:28 -0400 Received: from [2001:470:142:3::e] (port=54754 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 1nZsh0-0003As-Fc; Thu, 31 Mar 2022 07:10:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=UnX/f/npe2jrnWpzxE1xCApRW4evuVDDsHpuKcxiCog=; b=H1iYXogn4KfmVoKqshUA p7nUgEh/QfAC1qIaQMz45Iw0WJ8q2SXLCqk0voU7V0NBUMEp15bUIhCDAMwKUHaY3Mp2agD9K2+5c lNsSTQpq1u7U2rbXbajIE+k78sgdlfAr6rcYJD3GvsYHp3HyNFIfcXOBPofBoa2PeHQCCIoSM6mlP lsq6jPUC++Xm4Wad9kJgy4ShiA3OzXkuy/1oW7BJthebcqbGUaY8BkUX04y0LJIKfICZPRgM8XQhl t6TjGY4yoMOe9/EYvxG0SSsJ2aEyKBT50CeTNDBQ96rmXbWF1tixvoALqeEey4V5Dg4QCgTEe1vEg hwC3UJJ7ZazNVQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:61384 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 1nZsgu-0002dj-Lx; Thu, 31 Mar 2022 07:10:16 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 31 Mar 2022 13:09:55 +0200 Message-Id: <20220331110957.31829-1-ludo@gnu.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <87r173huph.fsf@gnu.org> References: <87r173huph.fsf@gnu.org> 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 710eace6dc..6cbc34ba0b 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 From patchwork Thu Mar 31 11:09:56 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: 38246 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 3B82D27BBEA; Thu, 31 Mar 2022 12:12:33 +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 0073327BBE9 for ; Thu, 31 Mar 2022 12:12:33 +0100 (BST) Received: from localhost ([::1]:37710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZsjA-0002nX-2U for patchwork@mira.cbaines.net; Thu, 31 Mar 2022 07:12:32 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZshj-0001fU-05 for guix-patches@gnu.org; Thu, 31 Mar 2022 07:11:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44130) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nZshi-0003Ue-MI for guix-patches@gnu.org; Thu, 31 Mar 2022 07:11:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nZshi-0002Df-GW for guix-patches@gnu.org; Thu, 31 Mar 2022 07:11:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54393] [PATCH v2 2/3] environment: Export 'load-manifest'. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 31 Mar 2022 11:11:02 +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.16487250438401 (code B ref 54393); Thu, 31 Mar 2022 11:11:02 +0000 Received: (at 54393) by debbugs.gnu.org; 31 Mar 2022 11:10:43 +0000 Received: from localhost ([127.0.0.1]:38022 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nZshO-0002BM-J2 for submit@debbugs.gnu.org; Thu, 31 Mar 2022 07:10:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48998) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nZsh9-00029X-Qu for 54393@debbugs.gnu.org; Thu, 31 Mar 2022 07:10:29 -0400 Received: from [2001:470:142:3::e] (port=54756 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 1nZsh1-0003Ax-2O; Thu, 31 Mar 2022 07:10:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=ftje0oZhs3dbyxdssEuCqh3SAJIOifxIjLCBnxr9k2M=; b=W8l0/GAq1xbVKiXa5DP0 ZLKBjnZ93jA1yLRBs7qH8EEybaeGlX8bFDrVEhb5hfTE2FPhbEpzoIXPBmLGVQTDEKWO6pHMOQpis yu39Xm6fCLA57XLR4XeQ6MU9sGhoaAh1+wswZJgpUFO6tdxYaFK4ky62ByxxedJ2V6rCg4rkx/fGj 1CrVoOBM436eNe4PAG5OouG1/c4QOzFE8LyMT46Txmz66nV/9D0PdNpxNRYDuV5r37Wp2b2ao8AZF ah0dAVQLXypwAZM6L6JnM+KlLoGozV5S59CJCuAFezB/9pyQ/CFOFKhk/1jEpcIn1gV7w+Q8b+YDn PFCX+vWG1ompzw==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:61384 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 1nZsh0-0002dj-Js; Thu, 31 Mar 2022 07:10:18 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 31 Mar 2022 13:09:56 +0200 Message-Id: <20220331110957.31829-2-ludo@gnu.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220331110957.31829-1-ludo@gnu.org> References: <87r173huph.fsf@gnu.org> <20220331110957.31829-1-ludo@gnu.org> 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/environment.scm (load-manifest): New procedure. (options/resolve-packages): Use it. --- guix/scripts/environment.scm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index ec071402f4..07b54cd89b 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -56,6 +56,7 @@ (define-module (guix scripts environment) #:use-module (srfi srfi-37) #:use-module (srfi srfi-98) #:export (assert-container-features + load-manifest guix-environment guix-environment* show-environment-options-help @@ -285,6 +286,11 @@ (define same-key? (cut eq? key <>)) (_ memo))) '() alist)) +(define (load-manifest file) ;TODO: factorize + "Load the user-profile manifest (Scheme code) from FILE and return it." + (let ((user-module (make-user-module '((guix profiles) (gnu))))) + (load* file user-module))) + (define (options/resolve-packages store opts) "Return OPTS with package specification strings replaced by manifest entries for the corresponding packages." @@ -331,8 +337,7 @@ (define (packages->outputs packages mode) (let ((module (make-user-module '()))) (packages->outputs (load* file module) mode))) (('manifest . file) - (let ((module (make-user-module '((guix profiles) (gnu))))) - (manifest-entries (load* file module)))) + (manifest-entries (load-manifest file))) (_ '())) opts) manifest-entry=?))) From patchwork Thu Mar 31 11:09:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 38248 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 A965F27BBEA; Thu, 31 Mar 2022 12:16:13 +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 B5DD627BBE9 for ; Thu, 31 Mar 2022 12:16:12 +0100 (BST) Received: from localhost ([::1]:45142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZsmh-0007uK-Ug for patchwork@mira.cbaines.net; Thu, 31 Mar 2022 07:16:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZshj-0001gS-DO for guix-patches@gnu.org; Thu, 31 Mar 2022 07:11:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44131) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nZshj-0003Um-31 for guix-patches@gnu.org; Thu, 31 Mar 2022 07:11:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nZshi-0002Dm-TT for guix-patches@gnu.org; Thu, 31 Mar 2022 07:11:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54393] [PATCH v2 3/3] shell: Add '--export-manifest'. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 31 Mar 2022 11:11:02 +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.16487250518436 (code B ref 54393); Thu, 31 Mar 2022 11:11:02 +0000 Received: (at 54393) by debbugs.gnu.org; 31 Mar 2022 11:10:51 +0000 Received: from localhost ([127.0.0.1]:38024 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nZshS-0002Bn-1d for submit@debbugs.gnu.org; Thu, 31 Mar 2022 07:10:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48990) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nZsh9-00029V-Oz for 54393@debbugs.gnu.org; Thu, 31 Mar 2022 07:10:32 -0400 Received: from [2001:470:142:3::e] (port=54758 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 1nZsh2-0003B8-7Y; Thu, 31 Mar 2022 07:10:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=zMtQau/T4yno5/RcDHSy26kiWvX4+EEuHFFVjRyOOf4=; b=i6W7WBHwCkff/+6MrOro s92bLs84nfKUc6XE4zlDtXkw4EygEpVYYiUD2efE11BqVAqWWyvayyuNgjq4JWQz91RiysogndZSF cwpSkK68uNkCOZ2xKtNx+8v56VfqwZOBwzIZFZfTaeM3TOvUo5oIWuBEjU7A9dDWIBwi9QVcPZTWx fHGbMo/KHHuSNFJq95wYQr/B17UveUU+tWV9zOD387dytlOdUS+OqDAux4QhidtqlahgHk58kNx2e JF0iNiKtVCvjjcUnQWNUnSaVIw6NqGt7IMAjmntSMnjiWoBQKmSOpiAlFjOrjfBLSMIWnsQ9Z2+8n HNGcu9gehOz+zA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:61384 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 1nZsh1-0002dj-8d; Thu, 31 Mar 2022 07:10:20 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 31 Mar 2022 13:09:57 +0200 Message-Id: <20220331110957.31829-3-ludo@gnu.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220331110957.31829-1-ludo@gnu.org> References: <87r173huph.fsf@gnu.org> <20220331110957.31829-1-ludo@gnu.org> 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/shell.scm (show-help, %options): Add '--export-manifest'. (manifest-entry-version-prefix, manifest->code*) (export-manifest): New procedures. (guix-shell): Honor '--export-manifest'. * tests/guix-shell-export-manifest.sh: New file. * Makefile.am (SH_TESTS): Add it. * doc/guix.texi (Invoking guix shell): Document '--export-manifest'. (Invoking guix environment): Link to it. (Invoking guix pack): Likewise. --- Makefile.am | 1 + doc/guix.texi | 57 +++++++++++++++ guix/scripts/shell.scm | 109 +++++++++++++++++++++++++++- tests/guix-shell-export-manifest.sh | 84 +++++++++++++++++++++ 4 files changed, 248 insertions(+), 3 deletions(-) create mode 100644 tests/guix-shell-export-manifest.sh diff --git a/Makefile.am b/Makefile.am index 91243f2cad..20ab7dd5f0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -572,6 +572,7 @@ SH_TESTS = \ tests/guix-environment.sh \ tests/guix-environment-container.sh \ tests/guix-shell.sh \ + tests/guix-shell-export-manifest.sh \ tests/guix-graph.sh \ tests/guix-describe.sh \ tests/guix-repl.sh \ diff --git a/doc/guix.texi b/doc/guix.texi index e8ef4286be..85a91019be 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -5848,6 +5848,55 @@ This is similar to the same-named option in @command{guix package} (@pxref{profile-manifest, @option{--manifest}}) and uses the same manifest files. +See @option{--export-manifest} below on how to obtain a first manifest. + +@cindex manifest, exporting +@anchor{shell-export-manifest} +@item --export-manifest +Write to standard output a manifest suitable for @option{--manifest} +corresponding to given command-line options. + +This is a way to ``convert'' command-line arguments into a manifest. +For example, imagine you are tired of typing long lines and would like +to get a manifest equivalent to this command line: + +@example +guix shell -D guile git emacs emacs-geiser emacs-geiser-guile +@end example + +Just add @option{--export-manifest} to the command line above: + +@example +guix shell --export-manifest \ + -D guile git emacs emacs-geiser emacs-geiser-guile +@end example + +@noindent +... and you get a manifest along these lines: + +@lisp +(concatenate-manifests + (list (specifications->manifest + (list "git" + "emacs" + "emacs-geiser" + "emacs-geiser-guile")) + (package->development-manifest + (specification->package "guile")))) +@end lisp + +You can store it into a file, say @file{manifest.scm}, and from there +pass it to @command{guix shell} or indeed pretty much any @command{guix} +command: + +@example +guix shell -m manifest.scm +@end example + +Voilà, you've converted a long command line into a manifest! That +conversion process honors package transformation options (@pxref{Package +Transformation Options}) so it should be lossless. + @item --profile=@var{profile} @itemx -p @var{profile} Create an environment containing the packages installed in @var{profile}. @@ -6235,6 +6284,10 @@ This is similar to the same-named option in @command{guix package} (@pxref{profile-manifest, @option{--manifest}}) and uses the same manifest files. +@xref{shell-export-manifest, @command{guix shell --export-manifest}}, +for information on how to ``convert'' command-line options into a +manifest. + @item --ad-hoc Include all specified packages in the resulting environment, as if an @i{ad hoc} package were defined with them as inputs. This option is @@ -6693,6 +6746,10 @@ for use on machines that do not have Guix installed. Note that you can specify @emph{either} a manifest file @emph{or} a list of packages, but not both. +@xref{shell-export-manifest, @command{guix shell --export-manifest}}, +for information on how to ``convert'' command-line options into a +manifest. + @item --system=@var{system} @itemx -s @var{system} Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of diff --git a/guix/scripts/shell.scm b/guix/scripts/shell.scm index 1eab05d737..5e7f454f4c 100644 --- a/guix/scripts/shell.scm +++ b/guix/scripts/shell.scm @@ -21,7 +21,8 @@ (define-module (guix scripts shell) #:use-module ((guix diagnostics) #:select (location)) #:use-module (guix scripts environment) #:autoload (guix scripts build) (show-build-options-help) - #:autoload (guix transformations) (transformation-option-key? + #:autoload (guix transformations) (options->transformation + transformation-option-key? show-transformation-options-help) #:use-module (guix scripts) #:use-module (guix packages) @@ -41,7 +42,12 @@ (define-module (guix scripts shell) #:use-module ((guix build utils) #:select (mkdir-p)) #:use-module (guix cache) #:use-module ((ice-9 ftw) #:select (scandir)) - #:autoload (gnu packages) (cache-is-authoritative?) + #:autoload (ice-9 pretty-print) (pretty-print) + #:autoload (gnu packages) (cache-is-authoritative? + package-unique-version-prefix + specification->package + specification->package+output + specifications->manifest) #:export (guix-shell)) (define (show-help) @@ -55,10 +61,13 @@ (define (show-help) -D, --development include the development inputs of the next package")) (display (G_ " -f, --file=FILE add to the environment the package FILE evaluates to")) + (display (G_ " -q inhibit loading of 'guix.scm' and 'manifest.scm'")) (display (G_ " --rebuild-cache rebuild cached environment, if any")) + (display (G_ " + --export-manifest print a manifest for the given options")) (show-environment-options-help) (newline) @@ -112,6 +121,10 @@ (define %options ;; 'wrapped-option'. (alist-delete 'ad-hoc? result))) + (option '("export-manifest") #f #f + (lambda (opt name arg result) + (alist-cons 'export-manifest? #t result))) + ;; For consistency with 'guix package', support '-f' rather than ;; '-l' like 'guix environment' does. (option '(#\f "file") #t #f @@ -380,6 +393,94 @@ (define (key->file key) (loop rest system file specs)) ((_ . rest) (loop rest system file specs))))) + +;;; +;;; Exporting a manifest. +;;; + +(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." + (package-unique-version-prefix (manifest-entry-name entry) + (manifest-entry-version entry))) + +(define (manifest->code* manifest extra-manifests) + "Like 'manifest->code', but insert a 'concatenate-manifests' call that +concatenates MANIFESTS, a list of expressions." + (if (null? (manifest-entries manifest)) + (match extra-manifests + ((one) one) + (lst `(concatenate-manifests ,@extra-manifests))) + (match (manifest->code manifest + #:entry-package-version + manifest-entry-version-prefix) + (('begin exp ... last) + `(begin + ,@exp + ,(match extra-manifests + (() last) + (_ `(concatenate-manifests + (list ,last ,@extra-manifests))))))))) + +(define (export-manifest opts port) + "Write to PORT a manifest corresponding to OPTS." + (define (manifest-lift proc) + (lambda (entry) + (match (manifest-entry-item entry) + ((? package? p) + (manifest-entry + (inherit (package->manifest-entry (proc p))) + (output (manifest-entry-output entry)))) + (_ + entry)))) + + (define (validated-spec spec) + ;; Return SPEC if it's validate package spec. + (specification->package+output spec) + spec) + + (let* ((transform (options->transformation opts)) + (specs (reverse + (filter-map (match-lambda + (('package 'ad-hoc-package spec) + (validated-spec spec)) + (_ #f)) + opts))) + (extras (reverse + (filter-map (match-lambda + (('package 'package spec) + ;; Make sure SPEC is valid. + (specification->package spec) + + ;; XXX: This is an approximation: + ;; transformation options are not applied. + `(package->development-manifest + (specification->package ,spec))) + (_ #f)) + opts))) + (manifest (concatenate-manifests + (cons (map-manifest-entries + (manifest-lift transform) + (specifications->manifest specs)) + (filter-map (match-lambda + (('manifest . file) + (load-manifest file)) + (_ #f)) + opts))))) + (display (G_ "\ +;; What follows is a \"manifest\" equivalent to the command line you gave. +;; You can store it in a file that you may then pass to any 'guix' command +;; that accepts a '--manifest' (or '-m') option.\n") + port) + (match (manifest->code* manifest extras) + (('begin exp ...) + (for-each (lambda (exp) + (newline port) + (pretty-print exp port)) + exp)) + (exp + (pretty-print exp port))))) + ;;; ;;; One-time hints. @@ -445,4 +546,6 @@ (define interactive? cache-entries #:entry-expiration entry-expiration))) - (guix-environment* opts)) + (if (assoc-ref opts 'export-manifest?) + (export-manifest opts (current-output-port)) + (guix-environment* opts))) diff --git a/tests/guix-shell-export-manifest.sh b/tests/guix-shell-export-manifest.sh new file mode 100644 index 0000000000..cbb90f04bf --- /dev/null +++ b/tests/guix-shell-export-manifest.sh @@ -0,0 +1,84 @@ +# GNU Guix --- Functional package management for GNU +# Copyright © 2022 Ludovic Courtès +# +# This file is part of GNU Guix. +# +# GNU Guix is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# GNU Guix is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Guix. If not, see . + +# +# Test 'guix shell --export-manifest'. +# + +guix shell --version + +tmpdir="t-guix-manifest-$$" +trap 'rm -r "$tmpdir"' EXIT +mkdir "$tmpdir" + +manifest="$tmpdir/manifest.scm" + +# Basics. +guix shell --export-manifest guile-bootstrap > "$manifest" +test "$(guix build -m "$manifest")" = "$(guix build guile-bootstrap)" + +guix shell -m "$manifest" --bootstrap -- \ + "$SHELL" -c 'guix package --export-manifest -p "$GUIX_ENVIRONMENT"' > \ + "$manifest.second" +for m in "$manifest" "$manifest.second" +do + grep -v '^;' < "$m" > "$m.new" # filter out comments + mv "$m.new" "$m" +done + +cat "$manifest" +cat "$manifest.second" + +cmp "$manifest" "$manifest.second" + +# Combining manifests. +guix shell --export-manifest -m "$manifest" gash gash-utils \ + > "$manifest.second" +guix build -m "$manifest.second" -d | \ + grep "$(guix build guile-bootstrap -d)" +guix build -m "$manifest.second" -d | \ + grep "$(guix build gash -d)" + +# Package transformation option. +guix shell --export-manifest guile guix --with-latest=guile-json > "$manifest" +grep 'options->transformation' "$manifest" +grep '(with-latest . "guile-json")' "$manifest" + +# Development manifest. +guix shell --export-manifest -D guile git > "$manifest" +grep 'package->development-manifest' "$manifest" +grep '"guile"' "$manifest" +guix build -m "$manifest" -d | \ + grep "$(guix build -e '(@@ (gnu packages commencement) gcc-final)' -d)" +guix build -m "$manifest" -d | \ + grep "$(guix build git -d)" + +# Test various combinations to make sure generated code uses interfaces +# correctly. +for options in \ + "coreutils grep sed" \ + "gsl openblas gcc-toolchain --tune" \ + "guile -m $manifest.previous" \ + "git:send-email gdb guile:debug" \ + "git -D coreutils" +do + guix shell --export-manifest $options > "$manifest" + cat "$manifest" + guix shell -m "$manifest" -n + mv "$manifest" "$manifest.previous" +done