Add native-compile-prune-cache command

* lisp/emacs-lisp/comp.el (native-compile-prune-cache): New
command (bug#48108).
This commit is contained in:
Lars Ingebrigtsen 2022-07-02 12:59:41 +02:00
parent 14d4d63c8c
commit 05d240997a
2 changed files with 32 additions and 1 deletions

View file

@ -148,8 +148,15 @@ This is run at the end of the Emacs startup process, and is meant to
be used to reinitialize structures that would normally be done at load
time.
** Native Compilation
---
** New function 'startup-redirect-eln-cache'.
*** New command 'native-compile-prune-cache'.
This command deletes older .eln cache entries (but not the ones for
the current Emacs version).
---
*** New function 'startup-redirect-eln-cache'.
This function can be called in your init files to change the
user-specific directory where Emacs stores the "*.eln" files produced
by native compilation of Lisp packages Emacs loads. The default

View file

@ -4288,6 +4288,30 @@ of (commands) to run simultaneously."
(let ((load (not (not load))))
(native--compile-async files recursively load selector)))
(defun native-compile-prune-cache ()
"Remove .eln files that aren't applicable to the current Emacs invocation."
(interactive)
(dolist (dir native-comp-eln-load-path)
;; If a directory is non absolute it is assumed to be relative to
;; `invocation-directory'.
(setq dir (expand-file-name dir invocation-directory))
(when (file-exists-p dir)
(dolist (subdir (directory-files dir t))
(when (and (file-directory-p subdir)
(file-writable-p subdir)
(not (equal (file-name-nondirectory
(directory-file-name subdir))
comp-native-version-dir)))
(message "Deleting %s..." subdir)
;; We're being overly cautious here -- there shouldn't be
;; anything but .eln files in these directories.
(dolist (eln (directory-files subdir t "\\.eln\\(\\.tmp\\)?\\'"))
(when (file-writable-p eln)
(delete-file eln)))
(when (directory-empty-p subdir)
(delete-directory subdir))))))
(message "Cache cleared"))
(provide 'comp)
;; LocalWords: limplified limplified limplification limplify Limple LIMPLE libgccjit elc eln