Sean Whitton <spwhit...@spwhitton.name> writes:

> Hello,
>
> On Sun 20 Jul 2025 at 11:00am -07, Xiyue Deng wrote:
>
>> Hi Sean,
>>
>> Sean Whitton <spwhit...@spwhitton.name> writes:
>>
>>> Hello Xiyue,
>>>
>>> Thanks.  I think you sent the wrong patches
>>
>> Oops, sorry.
>>
>>> but I had a look at your
>>> branch on salsa.  This still isn't quite what I mean.  I think that
>>>
>>> - you should be using the Emacs built binary (as you are now doing)
>>> - we should not commit the file emacs-common-substvars to git.
>>>   Instead it should be generated during the build.
>>>
>>> So the main thing missing is that the generating of the file should be
>>> incorporated into the build.  Probably it should go into the existing
>>> override_dh_auto_install.
>>>
>>
>> I understand that this file is mostly useful during package building.
>> Still, I'd like to give another try to propose to have
>> debian/emacs-common-substvars committed in git: this will help with
>> debugging in the following scenarios:
>>
>> * When we want to understand why some packages are (or not) being
>>   replaces by Emacs, and
>>
>> * When we want to see what packages are updated between Emacs releases
>>   (which is also why I put a package+version per line in the comments).
>>
>> Without this file, we need to get this information from `apt show' or
>> from https://packages.debian.org/ which would be very cumbersome and
>> hard to get it right.
>
> I don't mind also committing the information in a text file somewhere
> (with a version annotation), but the substvar generation should be
> wholly dynamic.
>

Indeed.  I also realized that the file generated during build only
exists during build, so the version information file needs to be
generated outside of building (like in debian-sync), so I'll leave that
for now.

I have now updated the generation script and introduced arguments to
switch output format.  It now supports output as substvars or in JSON as
information, and debian/rules is updated accordingly.  I have also
removed the debian/emacs-common-substvars now that it's only used during
build.

For the JSON information I'll send another set of patches after
1:30.1+1-7 is released (as it requires the backported package
functions), and integrate it in `debian-sync' rule.

My branch is updated accordingly (now 3 commits)[1].  Patches also
attached.

> -- 
> Sean Whitton

[1] 
https://salsa.debian.org/manphiz/deb-emacs/-/compare/deb%2Femacs%2Fd%2Fsid%2Fmaster...generate-provide-package-list?from_project_id=83361

-- 
Regards,
Xiyue Deng
From 30cded35d54b015e6634be1c270f426207f3ec8a Mon Sep 17 00:00:00 2001
From: Xiyue Deng <manp...@gmail.com>
Date: Mon, 16 Jun 2025 17:09:48 -0700
Subject: [PATCH 1/3] Add script to generate Emacs builtin packages information

- Support output in human readable JSON format or as substvars
---
 debian/generate-emacs-builtin-package-info.el | 109 ++++++++++++++++++
 1 file changed, 109 insertions(+)
 create mode 100644 debian/generate-emacs-builtin-package-info.el

