diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2019-01-13 15:36:49 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2019-01-15 20:24:09 +0100 |
| commit | 0ea939fb796fdd4f0d46d3534b2ec6135e0f3dc7 (patch) | |
| tree | 4e2117fbad1e173ba079800d3fb00d8d64702184 /gnu/packages.scm | |
| parent | ee8099f5b688ce5f57790db4122f0b5b91a26216 (diff) | |
guix package: '--list-available' can use data from the cache.
* gnu/packages.scm (fold-available-packages): New procedure.
* guix/scripts/package.scm (process-query): Use it instead of
'fold-packages'.
* tests/packages.scm ("fold-available-packages with/without cache"):
New test.
Diffstat (limited to 'gnu/packages.scm')
| -rw-r--r-- | gnu/packages.scm | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/gnu/packages.scm b/gnu/packages.scm index cf655e74480..a1814205f93 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm | |||
| @@ -53,6 +53,7 @@ | |||
| 53 | %default-package-module-path | 53 | %default-package-module-path |
| 54 | 54 | ||
| 55 | fold-packages | 55 | fold-packages |
| 56 | fold-available-packages | ||
| 56 | 57 | ||
| 57 | find-packages-by-name | 58 | find-packages-by-name |
| 58 | find-package-locations | 59 | find-package-locations |
| @@ -182,6 +183,50 @@ flags." | |||
| 182 | directory)) | 183 | directory)) |
| 183 | %load-path))) | 184 | %load-path))) |
| 184 | 185 | ||
| 186 | (define (fold-available-packages proc init) | ||
| 187 | "Fold PROC over the list of available packages. For each available package, | ||
| 188 | PROC is called along these lines: | ||
| 189 | |||
| 190 | (PROC NAME VERSION RESULT | ||
| 191 | #:outputs OUTPUTS | ||
| 192 | #:location LOCATION | ||
| 193 | …) | ||
| 194 | |||
| 195 | PROC can use #:allow-other-keys to ignore the bits it's not interested in. | ||
| 196 | When a package cache is available, this procedure does not actually load any | ||
| 197 | package module." | ||
| 198 | (define cache | ||
| 199 | (load-package-cache (current-profile))) | ||
| 200 | |||
| 201 | (if (and cache (cache-is-authoritative?)) | ||
| 202 | (vhash-fold (lambda (name vector result) | ||
| 203 | (match vector | ||
| 204 | (#(name version module symbol outputs | ||
| 205 | supported? deprecated? | ||
| 206 | file line column) | ||
| 207 | (proc name version result | ||
| 208 | #:outputs outputs | ||
| 209 | #:location (and file | ||
| 210 | (location file line column)) | ||
| 211 | #:supported? supported? | ||
| 212 | #:deprecated? deprecated?)))) | ||
| 213 | init | ||
| 214 | cache) | ||
| 215 | (fold-packages (lambda (package result) | ||
| 216 | (proc (package-name package) | ||
| 217 | (package-version package) | ||
| 218 | result | ||
| 219 | #:outputs (package-outputs package) | ||
| 220 | #:location (package-location package) | ||
| 221 | #:supported? | ||
| 222 | (->bool | ||
| 223 | (member (%current-system) | ||
| 224 | (package-supported-systems package))) | ||
| 225 | #:deprecated? | ||
| 226 | (->bool | ||
| 227 | (package-superseded package)))) | ||
| 228 | init))) | ||
| 229 | |||
| 185 | (define* (fold-packages proc init | 230 | (define* (fold-packages proc init |
| 186 | #:optional | 231 | #:optional |
| 187 | (modules (all-modules (%package-module-path) | 232 | (modules (all-modules (%package-module-path) |
