Skip to content

Commit

Permalink
Eliminate unnecessary rebuilds of autoload files.
Browse files Browse the repository at this point in the history
  • Loading branch information
doublep committed Apr 29, 2024
1 parent 76cd79e commit ab21378
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions eldev-plugins.el
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,16 @@ out-of-date."
(nreverse filtered))
files))))
(let ((inhibit-message t)
(make-backup-files nil))
(make-backup-files nil)
(autoloads-file (expand-file-name target eldev-project-dir)))
(package-generate-autoloads (package-desc-name (eldev-package-descriptor)) effective-dir)
;; Make sure we don't decide to unnecessarily rebuild it again: if the file
;; hasn't changed, `package-generate-autoloads' won't overwrite it, potentially
;; making it appear outdated compared to source files.
(set-file-times autoloads-file)
;; Always load the generated file. Maybe there are cases when we don't need that,
;; but most of the time we do.
(eldev--load-autoloads-file (expand-file-name target eldev-project-dir))))))
(eldev--load-autoloads-file autoloads-file)))))
(add-hook 'eldev-before-loading-dependencies-hook
(lambda (type _additional-sets)
(when (and type (not (eq type 'load-only)))
Expand Down
16 changes: 16 additions & 0 deletions test/autoloads.el
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,20 @@
(should (= exit-code 0))))))


(ert-deftest eldev-autoloads-no-rebuild-after-null-change ()
(eldev--test-with-temp-copy "project-j" nil
(eldev--test-run nil ("build")
(should (string= stdout "AUTOLOADS -> project-j-autoloads.el\n"))
(should (= exit-code 0)))
;; After one of the source files is "changed", the autoloads file must be rebuilt.
(eldev--test-pretend-source-is-changed "project-j.el")
(eldev--test-run nil ("build")
(should (string= stdout "AUTOLOADS -> project-j-autoloads.el\n"))
(should (= exit-code 0)))
;; But not anymore: it has been successfully rebuilt after all source changes.
(eldev--test-run nil ("build")
(should (string= stdout "Nothing to do\n"))
(should (= exit-code 0)))))


(provide 'test/autoloads)

0 comments on commit ab21378

Please sign in to comment.