Is there a way to tell if the current *.elc
files were not compiled with the current Emacs?
I am trying to detect an error where emacs is updated, but old .elc
files are left in the user elpa directory and they are not compatible.
Based on the hint from @Drew about the file header, this seems to work:
(defun elc-consistent-p (elc)
"Return non-nil if ELC is consistent with current Emacs.
ELC is the path to a .elc file.
That means it was compiled with the same emacs major and minor
version as the current emacs."
(string= (with-temp-buffer
(insert-file-contents elc)
(goto-char (point-min))
(re-search-forward ";;; in Emacs version \\([0-9]\\{2\\}\\.[0-9]+\\)"
nil t)
(match-string 1))
(format "%s.%s" emacs-major-version emacs-minor-version)))
.elc
file tells you what Emacs build it was created with. Does that help?