[bug#58824,1/1] scripts: refresh: Support --list-dependent=packages.
Commit Message
* 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.
---
guix/scripts/refresh.scm | 61 ++++++++++++++++++++++++----------------
1 file changed, 37 insertions(+), 24 deletions(-)
Comments
Hi,
On Thu, 27 Oct 2022 at 22:28, "\( via Guix-patches" via <guix-patches@gnu.org> wrote:
> - (option '(#\l "list-dependent") #f #f
> + (option '(#\l "list-dependent") #f #t
For what it is worth, I think it is a bad idea to have optional argument
with short-name, well IMHO; see [1].
1: <http://issues.guix.gnu.org/issue/50472>
Cheers,
simon
On Fri Nov 25, 2022 at 9:21 AM GMT, zimoun wrote:
> For what it is worth, I think it is a bad idea to have optional argument
> with short-name, well IMHO; see [1].
>
> 1: <http://issues.guix.gnu.org/issue/50472>
Hmm. Perhaps we could replace this with a whole new
-D, --list-dependent-packages
flag?
-- (
Hi,
On Fri, 25 Nov 2022 at 16:25, "\( via Guix-patches" via <guix-patches@gnu.org> wrote:
> Hmm. Perhaps we could replace this with a whole new
>
> -D, --list-dependent-packages
>
> flag?
Vagrant proposed [1] to add a flag as --machine-readable, quoting:
I vaguely recall discussing on irc not long ago the desire for "guix
refresh --list-dependent --machine-readable" (e.g. drop the "Building
the following X packages would ensure 10 dependent packages are
rebuilt:") or something similar. Would save having to pipe to cut, awk,
sed, perl, etc. ...
Well, there is also the annoyance that hidden packages are shown so it
becomes cumbersome for piping with “guix build” for instance. Maybe,
this patch could be tweaked to have something like,
guix refresh --list-build-dependent PACKAGE
returning a list accepted by “guix build”.
1: <https://yhetil.org/guix/87ilj69380.fsf@contorta>
Cheers,
simon
@@ -93,9 +93,12 @@ (define %options
(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 +420,10 @@ (define (all-packages)
'()
#: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 +436,31 @@ (define (full-name package)
(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 +537,8 @@ (define (options->updaters opts)
(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 +554,9 @@ (define (options->updaters opts)
(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?