Skip to content

Commit

Permalink
Rework byte recompile of built-in libs
Browse files Browse the repository at this point in the history
  • Loading branch information
JAremko committed Jan 26, 2021
1 parent e712eae commit 5182a45
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 1,325 deletions.
4 changes: 1 addition & 3 deletions .ci/built_in_manifest
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ https://raw.githubusercontent.com/nashamri/spacemacs-theme/master/spacemacs-comm
https://raw.githubusercontent.com/nashamri/spacemacs-theme/master/spacemacs-dark-theme.el core/libs/spacemacs-theme/spacemacs-dark-theme.el
https://raw.githubusercontent.com/nashamri/spacemacs-theme/master/spacemacs-light-theme.el core/libs/spacemacs-theme/spacemacs-light-theme.el
https://raw.githubusercontent.com/nashamri/spacemacs-theme/master/spacemacs-theme-pkg.el core/libs/spacemacs-theme/spacemacs-theme-pkg.el
https://raw.githubusercontent.com/sigma/mocker.el/master/mocker.el core/libs/mocker.el
https://raw.githubusercontent.com/emacscollective/packed/master/packed.el core/libs/packed.el
https://raw.githubusercontent.com/emacscollective/auto-compile/master/auto-compile.el core/libs/auto-compile.el
https://raw.githubusercontent.com/sigma/mocker.el/master/mocker.el core/libs/mocker.el
23 changes: 17 additions & 6 deletions core/core-compilation.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
;;
;;; License: GPLv3

(defconst spacemacs-compiled-files
(require 'cl-lib)
(require 'subr-x)

(defconst spacemacs--compiled-files
'(;; Built-in libs that we changed
"core/libs/forks/load-env-vars.el"
;; Rest of built-in libs.
"core/libs/packed.el"
"core/libs/auto-compile.el"
"core/libs/dash.el"
"core/libs/ht.el"
"core/libs/ido-vertical-mode.el"
Expand All @@ -27,13 +28,12 @@
"List of Spacemacs files that should be compiled.
File paths are relative to the `spacemacs-start-directory'.")


(defun spacemacs//ensure-byte-compilation (files)
"Make sure that elisp FILES are byte-compiled."
(dolist (file files)
(let ((fbp (file-name-sans-extension (file-truename file))))
(unless (file-exists-p (concat fbp ".elc"))
(byte-compile-file (concat fbp ".el"))))))
(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."
Expand All @@ -44,4 +44,15 @@ File paths are relative to the `spacemacs-start-directory'.")
(format "%s.elc")
(delete-file))))

(defun spacemacs//remove-byte-compiled-if-stale (files)
"Remove all .elc files corresponding to the source FILES if any is stale."
(when (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)
(cl-return t))))
(spacemacs//remove-byte-compiled-files files)))

(provide 'core-compilation)
22 changes: 18 additions & 4 deletions core/core-release-management.el
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ OWNER REPO."
"Hard reset the current branch to specified TAG."
(let ((proc-buffer "git-hard-reset")
(default-directory (file-truename spacemacs-start-directory)))
(prog1
(eq 0 (process-file "git" nil proc-buffer nil
"reset" "--hard" tag))
(kill-buffer proc-buffer))))
(prog1 (eq 0 (process-file "git" nil proc-buffer nil
"reset" "--hard" tag))
(kill-buffer proc-buffer)
(spacemacs//revision-update))))

(defun spacemacs//git-latest-tag (remote branch)
"Returns the latest tag on REMOTE/BRANCH."
Expand Down Expand Up @@ -348,6 +348,20 @@ Example: (1 42 3) = 1 042 003"
(add-hook 'spacemacs-post-theme-change-hook
'spacemacs/set-new-version-lighter-mode-line-faces)

(defun spacemacs//revision-update ()
"Update saved revision value and trigger `spacemacs-revision--changed-hook'."
(let ((proc-buffer "spacemacs//revision-update:git-get-current-rev"))
(when (eq 0 (process-file "git" nil proc-buffer nil "rev-parse" "HEAD"))
(with-current-buffer proc-buffer
(goto-char 1)
(setq spacemacs-revision--last (current-word))
(kill-buffer proc-buffer))))
(with-temp-file spacemacs-revision--file
(insert (format "(setq spacemacs-revision--last %S)"
spacemacs-revision--last))
(make-directory (file-name-directory spacemacs-revision--file) t))
(run-hooks 'spacemacs-revision--changed-hook))

(defun spacemacs//revision-check ()
"Update saved value of the current revision asynchronously.
NOTE: If old and new revisions are different `spacemacs-revision--changed-hook'
Expand Down
8 changes: 3 additions & 5 deletions core/core-spacemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,10 @@ Note: the hooked function is not executed when in dumped mode."
(unless (version< emacs-version "27")
(setq read-process-output-max dotspacemacs-read-process-output-max))))

;; Ensure that `spacemacs-compiled-files' are byte-compiled.
;; Ensure that `spacemacs--compiled-files' are byte-compiled.
(let ((default-directory spacemacs-start-directory))
(spacemacs//ensure-byte-compilation spacemacs-compiled-files))
;; Remove Spacemacs'es .elc files if Spacemacs revision has changed.
(add-hook 'spacemacs-revision--changed-hook 'spacemacs//byte-compile-cleanup)
;; Update saved revision.
(spacemacs//ensure-byte-compilation spacemacs--compiled-files))
;; Check if revision has changed.
(spacemacs//revision-check))

(provide 'core-spacemacs)
Loading

0 comments on commit 5182a45

Please sign in to comment.