packages: 'package-input-rewriting/spec' optionally replace hidden.

Commit eee95b5a87 changed package
rewriting to ignore hidden packages. This patch permits the previous use
by adding an option to rewrite hidden packages.

* guix/packages.scm (package-input-rewriting/spec)[rewrite]: When P is
hidden, return it as-is unless #:replace-hidden? has been enabled.
* tests/packages.scm ("package-input-rewriting/spec, replace hidden
package"): New test.
* doc/guix.texi (Defining Package Variants): Update.

Change-Id: I0a7988cac70e0c6b88b0fe6e27c1036fa723e030
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Greg Hogan 2024-11-22 14:29:39 +00:00 committed by Ludovic Courtès
parent 62f8399e6a
commit 522732d5c1
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
3 changed files with 26 additions and 6 deletions

View file

@ -7277,7 +7277,8 @@ build} (@pxref{Additional Build Options, @option{--expression} in
@command{guix build}}).
@item --file=@var{file}
build a pack the code within @var{file} evaluates to.
Build a pack containing the package or other object the code within
@var{file} evaluates to.
This has the same purpose as the same-named option in @command{guix
build} (@pxref{Additional Build Options, @option{--file} in
@ -8679,7 +8680,8 @@ This is exactly what the @option{--with-input} command-line option does
The following variant of @code{package-input-rewriting} can match packages to
be replaced by name rather than by identity.
@deffn {Procedure} package-input-rewriting/spec @var{replacements} [#:deep? #t]
@deffn {Procedure} package-input-rewriting/spec @var{replacements} @
[#:deep? #t] [#:replace-hidden? #t]
Return a procedure that, given a package, applies the given
@var{replacements} to all the package graph, including implicit inputs
unless @var{deep?} is false.
@ -8688,7 +8690,7 @@ unless @var{deep?} is false.
package specification such as @code{"gcc"} or @code{"guile@@2"}, and
each procedure takes a matching package and returns a replacement for
that package. Matching packages that have the @code{hidden?} property
set are not replaced.
set are not replaced unless @var{replace-hidden?} is set to true.
@end deffn
The example above could be rewritten this way:

View file

@ -1611,14 +1611,16 @@ (define (cut? p)
(package-mapping rewrite cut?
#:deep? deep?))
(define* (package-input-rewriting/spec replacements #:key (deep? #t))
(define* (package-input-rewriting/spec replacements
#:key (deep? #t) (replace-hidden? #f))
"Return a procedure that, given a package, applies the given REPLACEMENTS to
all the package graph, including implicit inputs unless DEEP? is false.
REPLACEMENTS is a list of spec/procedures pair; each spec is a package
specification such as \"gcc\" or \"guile@2\", and each procedure takes a
matching package and returns a replacement for that package. Matching
packages that have the 'hidden?' property set are not replaced."
packages that have the 'hidden?' property set are not replaced unless
REPLACE-HIDDEN? is set to true."
(define table
(fold (lambda (replacement table)
(match replacement
@ -1647,7 +1649,8 @@ (define replacement-property
(define (rewrite p)
(if (or (assq-ref (package-properties p) replacement-property)
(hidden-package? p))
(and (not replace-hidden?)
(hidden-package? p)))
p
(match (find-replacement p)
(#f p)

View file

@ -1628,6 +1628,21 @@ (define right-system?
(match (delete-duplicates pythons eq?)
((p) (eq? p python)))))
(test-assert "package-input-rewriting/spec, replace hidden package"
;; Rewrite hidden packages when requested.
(let* ((python (hidden-package python))
(p0 (dummy-package "chbouib"
(build-system trivial-build-system)
(inputs (list python))))
(rewrite (package-input-rewriting/spec
`(("python" . ,(const sed)))
#:replace-hidden? #t))
(p1 (rewrite p0)))
(match (package-inputs p1)
((("python" python))
(and (string=? (package-full-name python)
(package-full-name sed)))))))
(test-equal "package-input-rewriting/spec, graft"
(derivation-file-name (package-derivation %store sed))