diff --git a/debian/generate-emacs-builtin-package-info.el b/debian/generate-emacs-builtin-package-info.el
new file mode 100644
index 00000000000..8292df5dccf
--- /dev/null
+++ b/debian/generate-emacs-builtin-package-info.el
@@ -0,0 +1,109 @@
+;; Emacs script to generate a package provide list -*- lexical-binding:t -*-
+(require 'json)
+(require 'package)
+
+(defvar package-skip-list
+  '("elpa-emacs")
+  "A list of package that should be skipped in the provide list")
+
+(defun package-version-list-to-string (package-version-list)
+  "Convert a package version list to version string acceptable in Debian."
+  (when package-version-list
+    (let ((count 0)
+          version-list)
+      (dolist (item package-version-list)
+        (progn
+          (if (< item 0)
+              (progn
+                ;; This roughly matches the mapping in
+                ;; version-regexp-alist.
+                (cl-case item
+                  (-1 (push "~rc" version-list))
+                  (-2 (push "~beta" version-list))
+                  (-3 (push "~alpha" version-list))
+                  (-4 (push "~snapshot" version-list))
+                  (t (error "Unknown version: %d" item)))
+                ;; no "." between prerelease name and number
+                (setq count 0))
+            (when (> count 0)
+              (push "." version-list))
+            (push (number-to-string item) version-list)
+            (cl-incf count))))
+      (string-join (nreverse version-list)))))
+
+(defun emacs-provided-package-versions ()
+  "Return an alist of Debian package name to version mapping."
+  (let (emacs-provided-package-versions)
+    (mapc (lambda (package-name)
+            (let* ((debian-package-name (concat "elpa-"
+                                                (symbol-name package-name)))
+                   (debian-package-version (package-version-list-to-string
+                                            (package-builtin-package-version
+                                             package-name))))
+              (when (not (member debian-package-name package-skip-list))
+                (push `(,debian-package-name . ,debian-package-version)
+                      emacs-provided-package-versions))))
+          (package-versioned-builtin-packages))
+    (sort emacs-provided-package-versions)))
+
+(defun print-help ()
+  "Print help info"
+  (message "Generate information for Emacs built-in packages.  Please use the following options:
+	--json		Generate a report in human readable JSON format
+	--substvars	Generate substvars for Emacs build process
+	--script-help	This help info
+"))
+
+(defun generate-builtin-package-info-json ()
+  "Generate Emacs built-in-package info report in JSON format."
+  (princ (format "%s\n"
+                 (with-temp-buffer
+                   (insert (json-encode (emacs-provided-package-versions)))
+                   (json-pretty-print-buffer)
+                   (buffer-string)))))
+
+(defun generate-builtin-package-info-substvars ()
+  "Generate Emacs built-in package info as substvars for emacs-common."
+  (let (provides-substvars-list
+        replaces-substvars-list
+        (count 0))
+    (mapc (lambda (package-version)
+            (let* ((name (car package-version))
+                   (version (cdr package-version))
+                   (provides-entry-string (concat name
+                                                  (when version
+                                                    (format " (= %s)" version))
+                                                  ","))
+                   (replaces-entry-string (concat name
+                                                  (when version
+                                                    (format " (<< %s)" version))
+                                                  ",")))
+              (when (> count 0)
+                (push " " provides-substvars-list)
+                (push " " replaces-substvars-list))
+              (push provides-entry-string provides-substvars-list)
+              (push replaces-entry-string replaces-substvars-list)
+              (cl-incf count)))
+          (emacs-provided-package-versions))
+    (let ((debian-provides-substvars-string
+           (string-join (nreverse provides-substvars-list)))
+          (debian-replaces-substvars-string
+           (string-join (nreverse replaces-substvars-list))))
+      (princ (format "emacs:Provides=%s\n" debian-provides-substvars-string))
+      (princ (format "emacs:Breaks=%s\n" debian-replaces-substvars-string))
+      (princ (format "emacs:Replaces=%s\n" debian-replaces-substvars-string)))))
+
+(defun main ()
+  "Main program entrance."
+  (if (not argv)
+      (print "Missing argument.  Should specify \"--report\" or \"--substvars\"."
+             #'external-debugging-output)
+    (let ((option (elt argv 0)))
+      (pcase option
+        ("--json" (generate-builtin-package-info-json))
+        ("--substvars" (generate-builtin-package-info-substvars))
+        ("--script-help" (print-help))
+        (_ (error "Unknown option \"%s\"." option)))))
+  (kill-emacs 0))
+
+(main)
-- 
2.50.0

From 99b880478de2756bf48c38558b9102f0b62b5a98 Mon Sep 17 00:00:00 2001
From: Xiyue Deng <manp...@gmail.com>
Date: Wed, 18 Jun 2025 13:28:04 -0700
Subject: [PATCH 2/3] Add rule to generate substvars for emacs-common in
 debian/rules

- This is done by generating a temporary debian/emacs-common-substvars
file during installation and append that into
debian/emacs-common.substvars in override_dh_gencontrol.
---
 debian/rules | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/debian/rules b/debian/rules
index 18de17ac996..efcac98349a 100755
--- a/debian/rules
+++ b/debian/rules
@@ -221,6 +221,10 @@ check-vars:
 .PHONY: check-autogen
 check-autogen: $(persistent_autogen_files) $(nonpersistent_autogen_files)
 
+.PHONY: debian/emacs-common-substvars
+debian/emacs-common-substvars:
+	debian/build-nox/src/emacs -Q --script debian/generate-emacs-builtin-package-info.el --substvars > debian/emacs-common-substvars
+
 debian-sync: $(persistent_autogen_files)
         # so dh pattern rule doesn't try to handle this target
 	true
@@ -405,7 +409,7 @@ define install_common_binpkg_bits
 
 endef
 
-override_dh_auto_install: $(autogen_install_files)
+override_dh_auto_install: $(autogen_install_files) debian/emacs-common-substvars
 	rm -rf \
 	  $(install_dir_gtk) $(install_dir_pgtk) \
 	  $(install_dir_nox) $(install_dir_lucid) \
@@ -613,6 +617,10 @@ override_dh_auto_install: $(autogen_install_files)
 	rm -rf $(install_dir_nox)
 	rm -rf $(install_dir_lucid)
 
+# Add generated emacs:Provides to substvars
+execute_before_dh_gencontrol:
+	cat debian/emacs-common-substvars >> debian/emacs-common.substvars
+
 # Install the per-user systemd unit in a disabled state by default.
 override_dh_installsystemduser:
 	dh_installsystemduser --no-enable
-- 
2.50.0

From 58a635ed81a00c418743a07bcf515ab2df428e9a Mon Sep 17 00:00:00 2001
From: Xiyue Deng <manp...@gmail.com>
Date: Tue, 15 Jul 2025 15:50:22 -0700
Subject: [PATCH 3/3] Use substvars in emacs-common in debian/control

- This replaces the explicitly generated list of built-in package info.
---
 debian/control | 231 +------------------------------------------------
 1 file changed, 3 insertions(+), 228 deletions(-)

diff --git a/debian/control b/debian/control
index ce2420ab70f..2a1364ffd54 100644
--- a/debian/control
+++ b/debian/control
@@ -191,237 +191,12 @@ Breaks:
  emacs-gtk (<< 1:25),
  emacs-lucid (<< 1:25),
  emacs-nox (<< 1:25),
- elpa-allout (<< 2.3),
- elpa-allout-widgets (<< 1.0),
- elpa-ansi-color (<< 3.4.2),
- elpa-antlr-mode (<< 2.2.3),
- elpa-auth-source-pass (<< 5.0.0),
- elpa-backtrace (<< 1.0),
- elpa-bind-key (<< 2.4.1),
- elpa-cc-mode (<< 5.33.1),
- elpa-cedet (<< 2.0),
- elpa-cfengine (<< 1.4),
- elpa-cl-generic (<< 1.0),
- elpa-cl-lib (<< 1.0),
- elpa-cl-print (<< 1.0),
- elpa-compat (<< 30.1.9999),
- elpa-ede (<< 2.0),
- elpa-ediff (<< 2.81.6),
- elpa-editorconfig (<< 0.11.0),
- elpa-eglot (<< 1.17.30),
- elpa-eieio (<< 1.4),
- elpa-eieio-core (<< 1.4),
- elpa-eldoc (<< 1.15.0),
- elpa-epg (<< 1.0.0),
- elpa-erc (<< 5.6.0.30.1),
- elpa-eshell (<< 2.4.2),
- elpa-external-completion (<< 0.1),
- elpa-faceup (<< 0.0.6),
- elpa-feedmail (<< 11),
- elpa-find-cmd (<< 0.6),
- elpa-flymake (<< 1.3.7),
- elpa-flymake-proc (<< 1.0),
- elpa-foldout (<< 1.10),
- elpa-gnus (<< 5.13),
- elpa-idlwave (<< 6.1.22),
- elpa-image-dired (<< 0.5),
- elpa-info-xref (<< 3),
- elpa-isearchb (<< 1.5),
- elpa-js (<< 9),
- elpa-json (<< 1.5),
- elpa-jsonrpc (<< 1.0.25),
- elpa-let-alist (<< 1.0.6),
- elpa-map (<< 3.3.1),
- elpa-meta-mode (<< 1.0),
- elpa-mh-e (<< 8.6~snapshot),
- elpa-mixal-mode (<< 0.4),
- elpa-nadvice (<< 1.0),
- elpa-ntlm (<< 2.1.0),
- elpa-org (<< 9.7.11),
- elpa-package (<< 1.1.0),
- elpa-peg (<< 1.0.1),
- elpa-project (<< 0.11.1),
- elpa-ps-mode (<< 1.1.9),
- elpa-pulse (<< 1.0),
- elpa-python (<< 0.28),
- elpa-ruby-mode (<< 1.2),
- elpa-ruby-ts-mode (<< 0.2),
- elpa-semantic (<< 2.2),
- elpa-seq (<< 2.24),
- elpa-so-long (<< 1.1.2),
- elpa-soap-client (<< 3.2.3),
- elpa-sql (<< 3.6),
- elpa-srecode (<< 1.2),
- elpa-svg (<< 1.1),
- elpa-tabulated-list (<< 1.0),
- elpa-thunk (<< 1.0),
- elpa-tildify (<< 4.6.1),
- elpa-track-changes (<< 1.2),
- elpa-tramp (<< 2.7.1.30.1),
- elpa-transient (<< 0.7.2.2),
- elpa-use-package (<< 2.4.6),
- elpa-vera-mode (<< 2.28),
- elpa-verilog-mode (<< 2024.3.1.121933719),
- elpa-viper (<< 3.14.2),
- elpa-which-key (<< 3.6.0),
- elpa-whitespace (<< 13.2.2),
- elpa-window-tool-bar (<< 0.2.1),
- elpa-xref (<< 1.7.0),
+ ${emacs:Breaks}
 Replaces:
  emacs-bin-common (<< 1:28),
- elpa-allout (<< 2.3),
- elpa-allout-widgets (<< 1.0),
- elpa-ansi-color (<< 3.4.2),
- elpa-antlr-mode (<< 2.2.3),
- elpa-auth-source-pass (<< 5.0.0),
- elpa-backtrace (<< 1.0),
- elpa-bind-key (<< 2.4.1),
- elpa-cc-mode (<< 5.33.1),
- elpa-cedet (<< 2.0),
- elpa-cfengine (<< 1.4),
- elpa-cl-generic (<< 1.0),
- elpa-cl-lib (<< 1.0),
- elpa-cl-print (<< 1.0),
- elpa-compat (<< 30.1.9999),
- elpa-ede (<< 2.0),
- elpa-ediff (<< 2.81.6),
- elpa-editorconfig (<< 0.11.0),
- elpa-eglot (<< 1.17.30),
- elpa-eieio (<< 1.4),
- elpa-eieio-core (<< 1.4),
- elpa-eldoc (<< 1.15.0),
- elpa-epg (<< 1.0.0),
- elpa-erc (<< 5.6.0.30.1),
- elpa-eshell (<< 2.4.2),
- elpa-external-completion (<< 0.1),
- elpa-faceup (<< 0.0.6),
- elpa-feedmail (<< 11),
- elpa-find-cmd (<< 0.6),
- elpa-flymake (<< 1.3.7),
- elpa-flymake-proc (<< 1.0),
- elpa-foldout (<< 1.10),
- elpa-gnus (<< 5.13),
- elpa-idlwave (<< 6.1.22),
- elpa-image-dired (<< 0.5),
- elpa-info-xref (<< 3),
- elpa-isearchb (<< 1.5),
- elpa-js (<< 9),
- elpa-json (<< 1.5),
- elpa-jsonrpc (<< 1.0.25),
- elpa-let-alist (<< 1.0.6),
- elpa-map (<< 3.3.1),
- elpa-meta-mode (<< 1.0),
- elpa-mh-e (<< 8.6~snapshot),
- elpa-mixal-mode (<< 0.4),
- elpa-nadvice (<< 1.0),
- elpa-ntlm (<< 2.1.0),
- elpa-org (<< 9.7.11),
- elpa-package (<< 1.1.0),
- elpa-peg (<< 1.0.1),
- elpa-project (<< 0.11.1),
- elpa-ps-mode (<< 1.1.9),
- elpa-pulse (<< 1.0),
- elpa-python (<< 0.28),
- elpa-ruby-mode (<< 1.2),
- elpa-ruby-ts-mode (<< 0.2),
- elpa-semantic (<< 2.2),
- elpa-seq (<< 2.24),
- elpa-so-long (<< 1.1.2),
- elpa-soap-client (<< 3.2.3),
- elpa-sql (<< 3.6),
- elpa-srecode (<< 1.2),
- elpa-svg (<< 1.1),
- elpa-tabulated-list (<< 1.0),
- elpa-thunk (<< 1.0),
- elpa-tildify (<< 4.6.1),
- elpa-track-changes (<< 1.2),
- elpa-tramp (<< 2.7.1.30.1),
- elpa-transient (<< 0.7.2.2),
- elpa-use-package (<< 2.4.6),
- elpa-vera-mode (<< 2.28),
- elpa-verilog-mode (<< 2024.3.1.121933719),
- elpa-viper (<< 3.14.2),
- elpa-which-key (<< 3.6.0),
- elpa-whitespace (<< 13.2.2),
- elpa-window-tool-bar (<< 0.2.1),
- elpa-xref (<< 1.7.0),
+ ${emacs:Replaces}
 Provides:
- elpa-allout (= 2.3),
- elpa-allout-widgets (= 1.0),
- elpa-ansi-color (= 3.4.2),
- elpa-antlr-mode (= 2.2.3),
- elpa-auth-source-pass (= 5.0.0),
- elpa-backtrace (= 1.0),
- elpa-bind-key (= 2.4.1),
- elpa-cc-mode (= 5.33.1),
- elpa-cedet (= 2.0),
- elpa-cfengine (= 1.4),
- elpa-cl-generic (= 1.0),
- elpa-cl-lib (= 1.0),
- elpa-cl-print (= 1.0),
- elpa-compat (= 30.1.9999),
- elpa-ede (= 2.0),
- elpa-ediff (= 2.81.6),
- elpa-editorconfig (= 0.11.0),
- elpa-eglot (= 1.17.30),
- elpa-eieio (= 1.4),
- elpa-eieio-core (= 1.4),
- elpa-eldoc (= 1.15.0),
- elpa-epg (= 1.0.0),
- elpa-erc (= 5.6.0.30.1),
- elpa-eshell (= 2.4.2),
- elpa-external-completion (= 0.1),
- elpa-faceup (= 0.0.6),
- elpa-feedmail (= 11),
- elpa-find-cmd (= 0.6),
- elpa-flymake (= 1.3.7),
- elpa-flymake-proc (= 1.0),
- elpa-foldout (= 1.10),
- elpa-gnus (= 5.13),
- elpa-idlwave (= 6.1.22),
- elpa-image-dired (= 0.5),
- elpa-info-xref (= 3),
- elpa-isearchb (= 1.5),
- elpa-js (= 9),
- elpa-json (= 1.5),
- elpa-jsonrpc (= 1.0.25),
- elpa-let-alist (= 1.0.6),
- elpa-map (= 3.3.1),
- elpa-meta-mode (= 1.0),
- elpa-mh-e (= 8.6~snapshot),
- elpa-mixal-mode (= 0.4),
- elpa-nadvice (= 1.0),
- elpa-ntlm (= 2.1.0),
- elpa-org (= 9.7.11),
- elpa-package (= 1.1.0),
- elpa-peg (= 1.0.1),
- elpa-project (= 0.11.1),
- elpa-ps-mode (= 1.1.9),
- elpa-pulse (= 1.0),
- elpa-python (= 0.28),
- elpa-ruby-mode (= 1.2),
- elpa-ruby-ts-mode (= 0.2),
- elpa-semantic (= 2.2),
- elpa-seq (= 2.24),
- elpa-so-long (= 1.1.2),
- elpa-soap-client (= 3.2.3),
- elpa-sql (= 3.6),
- elpa-srecode (= 1.2),
- elpa-svg (= 1.1),
- elpa-tabulated-list (= 1.0),
- elpa-thunk (= 1.0),
- elpa-tildify (= 4.6.1),
- elpa-track-changes (= 1.2),
- elpa-tramp (= 2.7.1.30.1),
- elpa-transient (= 0.7.2.2),
- elpa-use-package (= 2.4.6),
- elpa-vera-mode (= 2.28),
- elpa-verilog-mode (= 2024.3.1.121933719),
- elpa-viper (= 3.14.2),
- elpa-which-key (= 3.6.0),
- elpa-whitespace (= 13.2.2),
- elpa-window-tool-bar (= 0.2.1),
- elpa-xref (= 1.7.0),
+ ${emacs:Provides}
 Description: GNU Emacs editor's shared, architecture independent infrastructure
  GNU Emacs is the extensible self-documenting text editor.
  This package contains the architecture independent infrastructure
-- 
2.50.0

Attachment: signature.asc
Description: PGP signature

Reply via email to