all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 74888@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>,
	"Christopher Baines" <guix@cbaines.net>,
	"Josselin Poiret" <dev@jpoiret.xyz>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"Mathieu Othacehe" <othacehe@gnu.org>,
	"Maxim Cournoyer" <maxim.cournoyer@gmail.com>,
	"Simon Tournier" <zimon.toutoune@gmail.com>,
	"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#74888] [PATCH 1/3] packages: Add #:recursive? to ‘package-input-rewriting’.
Date: Sun, 15 Dec 2024 17:25:40 +0100	[thread overview]
Message-ID: <e3384ca81537ea2ac2bce1eb3444474c1db9ed5e.1734279715.git.ludo@gnu.org> (raw)
In-Reply-To: <cover.1734279715.git.ludo@gnu.org>

* 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 <ludo@gnu.org>
+;;; Copyright © 2012-2024 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
 ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
@@ -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





  reply	other threads:[~2024-12-15 16:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-15 16:24 [bug#74888] [PATCH 0/3] Fixes to the 'security-updates' and 'ungraft' manifests Ludovic Courtès
2024-12-15 16:25 ` Ludovic Courtès [this message]
2024-12-15 16:25 ` [bug#74888] [PATCH 2/3] etc: upgrade: Really compute joint upgrades Ludovic Courtès
2024-12-15 16:25 ` [bug#74888] [PATCH 3/3] etc: ungraft: Use ‘package-mapping’ directly Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e3384ca81537ea2ac2bce1eb3444474c1db9ed5e.1734279715.git.ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=74888@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=guix@cbaines.net \
    --cc=maxim.cournoyer@gmail.com \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=zimon.toutoune@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.