diff options
author | ( <paren@disroot.org> | 2022-10-28 16:30:52 +0100 |
---|---|---|
committer | Guix Patches Tester <> | 2022-11-07 20:09:16 +0100 |
commit | e382cb8cf144ca62b3d52620f4ce5a5b47e4f8c5 (patch) | |
tree | cea934309450954d076e3e91679335c651a0634b | |
parent | 4a34da845ed91821d38ba8a9b65ad650dd7488d1 (diff) | |
download | guix-patches-e382cb8cf144ca62b3d52620f4ce5a5b47e4f8c5.tar guix-patches-e382cb8cf144ca62b3d52620f4ce5a5b47e4f8c5.tar.gz |
scripts: refresh: Support --list-dependent=packages.issue-58824
* guix/scripts/refresh.scm (%options)[list-dependent]: Allow an
optional argument. Set 'LIST-DEPENDENT-MACHINE-READABLE? to
#T in RESULT if the argument is "packages".
(list-dependents): Support #:MACHINE-READABLE?.
(guix-refresh): Pass #:MACHINE-READABLE? #T to LIST-DEPENDENTS if
'LIST-DEPENDENT-MACHINE-READABLE? is #T.
* doc/guix.texi: Document 'guix refresh --list-dependent=packages'.
-rw-r--r-- | doc/guix.texi | 13 | ||||
-rw-r--r-- | guix/scripts/refresh.scm | 62 |
2 files changed, 49 insertions, 26 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 1eb47e31cf..680666b58b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -14108,11 +14108,20 @@ be used when passing @command{guix refresh} one or more package names: @table @code -@item --list-dependent -@itemx -l +@item --list-dependent[=packages] +@itemx -l [packages] List top-level dependent packages that would need to be rebuilt as a result of upgrading one or more packages. +If the option is called with the optional @code{packages} argument, it +will display only the list of packages, without the header stating the +number of packages that will be rebuilt. This can be used to run +commands such as this, which builds all the dependents of @code{gtk}: + +@example +$ guix build $(guix refresh gtk -l packages) +@end example + @xref{Invoking guix graph, the @code{reverse-package} type of @command{guix graph}}, for information on how to visualize the list of dependents of a package. diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm index 14329751f8..7c3f392a96 100644 --- a/guix/scripts/refresh.scm +++ b/guix/scripts/refresh.scm @@ -9,6 +9,7 @@ ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net> ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com> ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev> +;;; Copyright © 2022 ( <paren@disroot.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -93,9 +94,12 @@ (option '(#\e "expression") #t #f (lambda (opt name arg result) (alist-cons 'expression arg result))) - (option '(#\l "list-dependent") #f #f + (option '(#\l "list-dependent") #f #t (lambda (opt name arg result) - (alist-cons 'list-dependent? #t result))) + (append `((list-dependent? . #t) + (list-dependent-machine-readable? + . ,(and arg (string=? arg "packages")))) + result))) (option '(#\r "recursive") #f #f (lambda (opt name arg result) (alist-cons 'recursive? #t result))) @@ -417,8 +421,10 @@ releases for ~a~%") '() #:select? (const #t))) ;include hidden packages -(define (list-dependents packages) - "List all the things that would need to be rebuilt if PACKAGES are changed." +(define* (list-dependents packages #:key (machine-readable? #f)) + "List all the things that would need to be rebuilt if PACKAGES are +changed. If MACHINE-READABLE? is #T, display only a list of packages, +with no human-friendly extra text." ;; Using %BAG-NODE-TYPE is more accurate than using %PACKAGE-NODE-TYPE ;; because it includes implicit dependencies. (define (full-name package) @@ -431,27 +437,31 @@ releases for ~a~%") (covering (filter (lambda (node) (null? (edges node))) dependents))) - (match dependents - (() - (format (current-output-port) - (N_ "No dependents other than itself: ~{~a~}~%" - "No dependents other than themselves: ~{~a~^ ~}~%" - (length packages)) - (map full-name packages))) - - ((x) - (format (current-output-port) - (G_ "A single dependent package: ~a~%") - (full-name x))) - (lst - (format (current-output-port) - (N_ "Building the following ~d package would ensure ~d \ + (if machine-readable? + (format (current-output-port) + (G_ "~{~a~^ ~}~%") + (map full-name covering)) + (match dependents + (() + (format (current-output-port) + (N_ "No dependents other than itself: ~{~a~}~%" + "No dependents other than themselves: ~{~a~^ ~}~%" + (length packages)) + (map full-name packages))) + ((x) + (format (current-output-port) + (G_ "A single dependent package: ~a~%") + (full-name x))) + (lst + (format (current-output-port) + (N_ "Building the following ~d package would ensure ~d \ dependent packages are rebuilt: ~{~a~^ ~}~%" - "Building the following ~d packages would ensure ~d \ + "Building the following ~d packages would ensure ~d \ dependent packages are rebuilt: ~{~a~^ ~}~%" - (length covering)) - (length covering) (length dependents) - (map full-name covering)))) + (length covering)) + (length covering) (length dependents) + (map full-name covering))))) + (return #t)))) (define (list-transitive packages) @@ -528,6 +538,8 @@ all are dependent packages: ~{~a~^ ~}~%") (updaters (options->updaters opts)) (recursive? (assoc-ref opts 'recursive?)) (list-dependent? (assoc-ref opts 'list-dependent?)) + (list-dependent-machine-readable? + (assoc-ref opts 'list-dependent-machine-readable?)) (list-transitive? (assoc-ref opts 'list-transitive?)) (key-download (assoc-ref opts 'key-download)) @@ -543,7 +555,9 @@ all are dependent packages: ~{~a~^ ~}~%") (mlet %store-monad ((packages (options->packages opts))) (cond (list-dependent? - (list-dependents packages)) + (list-dependents packages + #:machine-readable? + list-dependent-machine-readable?)) (list-transitive? (list-transitive packages)) (update? |