Better .elc cleanup

This commit is contained in:
JAremko 2021-02-11 15:52:32 +02:00 committed by Eugene Yaremenko
parent 9375d6f54d
commit 7238eb03e8
3 changed files with 20 additions and 25 deletions

View File

@ -27,6 +27,7 @@
"core/libs/package-build-badges.el"
"core/libs/package-build.el"
"core/libs/package-recipe-mode.el"
"core/libs/package-recipe.el"
"core/libs/page-break-lines.el"
"core/libs/quelpa.el"
"core/libs/spinner.el")
@ -40,24 +41,18 @@ File paths are relative to the `spacemacs-start-directory'.")
(unless (file-exists-p (concat fbp ".elc"))
(byte-compile-file (concat fbp ".el"))))))
(defun spacemacs//remove-byte-compiled-files (files)
"Remove .elc files corresponding to the source FILES."
(dolist (file files)
(let ((file-elc (thread-last file
(file-truename)
(file-name-sans-extension)
(format "%s.elc"))))
(when (file-exists-p file-elc)
(delete-file file-elc)))))
(defun spacemacs//remove-byte-compiled-files-in-dir (dir)
"Remove all .elc files in DIR directory."
(dolist (elc (directory-files-recursively dir "\\.elc$"))
(when (file-exists-p elc)
(delete-file elc))))
(defun spacemacs//contains-newer-than-byte-compiled-p (files)
"Return true if any file in FILES is newer than its byte-compiled version."
(cl-dolist (file files)
(let* ((file-el (file-truename file))
(file-elc (thread-last file-el
(file-name-sans-extension)
(format "%s.elc"))))
(when (file-newer-than-file-p file-el file-elc)
(defun spacemacs//dir-contains-stale-byte-compiled-files-p (dir)
"Returns true if any .elc file in DIR directory is stale or orphaned."
(cl-dolist (elc (directory-files-recursively dir "\\.elc$"))
(let ((el (substring elc 0 -1)))
(unless (and (file-exists-p el)
(file-newer-than-file-p elc el))
(cl-return t)))))
(defun spacemacs//update-last-emacs-version ()

View File

@ -256,7 +256,7 @@ Note: the hooked function is not executed when in dumped mode."
(let ((default-directory spacemacs-start-directory))
(if dotspacemacs-byte-compile
(spacemacs//ensure-byte-compilation spacemacs--compiled-files)
(spacemacs//remove-byte-compiled-files spacemacs--compiled-files)))
(spacemacs//remove-byte-compiled-files-in-dir spacemacs-core-directory)))
;; Check if revision has changed.
(spacemacs//revision-check))

14
init.el
View File

@ -25,16 +25,16 @@
(load (concat spacemacs-core-directory "core-dumper.el")
nil (not init-file-debug))
;; Clean compiled files if they become stale or Emacs version has changed.
;; Remove compiled core files if they become stale or Emacs version has changed.
(load (concat spacemacs-core-directory "core-compilation.el")
nil (not init-file-debug))
(load spacemacs--last-emacs-version-file t (not init-file-debug))
(let ((default-directory spacemacs-start-directory))
(when (or (not (string= spacemacs--last-emacs-version emacs-version))
(spacemacs//contains-newer-than-byte-compiled-p
spacemacs--compiled-files))
(spacemacs//remove-byte-compiled-files spacemacs--compiled-files)))
(when (not (string= spacemacs--last-emacs-version emacs-version))
(when (or (not (string= spacemacs--last-emacs-version emacs-version))
(spacemacs//dir-contains-stale-byte-compiled-files-p
spacemacs-core-directory))
(spacemacs//remove-byte-compiled-files-in-dir spacemacs-core-directory))
;; Update saved Emacs version.
(unless (string= spacemacs--last-emacs-version emacs-version)
(spacemacs//update-last-emacs-version))
(if (not (version<= spacemacs-emacs-min-version emacs-version))