Optimize make autoloads & improve path expansion

Make autoloads will expand the include paths of Doom autoload cookies.
This fixes an issue where paths were expanded to include a file
extension, bypassing the benefits of byte-compilation.
This commit is contained in:
Henrik Lissner 2018-05-16 10:29:57 +02:00
parent b4a7e5348a
commit 3e6d7f174a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -155,6 +155,7 @@ and `auto-mode-alist'.")
(insert ";;; -*- lexical-binding:t -*-\n" (insert ";;; -*- lexical-binding:t -*-\n"
";; This file was autogenerated by `doom|refresh-cache', DO NOT EDIT!\n") ";; This file was autogenerated by `doom|refresh-cache', DO NOT EDIT!\n")
(prin1 `(setq load-path ',load-path (prin1 `(setq load-path ',load-path
auto-mode-alist ',auto-mode-alist
Info-directory-list ',Info-directory-list Info-directory-list ',Info-directory-list
doom-disabled-packages ',doom-disabled-packages doom-disabled-packages ',doom-disabled-packages
package-activated-list ',package-activated-list) package-activated-list ',package-activated-list)
@ -742,7 +743,7 @@ This should be run whenever init.el or an autoload file is modified. Running
;; in case this function has side effects. ;; in case this function has side effects.
(progn (progn
(doom-packages--async-run 'doom//reload-autoloads) (doom-packages--async-run 'doom//reload-autoloads)
(load doom-autoload-file t nil t)) (load doom-autoload-file 'noerror nil 'nosuffix))
(let ((default-directory doom-emacs-dir) (let ((default-directory doom-emacs-dir)
(targets (targets
(file-expand-wildcards (file-expand-wildcards
@ -760,7 +761,7 @@ This should be run whenever init.el or an autoload file is modified. Running
(message "Deleted old autoloads.el")) (message "Deleted old autoloads.el"))
(message "Generating new autoloads.el") (message "Generating new autoloads.el")
(dolist (file (mapcar #'file-truename (reverse targets))) (dolist (file (mapcar #'file-truename (reverse targets)))
(let ((generated-autoload-load-name file)) (let ((generated-autoload-load-name (file-name-sans-extension file)))
(message (message
(cond ((not (doom-packages--read-if-cookies file)) (cond ((not (doom-packages--read-if-cookies file))
"⚠ Ignoring %s") "⚠ Ignoring %s")
@ -775,37 +776,58 @@ This should be run whenever init.el or an autoload file is modified. Running
(load-path (append (list doom-emacs-dir) (load-path (append (list doom-emacs-dir)
doom-psuedo-module-dirs doom-psuedo-module-dirs
doom-modules-dirs doom-modules-dirs
load-path))) load-path))
library-cache)
(unwind-protect (unwind-protect
(condition-case-unless-debug ex (condition-case-unless-debug ex
(with-current-buffer buf (with-current-buffer buf
(delay-mode-hooks (emacs-lisp-mode))
(goto-char (point-min)) (goto-char (point-min))
(insert ";;; -*- lexical-binding:t -*-\n" (insert ";;; -*- lexical-binding:t -*-\n"
";; This file is autogenerated by `doom//reload-autoloads', DO NOT EDIT !!\n\n") ";; This file is autogenerated by `doom//reload-autoloads', DO NOT EDIT !!\n\n")
(save-excursion
;; Replace autoload paths with absolute paths for faster
;; resolution during load and simpler `load-path'
(while (re-search-forward "^\\s-*(autoload\\s-+'[^ ]+\\s-+\"\\([^/][^\"]*\\)\"" nil t)
(let ((path (match-string 1)))
;; (delete-region (match-beginning 1) (match-end 1))
(replace-match
(or (cdr (assoc path library-cache))
(when-let* ((libpath (locate-library path))
(libpath (file-name-sans-extension libpath)))
(push (cons path libpath) library-cache)
libpath)
(progn
(warn "Couldn't find absolute path for: %s" path)
path))
t t nil 1)))
(message "✓ Autoload paths expanded"))
(save-excursion
;; insert package autoloads ;; insert package autoloads
(dolist (file (doom-packages--files doom-packages-dir "-autoloads\\.el$")) (dolist (file (doom-packages--files doom-packages-dir "-autoloads\\.el$"))
(when doom-debug-mode (insert
(message "⚠ Including %s" (file-relative-name file package-user-dir))) (with-temp-buffer
(let ((pfile (prin1-to-string file))) (insert "\n(let ((load-file-name " (prin1-to-string file) "))")
(insert "\n(let ((load-file-name " pfile "))")
(insert-file-contents file) (insert-file-contents file)
(while (re-search-forward "#\\$\\|^;\\(.*\n\\)" nil 'move) (while (re-search-forward "^;;\\(.*\n\\)" nil 'move)
(unless (nth 8 (syntax-ppss)) (replace-match "" t t))
(replace-match (if (match-end 1) "" pfile) t t)))
(unless (bolp) (insert "\n")) (unless (bolp) (insert "\n"))
(insert ")\n"))) (insert ")\n")
(message "✓ Package autoloads included") (buffer-string))))
(message "✓ Package autoloads included"))
;; Replace autoload paths with absolute paths for faster
;; resolution during load and simpler `load-path'
(while (re-search-forward "^\\s-*(add-to-list\\s-+'\\(?:load-path\\|auto-mode-alist\\)" nil t)
(beginning-of-line-text)
(kill-sexp))
(message "✓ Autoload load-path entries removed")
(goto-char (point-max))
(insert "
;; Local\sVariables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:\n")
(quiet! (eval-buffer buf))
(save-buffer) (save-buffer)
(let (byte-compile-warnings)
;; give the file a chance to reveal errors
(load doom-autoload-file nil 'nomessage 'nosuffix))
(message "Done!")) (message "Done!"))
('error ('error
(delete-file doom-autoload-file) (delete-file doom-autoload-file)