refresh: Support select packages SUBSET by module name.

* guix/scripts/refresh.scm (%options): Support '--select module:NAME'.
(show-help): Adjust accordingly.
(options->update-specs): Honor the module passed by '--select'.
* doc/guix.texi (Invoking guix refresh): Document it.
This commit is contained in:
宋文武 2023-04-09 12:43:30 +08:00
parent 5b545763ed
commit 4502de61f2
No known key found for this signature in database
GPG key ID: D415BF253B515976
2 changed files with 38 additions and 7 deletions

View file

@ -14227,8 +14227,8 @@ $ ./pre-inst-env guix refresh -s non-core -u
@item --select=[@var{subset}]
@itemx -s @var{subset}
Select all the packages in @var{subset}, one of @code{core} or
@code{non-core}.
Select all the packages in @var{subset}, one of @code{core}, @code{non-core}
or @code{module:@var{name}}.
The @code{core} subset refers to all the packages at the core of the
distribution---i.e., packages that are used to build ``everything
@ -14241,6 +14241,11 @@ The @code{non-core} subset refers to the remaining packages. It is
typically useful in cases where an update of the core packages would be
inconvenient.
The @code{module:@var{name}} subset refers to all the packages in a
specified guile module. The module can be specified as
@code{module:guile} or @code{module:(gnu packages guile)}, the former is
a shorthand for the later.
@item --manifest=@var{file}
@itemx -m @var{file}
Select all the packages from the manifest in @var{file}. This is useful to

View file

@ -32,6 +32,7 @@ (define-module (guix scripts refresh)
#:use-module ((guix scripts build) #:select (%standard-build-options))
#:use-module (guix store)
#:use-module (guix utils)
#:use-module (guix discovery)
#:use-module (guix packages)
#:use-module (guix profiles)
#:use-module (guix upstream)
@ -44,6 +45,7 @@ (define-module (guix scripts refresh)
#:use-module ((gnu packages commencement) #:select (%final-inputs))
#:use-module (ice-9 match)
#:use-module (ice-9 format)
#:use-module (ice-9 regex)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-26)
@ -71,8 +73,23 @@ (define %options
((or "core" "non-core")
(alist-cons 'select (string->symbol arg)
result))
((? (cut string-prefix? "module:" <>))
(let ((mod (cond
;; Shorthand name: "module:guile".
((string-match "module:([^\( ]+)$" arg) =>
(lambda (m)
`(gnu packages ,(string->symbol
(match:substring m 1)))))
;; Full name : "module:(gnu packages guile)".
((string-match "module:\\(([^)]+)\\)$" arg) =>
(lambda (m)
(map string->symbol
(string-split
(match:substring m 1) #\space))))
(else (leave (G_ "invalid module: ~a~%") arg)))))
(alist-cons 'select (cons 'module mod) result)))
(x
(leave (G_ "~a: invalid selection; expected `core' or `non-core'~%")
(leave (G_ "~a: invalid selection; expected `core', `non-core' or `module:NAME'~%")
arg)))))
(option '(#\t "type") #t #f
(lambda (opt name arg result)
@ -141,8 +158,10 @@ (define (show-help)
(display (G_ "
-u, --update update source files in place"))
(display (G_ "
-s, --select=SUBSET select all the packages in SUBSET, one of
`core' or `non-core'"))
-s, --select=SUBSET select all the packages in SUBSET, one of `core`,
`non-core' or `module:NAME' (eg: module:guile)
the module can also be fully specified as
'module:(gnu packages guile)'"))
(display (G_ "
-m, --manifest=FILE select all the packages from the manifest in FILE"))
(display (G_ "
@ -257,13 +276,20 @@ (define update-specs
(let ((select? (match (assoc-ref opts 'select)
('core core-package?)
('non-core (negate core-package?))
(_ (const #t)))))
(_ (const #t))))
(modules (match (assoc-ref opts 'select)
(('module . mod)
(list (resolve-interface mod)))
(_ (all-modules (%package-module-path)
#:warn
warn-about-load-error)))))
(map update-spec
(fold-packages (lambda (package result)
(if (select? package)
(keep-newest package result)
result))
'()))))
'()
modules))))
(some ;user-specified packages
some)))