summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorPhilip Kaludercic <philipk@posteo.net>2023-04-30 13:17:09 +0200
committerPhilip Kaludercic <philipk@posteo.net>2023-04-30 18:42:58 +0200
commitdd21003878dadba1e0420269e63e10685d4670a9 (patch)
tree29a362f78bca55c4bcd9787df868155906104ecb /lisp/emacs-lisp
parent2bcf11d0efecd18a1be8bcf0ac1a1dadb14d971a (diff)
downloademacs-dd21003878dadba1e0420269e63e10685d4670a9.tar.gz
Prevent generating empty autoload files
* lisp/emacs-lisp/loaddefs-gen.el (loaddefs-generate): Remove optimisation that would mistakenly discard old loaddefs in case a file was not modified by EXTRA-DATA is non-nil. (Bug#62734)
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/loaddefs-gen.el122
1 files changed, 56 insertions, 66 deletions
diff --git a/lisp/emacs-lisp/loaddefs-gen.el b/lisp/emacs-lisp/loaddefs-gen.el
index 1007be62dd9..a966b1e9f40 100644
--- a/lisp/emacs-lisp/loaddefs-gen.el
+++ b/lisp/emacs-lisp/loaddefs-gen.el
@@ -597,73 +597,63 @@ instead of just updating them with the new/changed autoloads."
defs))))))
(progress-reporter-done progress))
- ;; If we have no autoloads data, but we have EXTRA-DATA, then
- ;; generate the (almost) empty file anyway.
- (if (and (not defs) extra-data)
+ ;; First group per output file.
+ (dolist (fdefs (seq-group-by (lambda (x) (expand-file-name (car x)))
+ defs))
+ (let ((loaddefs-file (car fdefs))
+ hash)
(with-temp-buffer
- (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 (lambda (x) (expand-file-name (car x)))
- defs))
- (let ((loaddefs-file (car fdefs))
- hash)
- (with-temp-buffer
- (if (and updating (file-exists-p loaddefs-file))
- (insert-file-contents loaddefs-file)
- (insert (loaddefs-generate--rubric
- loaddefs-file nil t include-package-version))
- (search-backward "\f")
- (when extra-data
- (insert extra-data)
- (ensure-empty-lines 1)))
- (setq hash (buffer-hash))
- ;; 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" nil t))
- ;; 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")))))
- ;; Only write the file if we actually made a change.
- (unless (equal (buffer-hash) hash)
- (write-region (point-min) (point-max) loaddefs-file nil 'silent)
- (byte-compile-info
- (file-relative-name loaddefs-file (car (ensure-list dir)))
- t "GEN"))))))))
+ (if (and updating (file-exists-p loaddefs-file))
+ (insert-file-contents loaddefs-file)
+ (insert (loaddefs-generate--rubric
+ loaddefs-file nil t include-package-version))
+ (search-backward "\f")
+ (when extra-data
+ (insert extra-data)
+ (ensure-empty-lines 1)))
+ (setq hash (buffer-hash))
+ ;; 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" nil t))
+ ;; 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")))))
+ ;; Only write the file if we actually made a change.
+ (unless (equal (buffer-hash) hash)
+ (write-region (point-min) (point-max) loaddefs-file nil 'silent)
+ (byte-compile-info
+ (file-relative-name loaddefs-file (car (ensure-list dir)))
+ t "GEN")))))))
(defun loaddefs-generate--print-form (def)
"Print DEF in a format that makes sense for version control."