Subject: bug#78844: 30.1; feature request: public interface for querying builtin packages and versions

From: Xiyue Deng <[email-masked]>
Date: Tue, 24 Jun 2025 16:45:29 -0700

Hi Stefan,

Stefan Monnier <[email-masked]> writes:

>> This is mainly used for external tooling.  Having a list of
>> bundled/builtin packages and versions can help distribution package
>> manager, e.g. APT in Debian, to manage dependencies easier (as mentioned
>> in my first email).  We need to generate the package information and
>> store it in the Debian package info for those tools to use as they
>> cannot query Emacs in runtime.
>
> Ah, I see, so you really want to export the whole of
> `package--builtin-versions` rather than just the list of builtin
> packages.  This way you can later test for specific packages and/or
> versions without running Emacs (modulo compatibility between Emacs's
> notion of ordering between versions and that of what your external tool
> uses).
>

Exactly.  Thanks for confirming!

Updated patch attached.

>         Stefan

-- 
Regards,
Xiyue Deng
From fdc99549a581f34fe2d7e6c87b636f3e188a2514 Mon Sep 17 00:00:00 2001
From: Xiyue Deng <[email-masked]>
Date: Fri, 20 Jun 2025 21:34:45 -0700
Subject: [PATCH] Add public interfaces for accessing builtin package info
 (Bug#78844)

* lisp/emacs-lisp/package.el (package-builtin-packages): Add
* lisp/emacs-lisp/package.el (package-builtin-package-version): Add
---
 lisp/emacs-lisp/package.el | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 82fcf439a11..03a03bf4c04 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -669,6 +669,20 @@ package-alist
 loaded and/or activated, customize `package-load-list'.")
 (put 'package-alist 'risky-local-variable t)
 
+;;;; Public interfaces for accessing built-in package info
+
+(defun package-builtin-packages ()
+  "Return a list of builtin package symbols.
+The returned list is not guaranteed to be sorted."
+  (mapcar #'car package--builtin-versions))
+
+(defun package-builtin-package-version (package)
+  "Return the version-list of PACKAGE (symbol).
+The format of the returned version-list is as returned by the
+`version-to-list' function.  Returns nil if the package is not a builtin
+package or does not have a version."
+  (alist-get package package--builtin-versions))
+
 ;;;###autoload
 (defvar package-activated-list nil
   ;; FIXME: This should implicitly include all builtin packages.
-- 
2.47.2