From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id WMXzNHUDX2d2IAEAe85BDQ:P1 (envelope-from ) for ; Sun, 15 Dec 2024 16:27:34 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id WMXzNHUDX2d2IAEAe85BDQ (envelope-from ) for ; Sun, 15 Dec 2024 17:27:34 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=ivr3oE50; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=r53ofPlq; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1734280053; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=rTSo0qlKWhcJXPtDKOITHVi2d//E/SyXZy0e7+TxJJo=; b=PaVCF18r6fvoYWAMfBBrD9bnixeC5Ho2jR7sjLd4JO5M3YSKcwnCpgKW+d5kjvw3lekcF5 PTA+sd5SFo2X8+NXhKoaEONKezE/DLgKsdA/TYdAR7txWGFhR6Q5nXQD35tkaToQUxmo0K 8vByoFTgDYcyQ4pudAYArUvTMgcM+8o+03hrzgzrcWF3FbIkSM7wDINskGbG9fC9gLh7IA pzX2XdalByJO8dfM3B0TwLOko+yt7ovU3tPqelVsLyxFEhhmg9VCoDeBM0ELSyR5Lw0u3Y OdpnhNHNuSbWiFut2wb8EdsiUqPx9QY1NBcK1QyveNqKMF1w8AONsM6UiVP0Ig== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1734280053; a=rsa-sha256; cv=none; b=Lne/eWYfSLN6BHn510Hj2d+97MAWyskBClyVJLgm7as8Dk0V1/sDaVSDk+ZI0SsD5c3lgH Q5QoeU6ykqe+tFxjAqyYHcG2mwr3Hhp+5KoAp8nhxv2uEbtD9ALj85ekTESbxIZnDskN3/ AzwEV5nBqDudXsOYp7Cxow0lrR0+Bpr8/GtBs/ZBvjDoGbJzIHLdlOMK5Nji/3YzJTQ8te wwX36QGbQJVWyyTMfJcYYV6BJln1XLrddNGR54CyUDNjOvDRtO4T2PH9u7K+w8KFzWvxGf DuCFhzdSTpXAi8yKeBOGGOiCu3heNch8Wh9eI8+/IrzwDIqz3ilusIbc0ks+UQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=ivr3oE50; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=r53ofPlq; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8554B84EED for ; Sun, 15 Dec 2024 17:27:33 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMrSY-0003wI-CM; Sun, 15 Dec 2024 11:27:10 -0500 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 1tMrSV-0003vw-DP for guix-patches@gnu.org; Sun, 15 Dec 2024 11:27:07 -0500 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 1tMrSV-0006ae-1Q; Sun, 15 Dec 2024 11:27:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=rTSo0qlKWhcJXPtDKOITHVi2d//E/SyXZy0e7+TxJJo=; b=ivr3oE50Y6v80IcIv6bzN8a9ILJCTe58gl35TEGSy3CvAhUPrjwRlSbyYYzhlxehJ++f1F2Ab8UaiEJnsVqzfuIFYtrrpC/saGBW2kx7Fpm0AmSHoAkfbrwA4Ad8yOXhAVdb69P0/IxfuLjaTcFEICrKxVYX0SrzzlVjTWymzcYgmR1MoGZ7EBjoifgP14xKtm/t3t7NKsUJ2LZhdep5TU6GrF0RJeC462M8uyepiZGbtgkvsDRrvtsz8iF7wCEJ4bUK8499qBW/DeEmlc3okPwBijr7BskC4pCdk4hEe9fBTUifGwsU54AFjD4bpqNFqRrFLRlDzt5OnSIwkXDyNA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tMrSQ-0006Rv-5z; Sun, 15 Dec 2024 11:27:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74888] [PATCH 1/3] packages: Add #:recursive? to =?UTF-8?Q?=E2=80=98package-input-rewriting=E2=80=99.?= 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, maxim.cournoyer@gmail.com, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Sun, 15 Dec 2024 16:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74888 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74888@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 74888-submit@debbugs.gnu.org id=B74888.173427997724695 (code B ref 74888); Sun, 15 Dec 2024 16:27:02 +0000 Received: (at 74888) by debbugs.gnu.org; 15 Dec 2024 16:26:17 +0000 Received: from localhost ([127.0.0.1]:51717 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMrRg-0006QB-H4 for submit@debbugs.gnu.org; Sun, 15 Dec 2024 11:26:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39180) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMrRc-0006Pk-Tn for 74888@debbugs.gnu.org; Sun, 15 Dec 2024 11:26:13 -0500 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 1tMrRX-0006Tq-Kr; Sun, 15 Dec 2024 11:26:07 -0500 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=rTSo0qlKWhcJXPtDKOITHVi2d//E/SyXZy0e7+TxJJo=; b=r53ofPlq09tC/9A6lhbx iHegE9nCS2NgHIauv8R7vgl3b8RXPjHo0yzFAYh34dTPvFyG5kza0PjSqxtpBsyMUU0OHCe2MNfIQ 9SulmIOW/xlbkd0g3+1A5eJyE1Sp7iIkyjO06OFkFD1SDEmdDeZi+bu8GaUYPvFdeNJmn7/k6CqdM JWLu7/qm8q4URgM1AXoyadC4AViHy5KFBcjNktt7U6bDuny7I+jUtHa7pR3jjtFsr52zkZE4BZpd+ 3wsLeQjN9TZcp1lBy4H2T6JDCZwUnEq8ieUfVz0kumpwou2Dte/KkfBdd1s1O79LqpoqSrCZI5Meb lTMeyYGNE0dnLA==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sun, 15 Dec 2024 17:25:40 +0100 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -2.79 X-Spam-Score: -2.79 X-Migadu-Queue-Id: 8554B84EED X-Migadu-Scanner: mx11.migadu.com X-TUID: hwIqaBQB/Q2U * guix/packages.scm (package-input-rewriting): Add #:recursive? [cut?]: Honor it. * tests/packages.scm ("package-input-rewriting, recursive"): New test. * doc/guix.texi (Defining Package Variants): Document it. Change-Id: Ie82f35ae0ae873dc68f8b1c0dd6616f552772e65 --- doc/guix.texi | 6 +++++- guix/packages.scm | 9 +++++++-- tests/packages.scm | 32 +++++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index a2915de954..995ff5ad4e 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -8653,13 +8653,17 @@ Defining Package Variants graph, is what the @code{package-input-rewriting} procedure in @code{(guix packages)} implements. -@deffn {Procedure} package-input-rewriting replacements [rewrite-name] [#:deep? #t] +@deffn {Procedure} package-input-rewriting replacements [rewrite-name] @ + [#:deep? #t] [#:recursive? #f] Return a procedure that, when passed a package, replaces its direct and indirect dependencies, including implicit inputs when @var{deep?} is true, according to @var{replacements}. @var{replacements} is a list of package pairs; the first element of each pair is the package to replace, and the second one is the replacement. +When @var{recursive?} is true, apply replacements to the right-hand sides of +@var{replacements} as well, recursively. + Optionally, @var{rewrite-name} is a one-argument procedure that takes the name of a package and returns its new name after rewrite. @end deffn diff --git a/guix/packages.scm b/guix/packages.scm index 0ce3276051..75271b7a05 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -1582,12 +1582,16 @@ (define* (package-mapping proc #:optional (cut? (const #f)) (define* (package-input-rewriting replacements #:optional (rewrite-name identity) - #:key (deep? #t)) + #:key (deep? #t) + (recursive? #f)) "Return a procedure that, when passed a package, replaces its direct and indirect dependencies, including implicit inputs when DEEP? is true, according to REPLACEMENTS. REPLACEMENTS is a list of package pairs; the first element of each pair is the package to replace, and the second one is the replacement. +When RECURSIVE? is true, apply replacements to the right-hand sides of +REPLACEMENTS as well, recursively. + Optionally, REWRITE-NAME is a one-argument procedure that takes the name of a package and returns its new name after rewrite." (define replacement-property @@ -1608,7 +1612,8 @@ (define* (package-input-rewriting replacements (define (cut? p) (or (assq-ref (package-properties p) replacement-property) - (assq-ref replacements p))) + (and (not recursive?) + (assq-ref replacements p)))) (package-mapping rewrite cut? #:deep? deep?)) diff --git a/tests/packages.scm b/tests/packages.scm index 7c28e75c45..6417bc79de 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012-2023 Ludovic Courtès +;;; Copyright © 2012-2024 Ludovic Courtès ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2021 Maxim Cournoyer ;;; Copyright © 2021 Maxime Devos @@ -1501,6 +1501,36 @@ (define compressors '(("gzip" . "gz") ((("python" python) _ ...) (derivation-file-name (package-derivation %store python)))))) +(test-assert "package-input-rewriting, recursive" + (let* ((dep (dummy-package "dep" (native-inputs (list grep)))) + (p0 (dummy-package "example1" (inputs (list dep grep)))) + (p1 (dummy-package "example2" (inputs (list dep grep)))) + (replacements `((,grep . ,findutils) (,p0 . ,p1))) + (rewrite (package-input-rewriting replacements)) + (rewrite/recursive (package-input-rewriting replacements + #:recursive? #t)) + (p2 (rewrite p0)) + (p3 (rewrite/recursive p0))) + (and (string=? (package-name p2) "example2") + ;; Here P0 is replaced by P1, but P1 itself is kept unchanged. + (match (package-inputs p2) + ((("dep" dep1) ("grep" dep2)) + (and (match (package-native-inputs dep1) + ((("grep" x)) (eq? x grep))) + (eq? dep2 grep)))) + + ;; Here P0 is replaced by P1, and in addition references to GREP in + ;; P1 and its dependencies are also replaced by FINDUTILS. + (string=? (package-name p3) "example2") + (match (package-inputs p3) + ((("dep" dep1) ("grep" dep2)) + (and (match (package-native-inputs dep1) + ((("grep" x)) + (string=? (package-full-name x) + (package-full-name findutils)))) + (string=? (package-full-name dep2) + (package-full-name findutils)))))))) + (test-assert "package-input-rewriting/spec" (let* ((dep (dummy-package "chbouib" (native-inputs `(("x" ,grep))))) -- 2.46.0