From: "Ludovic Courtès" <ludo@gnu.org>
To: 34060@debbugs.gnu.org
Subject: [bug#34060] [PATCH 09/10] guix package: '--list-available' can use data from the cache.
Date: Sun, 13 Jan 2019 16:47:32 +0100 [thread overview]
Message-ID: <20190113154733.29737-9-ludo@gnu.org> (raw)
In-Reply-To: <20190113154733.29737-1-ludo@gnu.org>
* 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.
---
gnu/packages.scm | 45 ++++++++++++++++++++++++++++++++++++++++
guix/scripts/package.scm | 45 ++++++++++++++++++++++------------------
tests/packages.scm | 22 ++++++++++++++++++++
3 files changed, 92 insertions(+), 20 deletions(-)
diff --git a/gnu/packages.scm b/gnu/packages.scm
index cf655e7448..a1814205f9 100644
--- a/gnu/packages.scm
+++ b/gnu/packages.scm
@@ -53,6 +53,7 @@
%default-package-module-path
fold-packages
+ fold-available-packages
find-packages-by-name
find-package-locations
@@ -182,6 +183,50 @@ flags."
directory))
%load-path)))
+(define (fold-available-packages proc init)
+ "Fold PROC over the list of available packages. For each available package,
+PROC is called along these lines:
+
+ (PROC NAME VERSION RESULT
+ #:outputs OUTPUTS
+ #:location LOCATION
+ …)
+
+PROC can use #:allow-other-keys to ignore the bits it's not interested in.
+When a package cache is available, this procedure does not actually load any
+package module."
+ (define cache
+ (load-package-cache (current-profile)))
+
+ (if (and cache (cache-is-authoritative?))
+ (vhash-fold (lambda (name vector result)
+ (match vector
+ (#(name version module symbol outputs
+ supported? deprecated?
+ file line column)
+ (proc name version result
+ #:outputs outputs
+ #:location (and file
+ (location file line column))
+ #:supported? supported?
+ #:deprecated? deprecated?))))
+ init
+ cache)
+ (fold-packages (lambda (package result)
+ (proc (package-name package)
+ (package-version package)
+ result
+ #:outputs (package-outputs package)
+ #:location (package-location package)
+ #:supported?
+ (->bool
+ (member (%current-system)
+ (package-supported-systems package)))
+ #:deprecated?
+ (->bool
+ (package-superseded package))))
+ init)))
+
(define* (fold-packages proc init
#:optional
(modules (all-modules (%package-module-path)
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 4f483ac141..e6f633b630 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -741,29 +741,34 @@ processed, #f otherwise."
(('list-available regexp)
(let* ((regexp (and regexp (make-regexp* regexp)))
- (available (fold-packages
- (lambda (p r)
- (let ((n (package-name p)))
- (if (and (supported-package? p)
- (not (package-superseded p)))
- (if regexp
- (if (regexp-exec regexp n)
- (cons p r)
- r)
- (cons p r))
- r)))
+ (available (fold-available-packages
+ (lambda* (name version result
+ #:key outputs location
+ supported? superseded?
+ #:allow-other-keys)
+ (if (and supported? (not superseded?))
+ (if regexp
+ (if (regexp-exec regexp name)
+ (cons `(,name ,version
+ ,outputs ,location)
+ result)
+ result)
+ (cons `(,name ,version
+ ,outputs ,location)
+ result))
+ result))
'())))
(leave-on-EPIPE
- (for-each (lambda (p)
- (format #t "~a\t~a\t~a\t~a~%"
- (package-name p)
- (package-version p)
- (string-join (package-outputs p) ",")
- (location->string (package-location p))))
+ (for-each (match-lambda
+ ((name version outputs location)
+ (format #t "~a\t~a\t~a\t~a~%"
+ name version
+ (string-join outputs ",")
+ (location->string location))))
(sort available
- (lambda (p1 p2)
- (string<? (package-name p1)
- (package-name p2))))))
+ (match-lambda*
+ (((name1 . _) (name2 . _))
+ (string<? name1 name2))))))
#t))
(('search _)
diff --git a/tests/packages.scm b/tests/packages.scm
index 8aa117a2e7..ed635d9011 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -995,6 +995,28 @@
((one)
(eq? one guile-2.0))))
+(test-assert "fold-available-packages with/without cache"
+ (let ()
+ (define no-cache
+ (fold-available-packages (lambda* (name version result #:rest rest)
+ (cons (cons* name version rest)
+ result))
+ '()))
+
+ (define from-cache
+ (call-with-temporary-directory
+ (lambda (cache)
+ (generate-package-cache cache)
+ (mock ((guix describe) current-profile (const cache))
+ (mock ((gnu packages) cache-is-authoritative? (const #t))
+ (fold-available-packages (lambda* (name version result
+ #:rest rest)
+ (cons (cons* name version rest)
+ result))
+ '()))))))
+
+ (lset= equal? no-cache from-cache)))
+
(test-assert "find-packages-by-name"
(match (find-packages-by-name "hello")
(((? (cut eq? hello <>))) #t)
--
2.20.1
next prev parent reply other threads:[~2019-01-13 15:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-13 15:45 [bug#34060] [PATCH 00/10] Add a cache for package lookups Ludovic Courtès
2019-01-13 15:47 ` [bug#34060] [PATCH 01/10] profiling: Add a "gc" profiling component Ludovic Courtès
2019-01-13 15:47 ` [bug#34060] [PATCH 02/10] guix package: Avoid 'find-newest-available-packages' Ludovic Courtès
2019-01-13 15:47 ` [bug#34060] [PATCH 03/10] packages: Remove 'find-newest-available-packages' Ludovic Courtès
2019-01-13 15:47 ` [bug#34060] [PATCH 04/10] inferior: Add 'gexp->derivation-in-inferior' Ludovic Courtès
2019-01-13 15:47 ` [bug#34060] [PATCH 05/10] discovery: Add 'fold-module-public-variables*' Ludovic Courtès
2019-01-13 15:47 ` [bug#34060] [PATCH 06/10] pull: Build profile with 'channel-instances->derivation' Ludovic Courtès
2019-01-15 19:27 ` Ludovic Courtès
2019-01-13 15:47 ` [bug#34060] [PATCH 07/10] channels: Compute a package cache and use it Ludovic Courtès
2019-01-13 15:47 ` [bug#34060] [PATCH 08/10] edit: Use 'specification->location' to read information from the cache Ludovic Courtès
2019-01-13 15:47 ` Ludovic Courtès [this message]
2019-01-13 15:47 ` [bug#34060] [PATCH 10/10] status: Distinguish 'package-cache' profile hook Ludovic Courtès
2019-01-15 19:26 ` bug#34060: [PATCH 00/10] Add a cache for package lookups Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190113154733.29737-9-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=34060@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.