diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2019-02-12 22:17:11 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2019-02-12 23:30:16 +0100 |
| commit | 739380542da7e434c581ec620edeb4348d6ece89 (patch) | |
| tree | 85d7c3d1caf3ead51829016fb3787116cfbab588 | |
| parent | 46765f82dbd541a6ab48ba84816dbcf701d8714b (diff) | |
inferior: Add 'inferior-available-packages'.
* guix/inferior.scm (inferior-available-packages): New procedure.
* tests/inferior.scm ("inferior-available-packages"): New test.
| -rw-r--r-- | guix/inferior.scm | 26 | ||||
| -rw-r--r-- | tests/inferior.scm | 22 |
2 files changed, 47 insertions, 1 deletions
diff --git a/guix/inferior.scm b/guix/inferior.scm index 6cfa146029b..027418a98de 100644 --- a/guix/inferior.scm +++ b/guix/inferior.scm | |||
| @@ -61,6 +61,7 @@ | |||
| 61 | inferior-object? | 61 | inferior-object? |
| 62 | 62 | ||
| 63 | inferior-packages | 63 | inferior-packages |
| 64 | inferior-available-packages | ||
| 64 | lookup-inferior-packages | 65 | lookup-inferior-packages |
| 65 | 66 | ||
| 66 | inferior-package? | 67 | inferior-package? |
| @@ -256,6 +257,31 @@ equivalent. Return #f if the inferior could not be launched." | |||
| 256 | vlist-null | 257 | vlist-null |
| 257 | (inferior-packages inferior))) | 258 | (inferior-packages inferior))) |
| 258 | 259 | ||
| 260 | (define (inferior-available-packages inferior) | ||
| 261 | "Return the list of name/version pairs corresponding to the set of packages | ||
| 262 | available in INFERIOR. | ||
| 263 | |||
| 264 | This is faster and requires less resource-intensive than calling | ||
| 265 | 'inferior-packages'." | ||
| 266 | (if (inferior-eval '(defined? 'fold-available-packages) | ||
| 267 | inferior) | ||
| 268 | (inferior-eval '(fold-available-packages | ||
| 269 | (lambda* (name version result | ||
| 270 | #:key supported? deprecated? | ||
| 271 | #:allow-other-keys) | ||
| 272 | (if (and supported? (not deprecated?)) | ||
| 273 | (acons name version result) | ||
| 274 | result)) | ||
| 275 | '()) | ||
| 276 | inferior) | ||
| 277 | |||
| 278 | ;; As a last resort, if INFERIOR is old and lacks | ||
| 279 | ;; 'fold-available-packages', fall back to 'inferior-packages'. | ||
| 280 | (map (lambda (package) | ||
| 281 | (cons (inferior-package-name package) | ||
| 282 | (inferior-package-version package))) | ||
| 283 | (inferior-packages inferior)))) | ||
| 284 | |||
| 259 | (define* (lookup-inferior-packages inferior name #:optional version) | 285 | (define* (lookup-inferior-packages inferior name #:optional version) |
| 260 | "Return the sorted list of inferior packages matching NAME in INFERIOR, with | 286 | "Return the sorted list of inferior packages matching NAME in INFERIOR, with |
| 261 | highest version numbers first. If VERSION is true, return only packages with | 287 | highest version numbers first. If VERSION is true, return only packages with |
diff --git a/tests/inferior.scm b/tests/inferior.scm index d5a894ca8ff..71ebf8f59be 100644 --- a/tests/inferior.scm +++ b/tests/inferior.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2018, 2019 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; | 3 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 4 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 5 | ;;; |
| @@ -89,6 +89,26 @@ | |||
| 89 | (close-inferior inferior) | 89 | (close-inferior inferior) |
| 90 | result)))) | 90 | result)))) |
| 91 | 91 | ||
| 92 | (test-equal "inferior-available-packages" | ||
| 93 | (take (sort (fold-available-packages | ||
| 94 | (lambda* (name version result | ||
| 95 | #:key supported? deprecated? | ||
| 96 | #:allow-other-keys) | ||
| 97 | (if (and supported? (not deprecated?)) | ||
| 98 | (alist-cons name version result) | ||
| 99 | result)) | ||
| 100 | '()) | ||
| 101 | (lambda (x y) | ||
| 102 | (string<? (car x) (car y)))) | ||
| 103 | 10) | ||
| 104 | (let* ((inferior (open-inferior %top-builddir | ||
| 105 | #:command "scripts/guix")) | ||
| 106 | (packages (inferior-available-packages inferior))) | ||
| 107 | (close-inferior inferior) | ||
| 108 | (take (sort packages (lambda (x y) | ||
| 109 | (string<? (car x) (car y)))) | ||
| 110 | 10))) | ||
| 111 | |||
| 92 | (test-equal "lookup-inferior-packages" | 112 | (test-equal "lookup-inferior-packages" |
| 93 | (let ((->list (lambda (package) | 113 | (let ((->list (lambda (package) |
| 94 | (list (package-name package) | 114 | (list (package-name package) |
