summaryrefslogtreecommitdiff
path: root/gnu/packages.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/packages.scm')
-rw-r--r--gnu/packages.scm50
1 files changed, 49 insertions, 1 deletions
diff --git a/gnu/packages.scm b/gnu/packages.scm
index d22c992bb1..c0b527acf0 100644
--- a/gnu/packages.scm
+++ b/gnu/packages.scm
@@ -4,6 +4,7 @@
;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2016, 2017 Alex Kost <alezost@gmail.com>
;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
+;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -64,7 +65,8 @@
specification->location
specifications->manifest
- generate-package-cache))
+ generate-package-cache
+ generate-package-metadata-cache))
;;; Commentary:
;;;
@@ -426,6 +428,52 @@ reducing the memory footprint."
#:opts '(#:to-file? #t)))))
cache-file)
+(define %package-metadata-cache-file
+ ;; Location of the package metadata cache.
+ "/lib/guix/package-metadata.cache")
+
+(define (generate-package-metadata-cache directory)
+ "Generate under DIRECTORY a cache of the metadata of all available packages.
+
+The primary purpose of this cache is to speed up package metadata lookup
+during package search so that we don't have to traverse and load all the
+package modules."
+ (define cache-file
+ (string-append directory %package-metadata-cache-file))
+
+ (define (package<? p1 p2)
+ (string<? (package-full-name p1) (package-full-name p2)))
+
+ (define (expand-cache package result)
+ (cons `#(,(package-name package)
+ ,(package-version package)
+ ,(delete-duplicates
+ (map package-full-name
+ (sort (filter package? (package-direct-inputs package))
+ package<?)))
+ ,(package-outputs package)
+ ,(package-supported-systems package)
+ ,(package-synopsis package)
+ ,(package-description package)
+ ,(package-home-page package)
+ ,(let ((location (package-location package)))
+ (list (location-file location)
+ (location-line location)
+ (location-column location))))
+ result))
+
+ (define exp
+ (fold-packages expand-cache '()))
+
+ (mkdir-p (dirname cache-file))
+ (call-with-output-file cache-file
+ (lambda (port)
+ (put-bytevector port
+ (compile `'(,@exp)
+ #:to 'bytecode
+ #:opts '(#:to-file? #t)))))
+ cache-file)
+
(define %sigint-prompt
;; The prompt to jump to upon SIGINT.