From patchwork Mon Oct 7 08:35:55 2024 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: 68756 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 26F8027BBEA; Mon, 7 Oct 2024 09:37:23 +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=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,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 956A127BBE2 for ; Mon, 7 Oct 2024 09:37:22 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxjEo-00066R-Ed; Mon, 07 Oct 2024 04:37:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxjEm-000660-8n for guix-patches@gnu.org; Mon, 07 Oct 2024 04:37:04 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sxjEm-0006Ox-0S; Mon, 07 Oct 2024 04:37:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=gCzNbjZP/QQ2aJE4Vq7CLBVDqsZWk6vssDafT3ei0qY=; b=CFF/ZV+nq0oGFcvqFnmpA+Ibb5YDilDq+aZCcWRVki/q3cYIVPhI11TfrrRBSAV6y7mHZCzOxxx0JMfvDaRBb7OWmsKymxORefRvnfejK9dcnC7a/LG/+upi6mdvo2BTbR/U1iRRTUYhr4/9VD5TwreoErO2ZvIzDAZbBso0wJtWdLQXzx3SMgjkXnuNjzp5kL/i18GzAj31fqphg/9Zke+O4UA4nABPVRgukQv5uyxuFF8xMm+VARelRThRY1mD6dPJbUtBHG+rKl4/lPnzQboY0dNZ9n82LOptUq9pUgdoCzL67cz6QqbOggOB9SoBgfUULDoIVy/holp7HsAmXQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sxjEj-0005Mv-RQ; Mon, 07 Oct 2024 04:37:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73674] [PATCH] shell: Enable caching when using deterministic package transformations. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Mon, 07 Oct 2024 08:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73674 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73674@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.172829018220556 (code B ref -1); Mon, 07 Oct 2024 08:37:01 +0000 Received: (at submit) by debbugs.gnu.org; 7 Oct 2024 08:36:22 +0000 Received: from localhost ([127.0.0.1]:44690 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxjE5-0005LU-Hz for submit@debbugs.gnu.org; Mon, 07 Oct 2024 04:36:22 -0400 Received: from lists.gnu.org ([209.51.188.17]:34290) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxjE3-0005LK-3i for submit@debbugs.gnu.org; Mon, 07 Oct 2024 04:36:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxjDt-0005c7-HA for guix-patches@gnu.org; Mon, 07 Oct 2024 04:36:11 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxjDs-0006KN-1y; Mon, 07 Oct 2024 04:36:08 -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=gCzNbjZP/QQ2aJE4Vq7CLBVDqsZWk6vssDafT3ei0qY=; b=dCgr6cwltsj1jk r2M9VD6ZJAaID3vQ6jtITZLH6p/1mZnSYI1Z9KuGmz9+1ML0QrGHVlNW4aIdxKqERD6wvUwHRY0zo 5HgOJWzewrVuuEKhlpshqYpE4bC3ssZ1kXwVeIqdqEW+h7Jw2GZOosjcAydzi5sIYcGOqK9jNgiGa SN78XQgx7yLmULhBa0upqpR/Bnp3OUinnvNdDDFL55hux66iA4Q54JVe0I/lrQZFVUgLi41K/mxYO Db7mhCh/fB1Uyo7tKVx4bsQ+8kQ7dGbGVXMy3eY17TWFpUixNyjGjF4EzFRXYeSJOblexGwCT52BO Vhv6q2sIgSCaAm6XbDqg==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 7 Oct 2024 10:35:55 +0200 Message-ID: X-Mailer: git-send-email 2.46.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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches From: Ludovic Courtès Until now, using any package transformation would disable the automatic GC root creation and caching in ‘guix shell’. This change introduces a finer-grain distinction: a command like: guix shell --tune inkscape is now subject to caching, whereas: guix shell --with-latest=inkscape inkscape remains non-cacheable. * guix/transformations.scm (%transformations-with-external-dependencies): New variable. (cacheable-transformation-option-key?): New procedure. * guix/scripts/shell.scm (profile-cached-gc-root): In the ‘transformation-option-key?’ clause, call ‘loop’ when ‘cacheable-transformation-option-key?’ returns true. Change-Id: I847b661dfea20ecf851db2023a5c7ea8c5b5ca7c --- guix/scripts/shell.scm | 13 ++++++++----- guix/transformations.scm | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 6 deletions(-) base-commit: 73ec844389e91cb0f5a2647070516fc8d19d8730 diff --git a/guix/scripts/shell.scm b/guix/scripts/shell.scm index 0584a7e018..d23362a15d 100644 --- a/guix/scripts/shell.scm +++ b/guix/scripts/shell.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2021-2023 Ludovic Courtès +;;; Copyright © 2021-2024 Ludovic Courtès ;;; Copyright © 2023 Janneke Nieuwenhuizen ;;; ;;; This file is part of GNU Guix. @@ -25,6 +25,7 @@ (define-module (guix scripts shell) show-native-build-options-help) #:autoload (guix transformations) (options->transformation transformation-option-key? + cacheable-transformation-option-key? show-transformation-options-help) #:autoload (guix grafts) (%graft?) #:use-module (guix scripts) @@ -417,11 +418,13 @@ (define (profile-cached-gc-root opts) ;; Arbitrary expressions might be non-deterministic or otherwise depend ;; on external state so do not cache when they're used. (values #f #f)) - ((((? transformation-option-key?) . _) . _) + ((((? transformation-option-key? key) . _) . rest) ;; Transformation options are potentially "non-deterministic", or at - ;; least depending on external state (with-source, with-commit, etc.), - ;; so do not cache anything when they're used. - (values #f #f)) + ;; least depending on external state (with-source, with-commit, etc.). + ;; Cache only those that are known to be "cacheable". + (if (cacheable-transformation-option-key? key) + (loop rest system file (cons (first opts) specs)) + (values #f #f))) ((('profile . _) . _) ;; If the user already specified a profile, there's nothing more to ;; cache. diff --git a/guix/transformations.scm b/guix/transformations.scm index 582f8a2729..ea8b7a0844 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2016-2023 Ludovic Courtès +;;; Copyright © 2016-2024 Ludovic Courtès ;;; Copyright © 2021 Marius Bakke ;;; Copyright © 2023 Sarthak Shah ;;; Copyright © 2023, 2024 Efraim Flashner @@ -63,6 +63,7 @@ (define-module (guix transformations) show-transformation-options-help transformation-option-key? + cacheable-transformation-option-key? %transformation-options)) ;;; Commentary: @@ -938,6 +939,16 @@ (define %transformations (with-latest . ,transform-package-latest) (with-version . ,transform-package-version))) +(define %transformations-with-external-dependencies + ;; Subset of options that depend on external resources and that can thus be + ;; considered "non-deterministic" and non-cacheable. + '(with-source + with-branch + with-git-url + with-patch + with-latest + with-version)) + (define (transformation-procedure key) "Return the transformation procedure associated with KEY, a symbol such as 'with-source', or #f if there is none." @@ -952,6 +963,13 @@ (define (transformation-option-key? key) For example, (transformation-option-key? 'with-input) => #t." (->bool (transformation-procedure key))) +(define (cacheable-transformation-option-key? key) + "Return true if KEY corresponds to a transformation option whose result can +be cached--i.e., the transformation is deterministic and does not depend on +external resources." + (and (transformation-option-key? key) + (not (memq key %transformations-with-external-dependencies)))) + ;;; ;;; Command-line handling.