emacs-31 927a7fff5ec 2/2: Restore public interfaces for accessing built-in package info

Philip Kaludercic <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: emacs-31
commit 927a7fff5ecd11057665dcd9a1bf4faa5aff0a45
Author: Xiyue Deng <[email protected]>
Commit: Philip Kaludercic <[email protected]>

    Restore public interfaces for accessing built-in package info
    
    These functions were removed in ab36f5892203e4b1f59da7c995e0f1fa0a81d1b6
    during the reorganization of package.el as part of Bug#80079.
    
    Also add a simple test for these functions to avoid future regressions.
    
    See also discussion at
    https://lists.gnu.org/archive/html/emacs-devel/2026-06/msg00149.html.
    
    * lisp/emacs-lisp/package.el (package-versioned-builtin-packages,
    package-builtin-package-version): Restore.
    * lisp/emacs-lisp/package-activate.el: Remove lingering comments.
    * test/lisp/emacs-lisp/package-tests.el
    (package-test-builtin-package-info): Add.
---
 lisp/emacs-lisp/package-activate.el   |  2 --
 lisp/emacs-lisp/package.el            | 16 ++++++++++++++++
 test/lisp/emacs-lisp/package-tests.el | 11 +++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/package-activate.el b/lisp/emacs-lisp/package-activate.el
index 53a3fa30836..5e2623c57f1 100644
--- a/lisp/emacs-lisp/package-activate.el
+++ b/lisp/emacs-lisp/package-activate.el
@@ -208,8 +208,6 @@ called via `package-activate-all'.  To change which packages are
 loaded and/or activated, customize `package-load-list'.")
 (put 'package-alist 'risky-local-variable t)
 
-;;;; Public interfaces for accessing built-in package info
-
 ;;;###autoload
 (defvar package-activated-list nil
   ;; FIXME: This should implicitly include all builtin packages.
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index cd3c850f7a4..12b450d93db 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -535,6 +535,22 @@ package."
   summary)
 
 
+;;; Public interfaces for accessing built-in package info
+
+(defun package-versioned-builtin-packages ()
+  "Return a list of all the versioned built-in packages.
+The return value is a list of names of built-in packages represented as
+symbols."
+  (mapcar #'car package--builtin-versions))
+
+(defun package-builtin-package-version (package)
+  "Return the version of a built-in PACKAGE given by its symbol.
+The return value is a list of integers representing the version of
+PACKAGE, in the format returned by `version-to-list', or nil if the
+package is built-in but has no version or is not a built-in package."
+  (alist-get package package--builtin-versions))
+
+
 ;;; Installed packages
 
 ;; The following functions are called on each installed package by
diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el
index a2e4adb7b8e..b6fb9005e4c 100644
--- a/test/lisp/emacs-lisp/package-tests.el
+++ b/test/lisp/emacs-lisp/package-tests.el
@@ -1028,6 +1028,17 @@ but with a different end of line convention (bug#48137)."
             (list new-pkg-desc simple-depend-desc-2 simple-depend-desc-1
                   multi-file-desc simple-depend-desc simple-single-desc)))))
 
+(ert-deftest package-test-builtin-package-info ()
+  "Test public interfaces for querying package info."
+  (should (not (null (package-versioned-builtin-packages))))
+  ;; Picking any built-in library to check the version. Update results
+  ;; as needed.
+  (require 'lisp-mnt)
+  (should (equal (package-builtin-package-version 'cl-lib)
+                 (with-temp-buffer
+                   (insert-file-contents (locate-library "cl-lib.el"))
+                   (version-to-list (lm-version))))))
+
 (provide 'package-test)
 
 ;;; package-tests.el ends here
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.