Subject: [bug#39258] [PATCH v6 1/2] DRAFT packages: Add fields to packages cache.

From: zimoun <[email-masked]>
Date: Thu, 15 Jul 2021 09:33:27 +0200

* gnu/packages.scm (generate-package-cache)[expand-cache]: Add synopsis and
description.
(load-package-cache, find-packages-by-names, find-packages-locations): Adapt
accordingly.
(fold-available-packages): Add synopsis, description, module and symbol when
cache is authoritative.  Replace 'fold-packages' by
'fold-module-public-variables*' when cache is not authoritative.
---
 gnu/packages.scm | 52 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/gnu/packages.scm b/gnu/packages.scm
index ccfc83dd11..34c6d73b86 100644
--- a/gnu/packages.scm
+++ b/gnu/packages.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2014 Eric Bavier <[email-masked]>
 ;;; Copyright © 2016, 2017 Alex Kost <[email-masked]>
 ;;; Copyright © 2016 Mathieu Lirzin <[email-masked]>
+;;; Copyright © 2021 Simon Tournier <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -211,28 +212,45 @@ package module."
       (vhash-fold (lambda (name vector result)
                     (match vector
                       (#(name version module symbol outputs
+                              synopsis description
                               supported? deprecated?
                               file line column)
                        (proc name version result
                              #:outputs outputs
+                             #:synopsis synopsis
+                             #:description description
                              #:location (and file
                                              (location file line column))
+                             #:module module
+                             #:symbol symbol
                              #: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 (supported-package? package))
-                             #:deprecated?
-                             (->bool
-                              (package-superseded package))))
-                     init)))
+      (fold-module-public-variables*
+       (lambda (module symbol variable result)
+         (let ((package (false-if-exception
+                         (variable-ref variable))))
+           (if (package? package)
+               (proc (package-name package)
+                     (package-version package)
+                     result
+                     #:outputs (package-outputs package)
+                     #:synopsis (package-synopsis package)
+                     #:description (package-description package)
+                     #:location (package-location package)
+                     #:module (module-name module)
+                     #:symbol symbol
+                     #:supported?
+                     (->bool (supported-package? package))
+                     #:deprecated?
+                     (->bool
+                      (package-superseded package)))
+               result)))
+       init
+       (all-modules (%package-module-path)
+                    #:warn
+                    warn-about-load-error))))
 
 (define* (fold-packages proc init
                         #:optional
@@ -268,6 +286,7 @@ package names.  Return #f on failure."
            (fold (lambda (item vhash)
                    (match item
                      (#(name version module symbol outputs
+                             synopsis description
                              supported? deprecated?
                              file line column)
                       (vhash-cons name item vhash))))
@@ -316,7 +335,7 @@ decreasing version order."
   (if (and (cache-is-authoritative?) cache)
       (match (cache-lookup cache name)
         (#f #f)
-        ((#(_ versions modules symbols _ _ _ _ _ _) ...)
+        ((#(_ versions modules symbols _ _ _ _ _ _ _ _) ...)
          (fold (lambda (version* module symbol result)
                  (if (or (not version)
                          (version-prefix? version version*))
@@ -337,9 +356,8 @@ matching NAME and VERSION."
   (if (and cache (cache-is-authoritative?))
       (match (cache-lookup cache name)
         (#f '())
-        ((#(name versions modules symbols outputs
-                 supported? deprecated?
-                 files lines columns) ...)
+        ((#(_ versions _ _ _ _ _ _ _
+              files lines columns) ...)
          (fold (lambda (version* file line column result)
                  (if (and file
                           (or (not version)
@@ -393,6 +411,8 @@ reducing the memory footprint."
                             ,(module-name module)
                             ,symbol
                             ,(package-outputs package)
+                            ,(package-synopsis package)
+                            ,(package-description package)
                             ,(->bool (supported-package? package))
                             ,(->bool (package-superseded package))
                             ,@(let ((loc (package-location package)))
-- 
2.32.0