From ad432c1644e27976c579a998a08752a55ffcafa1 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 11 Jun 2022 17:59:23 +0200 Subject: [PATCH] Fix loaddefs installation of packages with no autoloads * lisp/emacs-lisp/loaddefs-gen.el (loaddefs-generate): Always generate an output file if we have EXTRA-DATA. This fixes package installation of packages with no ;;;###autoload forms. --- lisp/emacs-lisp/loaddefs-gen.el | 112 ++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 50 deletions(-) diff --git a/lisp/emacs-lisp/loaddefs-gen.el b/lisp/emacs-lisp/loaddefs-gen.el index 5280941cfcd..95666ddb2a0 100644 --- a/lisp/emacs-lisp/loaddefs-gen.el +++ b/lisp/emacs-lisp/loaddefs-gen.el @@ -514,7 +514,9 @@ its autoloads into the specified file instead. The function does NOT recursively descend into subdirectories of the directory or directories specified. -If EXTRA-DATA, include this string at the start of the generated file. +If EXTRA-DATA, include this string at the start of the generated +file. This will also force generation of OUTPUT-FILE even if +there are no autoloads to put into the file. If INCLUDE-PACKAGE-VERSION, include package version data. @@ -562,56 +564,66 @@ If GENERATE-FULL, don't update, but regenerate all the loaddefs files." defs)))) (progress-reporter-done progress)) - ;; Generate the loaddef files. First group per output file. - (dolist (fdefs (seq-group-by #'car defs)) - (let ((loaddefs-file (car fdefs))) + ;; If we have no autoloads data, but we have EXTRA-DATA, then + ;; generate the (almost) empty file anyway. + (if (and (not defs) extra-data) (with-temp-buffer - (if (and updating (file-exists-p loaddefs-file)) - (insert-file-contents loaddefs-file) - (insert (loaddefs-generate--rubric loaddefs-file nil t)) - (search-backward "\f") - (when extra-data - (insert extra-data) - (ensure-empty-lines 1))) - ;; Then group by source file (and sort alphabetically). - (dolist (section (sort (seq-group-by #'cadr (cdr fdefs)) - (lambda (e1 e2) - (string< - (file-name-sans-extension - (file-name-nondirectory (car e1))) - (file-name-sans-extension - (file-name-nondirectory (car e2))))))) - (pop section) - (let* ((relfile (file-relative-name - (cadar section) - (file-name-directory loaddefs-file))) - (head (concat "\n\f\n;;; Generated autoloads from " - relfile "\n\n"))) - (when (file-exists-p loaddefs-file) - ;; If we're updating an old loaddefs file, then see if - ;; there's a section here for this file already. - (goto-char (point-min)) - (if (not (search-forward head nil t)) - ;; It's a new file; put the data at the end. - (progn - (goto-char (point-max)) - (search-backward "\f\n")) - ;; Delete the old version of the section. - (delete-region (match-beginning 0) - (and (search-forward "\n\f\n;;;") - (match-beginning 0))) - (forward-line -2))) - (insert head) - (dolist (def (reverse section)) - (setq def (caddr def)) - (if (stringp def) - (princ def (current-buffer)) - (loaddefs-generate--print-form def)) - (unless (bolp) - (insert "\n"))))) - (write-region (point-min) (point-max) loaddefs-file nil 'silent) - (byte-compile-info (file-relative-name loaddefs-file lisp-directory) - t "GEN")))))) + (insert (loaddefs-generate--rubric output-file nil t)) + (search-backward "\f") + (insert extra-data) + (ensure-empty-lines 1) + (write-region (point-min) (point-max) output-file nil 'silent)) + ;; We have some data, so generate the loaddef files. First + ;; group per output file. + (dolist (fdefs (seq-group-by #'car defs)) + (let ((loaddefs-file (car fdefs))) + (with-temp-buffer + (if (and updating (file-exists-p loaddefs-file)) + (insert-file-contents loaddefs-file) + (insert (loaddefs-generate--rubric loaddefs-file nil t)) + (search-backward "\f") + (when extra-data + (insert extra-data) + (ensure-empty-lines 1))) + ;; Then group by source file (and sort alphabetically). + (dolist (section (sort (seq-group-by #'cadr (cdr fdefs)) + (lambda (e1 e2) + (string< + (file-name-sans-extension + (file-name-nondirectory (car e1))) + (file-name-sans-extension + (file-name-nondirectory (car e2))))))) + (pop section) + (let* ((relfile (file-relative-name + (cadar section) + (file-name-directory loaddefs-file))) + (head (concat "\n\f\n;;; Generated autoloads from " + relfile "\n\n"))) + (when (file-exists-p loaddefs-file) + ;; If we're updating an old loaddefs file, then see if + ;; there's a section here for this file already. + (goto-char (point-min)) + (if (not (search-forward head nil t)) + ;; It's a new file; put the data at the end. + (progn + (goto-char (point-max)) + (search-backward "\f\n")) + ;; Delete the old version of the section. + (delete-region (match-beginning 0) + (and (search-forward "\n\f\n;;;") + (match-beginning 0))) + (forward-line -2))) + (insert head) + (dolist (def (reverse section)) + (setq def (caddr def)) + (if (stringp def) + (princ def (current-buffer)) + (loaddefs-generate--print-form def)) + (unless (bolp) + (insert "\n"))))) + (write-region (point-min) (point-max) loaddefs-file nil 'silent) + (byte-compile-info (file-relative-name loaddefs-file lisp-directory) + t "GEN"))))))) (defun loaddefs-generate--print-form (def) "Print DEF in the way make-docfile.c expects it." -- 2.39.2