Fix doom//byte-compile

This commit is contained in:
Henrik Lissner 2018-05-24 19:09:23 +02:00
parent 3261f1fd71
commit 6ea5430c4d
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -269,95 +269,92 @@ these files.
If RECOMPILE-P is non-nil, only recompile out-of-date files." If RECOMPILE-P is non-nil, only recompile out-of-date files."
(interactive (interactive
(list nil current-prefix-arg)) (list nil current-prefix-arg))
(let ((default-directory doom-emacs-dir) (let ((default-directory doom-emacs-dir))
(recompile-p (or recompile-p (and (member "-r" (cdr argv)) t)))
(argv (delete "-r" argv)))
(unless recompile-p (unless recompile-p
(doom//clean-byte-compiled-files)) (doom//clean-byte-compiled-files))
(let ((total-ok 0) (let ((total-ok 0)
(total-fail 0) (total-fail 0)
(total-noop 0) (total-noop 0)
(modules (or modules (cdr argv))) compile-plugins-p
compile-plugins targets)
compile-targets) (dolist (module (delete-dups modules) (nreverse targets))
;; Ensure that Doom has been fully loaded, some of its state may be (pcase module
;; pertinent to files compiled later. (":core" (push doom-core-dir targets))
(let ((doom--stage 'compile) (":private" (push doom-private-dir targets))
noninteractive) (":plugins"
;; Core libraries aren't fully loaded in a noninteractive session, so we (byte-recompile-directory package-user-dir 0 t)
;; pretend to be interactive and reinitialize (setq compile-plugins-p t))
(doom-initialize)) ((pred file-directory-p)
(push module targets))
((pred (string-match "^\\([^/]+\\)/\\([^/]+\\)$"))
(push (doom-module-locate-path
(intern (format ":%s" (match-string 1 module)))
(intern (match-string 2 module)))
targets))))
(unless (equal modules (list ":plugins"))
(let ((inhibit-message t)
noninteractive)
;; But first we must be sure that Doom and your private config have been
;; fully loaded. Which usually aren't so in an noninteractive session.
(doom//reload-autoloads)
(doom-initialize t)
(unless (equal modules (list ":core"))
(doom-initialize-modules t))))
;; If no targets were supplied, then we use your module list.
(unless targets
(setq targets (append (list doom-core-dir)
(doom-module-load-path))))
;; Assemble el files we want to compile; taking into account that MODULES ;; Assemble el files we want to compile; taking into account that MODULES
;; may be a list of MODULE/SUBMODULE strings from the command line. ;; may be a list of MODULE/SUBMODULE strings from the command line.
(setq (let ((target-files (doom-files-in targets :depth 2 :match "\\.el$")))
modules (or modules (append (list doom-core-dir) (doom-module-load-path))) (if (not target-files)
compile-targets (unless compile-plugins-p
(cl-loop for target in modules (message "No targets to %scompile" (if recompile-p "re" "")))
if (equal target ":core")
nconc (nreverse (doom-files-under doom-core-dir :match "\\.el$"))
and collect (expand-file-name "init.el" doom-private-dir)
if (equal target ":private")
nconc (nreverse (doom-files-under doom-private-dir :match "\\.el$"))
if (equal target ":plugins")
do (setq compile-plugins t)
else if (file-directory-p target)
nconc (nreverse (doom-files-under target :match "\\.el$"))
else if (cl-member target doom-psuedo-module-dirs :test #'file-in-directory-p)
nconc (nreverse (doom-files-under it :match "\\.el$"))
else if (string-match "^\\([^/]+\\)/\\([^/]+\\)$" target)
nconc (nreverse (doom-files-under
(doom-module-locate-path
(intern (format ":%s" (match-string 1 target)))
(intern (match-string 2 target)))
:match "\\.el$"))
else if (file-exists-p target)
collect target
finally do (setq argv nil)))
(if compile-plugins
(byte-recompile-directory package-user-dir 0 t)
(if (not compile-targets)
(message "No targets to compile")
(condition-case ex (condition-case ex
(let ((use-package-expand-minimally t)) (let ((use-package-expand-minimally t))
(push (expand-file-name "init.el" doom-emacs-dir) compile-targets) ;; Always compile private init file
(dolist (target (cl-delete-duplicates (mapcar #'file-truename compile-targets) :test #'equal)) (cl-pushnew (expand-file-name "init.el" doom-private-dir)
(when (or (not recompile-p) target-files :test #'equal)
(let ((elc-file (byte-compile-dest-file target))) (cl-pushnew (expand-file-name "init.el" doom-emacs-dir)
(and (file-exists-p elc-file) target-files :test #'equal)
(file-newer-than-file-p target elc-file)))) (dolist (target (cl-delete-duplicates (mapcar #'file-truename target-files) :test #'equal))
(let ((result (cond ((string-match-p "/\\(packages\\|doctor\\)\\.el$" target) (if (or (not recompile-p)
'no-byte-compile) (let ((elc-file (byte-compile-dest-file target)))
((doom-file-cookie-p target) (and (file-exists-p elc-file)
(byte-compile-file target)) (file-newer-than-file-p target elc-file))))
('no-byte-compile))) (let ((result (if (or (string-match-p "/\\(?:packages\\|doctor\\)\\.el$" target)
(short-name (if (file-in-directory-p target doom-emacs-dir) (not (doom-file-cookie-p target)))
(file-relative-name target doom-emacs-dir) 'no-byte-compile
(abbreviate-file-name target)))) (byte-compile-file target)))
(cl-incf (short-name (if (file-in-directory-p target doom-emacs-dir)
(cond ((eq result 'no-byte-compile) (file-relative-name target doom-emacs-dir)
(print! (dark (white "⚠ Ignored %s" short-name))) (abbreviate-file-name target))))
total-noop) (cl-incf
((null result) (cond ((eq result 'no-byte-compile)
(print! (red "✕ Failed to compile %s" short-name)) (print! (dark (white "⚠ Ignored %s" short-name)))
total-fail) total-noop)
(t ((null result)
(print! (green "✓ Compiled %s" short-name)) (print! (red "✕ Failed to compile %s" short-name))
(quiet! (load target t t)) total-fail)
total-ok)))))) (t
(print! (green "✓ Compiled %s" short-name))
(quiet! (load target t t))
total-ok))))
(cl-incf total-noop)))
(print! (print!
(bold (bold
(color (if (= total-fail 0) 'green 'red) (color (if (= total-fail 0) 'green 'red)
"%s %d/%d file(s) (%d ignored)" "%s %d/%d file(s) (%d ignored)"
(if recompile-p "Recompiled" "Compiled") (if recompile-p "Recompiled" "Compiled")
total-ok (- (length compile-targets) total-noop) total-ok (- (length target-files) total-noop)
total-noop)))) total-noop))))
(error (error
(print! (red "\n%%s\n\n%%s\n\n%%s") (print! (red "\n%%s\n\n%%s\n\n%%s")
"There were breaking errors." "There were breaking errors."
(error-message-string ex) (error-message-string ex)
"Reverting changes...") "Reverting changes...")
(quiet! (doom//clean-byte-compiled-files)) (quiet! (doom//clean-byte-compiled-files))
(print! (green "Finished (nothing was byte-compiled)"))))))))) (print! (yellow "Finished (nothing was byte-compiled)")))))))))
;;;###autoload ;;;###autoload
(defun doom//clean-byte-compiled-files () (defun doom//clean-byte-compiled-files ()