This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/core/core-compilation.el

80 lines
3.1 KiB
EmacsLisp
Raw Normal View History

;;; core-compilation.el --- Spacemacs Core File -*- no-byte-compile: t -*-
2021-01-18 14:26:45 +00:00
;;
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
;;
;; Author: Eugene "JAremko" Yaremenko <w3techplayground@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
2021-01-18 14:26:45 +00:00
2021-01-25 14:56:36 +00:00
(require 'cl-lib)
(require 'subr-x)
(defvar spacemacs--last-emacs-version ""
"This variable is set during Emacs initialization to its version.")
(defconst spacemacs--last-emacs-version-file
(expand-file-name (concat spacemacs-cache-directory "last-emacs-version"))
"File that sets `spacemacs--last-emacs-version' variable.")
2021-01-25 14:56:36 +00:00
(defconst spacemacs--compiled-files
2021-01-18 14:26:45 +00:00
'(;; Built-in libs that we changed
"core/libs/forks/load-env-vars.el"
"core/libs/forks/spacemacs-ht.el"
2021-01-18 14:26:45 +00:00
;; Rest of built-in libs.
"core/libs/ido-vertical-mode.el"
"core/libs/package-build-badges.el"
"core/libs/package-build.el"
"core/libs/package-recipe-mode.el"
2021-02-11 13:52:32 +00:00
"core/libs/package-recipe.el"
2021-01-18 14:26:45 +00:00
"core/libs/page-break-lines.el"
2021-02-11 17:41:39 +00:00
"core/libs/validate.el"
2021-01-18 14:26:45 +00:00
"core/libs/quelpa.el"
"core/libs/spinner.el")
"List of Spacemacs files that should be compiled.
2021-01-24 13:44:57 +00:00
File paths are relative to the `spacemacs-start-directory'.")
2021-01-18 14:26:45 +00:00
2021-01-20 00:55:18 +00:00
(defun spacemacs//ensure-byte-compilation (files)
"Make sure that elisp FILES are byte-compiled."
2021-01-18 14:26:45 +00:00
(dolist (file files)
2021-01-20 00:55:18 +00:00
(let ((fbp (file-name-sans-extension (file-truename file))))
2021-01-25 14:56:36 +00:00
(unless (file-exists-p (concat fbp ".elc"))
(byte-compile-file (concat fbp ".el"))))))
2021-01-18 14:26:45 +00:00
2021-02-11 13:52:32 +00:00
(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))))
2021-01-25 01:06:28 +00:00
2021-02-11 13:52:32 +00:00
(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))
2021-01-31 07:20:42 +00:00
(cl-return t)))))
2021-01-25 14:56:36 +00:00
(defun spacemacs//update-last-emacs-version ()
"Update `spacemacs--last-emacs-version' and its saved value."
(with-temp-file spacemacs--last-emacs-version-file
(insert (format "(setq spacemacs--last-emacs-version %S)"
(setq spacemacs--last-emacs-version emacs-version)))
(make-directory (file-name-directory spacemacs--last-emacs-version-file)
t)))
2021-01-18 14:26:45 +00:00
(provide 'core-compilation)