2018-09-07 21:49:49 -04:00
|
|
|
;;; core/cli/byte-compile.el -*- lexical-binding: t; -*-
|
|
|
|
|
Rewrite core-cli
Highlights:
- 'doom purge' now purges builds, elpa packages, and repos by default.
Regrafting repos is now opt-in with the -g/--regraft switches.
Negation flags have been added for elpa/repos: -e/--no-elpa and
-r/--no-repos.
- Removed 'doom rebuild' (it is now just 'doom build' or 'doom b').
- Removed 'doom build's -f flag, this is now the default. Added the -r
flag instead, which only builds packages that need rebuilding.
- 'doom update' now updates packages synchronously, but produces more
informative output about the updating process.
- Straight can now prompt in batch mode, which resolves a lot of issues
with 'doom update' (and 'doom upgrade') freezing indefinitely or
throwing repo branch errors.
- 'bin/doom's switches are now positional. Switches aimed at `bin/doom`
must precede any subcommands. e.g.
Do: 'doom -yd upgrade'
Don't do: 'doom upgrade -yd'
- Moved 'doom doctor' from bin/doom-doctor to core/cli/doctor, and
integrated core/doctor.el into it, as to avoid naming conflicts
between it and Emacs doctor.
- The defcli! macro now has a special syntax for declaring flags, their
arguments and descriptions.
Addresses #1981, #1925, #1816, #1721, #1322
2019-11-07 15:59:56 -05:00
|
|
|
(defcli! (compile c)
|
|
|
|
((recompile-p ["-r" "--recompile"])
|
|
|
|
&rest targets)
|
2018-09-07 21:49:49 -04:00
|
|
|
"Byte-compiles your config or selected modules.
|
|
|
|
|
|
|
|
compile [TARGETS...]
|
|
|
|
compile :core :private lang/python
|
|
|
|
compile feature lang
|
|
|
|
|
2019-07-21 15:39:45 +02:00
|
|
|
Accepts :core and :private as special arguments, which target Doom's core files
|
|
|
|
and your private config files, respectively. To recompile your packages, use
|
|
|
|
'doom rebuild' instead."
|
Rewrite core-cli
Highlights:
- 'doom purge' now purges builds, elpa packages, and repos by default.
Regrafting repos is now opt-in with the -g/--regraft switches.
Negation flags have been added for elpa/repos: -e/--no-elpa and
-r/--no-repos.
- Removed 'doom rebuild' (it is now just 'doom build' or 'doom b').
- Removed 'doom build's -f flag, this is now the default. Added the -r
flag instead, which only builds packages that need rebuilding.
- 'doom update' now updates packages synchronously, but produces more
informative output about the updating process.
- Straight can now prompt in batch mode, which resolves a lot of issues
with 'doom update' (and 'doom upgrade') freezing indefinitely or
throwing repo branch errors.
- 'bin/doom's switches are now positional. Switches aimed at `bin/doom`
must precede any subcommands. e.g.
Do: 'doom -yd upgrade'
Don't do: 'doom upgrade -yd'
- Moved 'doom doctor' from bin/doom-doctor to core/cli/doctor, and
integrated core/doctor.el into it, as to avoid naming conflicts
between it and Emacs doctor.
- The defcli! macro now has a special syntax for declaring flags, their
arguments and descriptions.
Addresses #1981, #1925, #1816, #1721, #1322
2019-11-07 15:59:56 -05:00
|
|
|
(doom-cli-byte-compile targets recompile-p))
|
2018-09-07 21:49:49 -04:00
|
|
|
|
2019-07-28 01:32:16 +02:00
|
|
|
(defcli! clean ()
|
2019-07-21 15:39:45 +02:00
|
|
|
"Delete all *.elc files."
|
Rewrite core-cli
Highlights:
- 'doom purge' now purges builds, elpa packages, and repos by default.
Regrafting repos is now opt-in with the -g/--regraft switches.
Negation flags have been added for elpa/repos: -e/--no-elpa and
-r/--no-repos.
- Removed 'doom rebuild' (it is now just 'doom build' or 'doom b').
- Removed 'doom build's -f flag, this is now the default. Added the -r
flag instead, which only builds packages that need rebuilding.
- 'doom update' now updates packages synchronously, but produces more
informative output about the updating process.
- Straight can now prompt in batch mode, which resolves a lot of issues
with 'doom update' (and 'doom upgrade') freezing indefinitely or
throwing repo branch errors.
- 'bin/doom's switches are now positional. Switches aimed at `bin/doom`
must precede any subcommands. e.g.
Do: 'doom -yd upgrade'
Don't do: 'doom upgrade -yd'
- Moved 'doom doctor' from bin/doom-doctor to core/cli/doctor, and
integrated core/doctor.el into it, as to avoid naming conflicts
between it and Emacs doctor.
- The defcli! macro now has a special syntax for declaring flags, their
arguments and descriptions.
Addresses #1981, #1925, #1816, #1721, #1322
2019-11-07 15:59:56 -05:00
|
|
|
:bare t
|
2019-07-21 15:39:45 +02:00
|
|
|
(doom-clean-byte-compiled-files))
|
2018-09-07 21:49:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Helpers
|
|
|
|
|
2018-12-06 15:56:36 -05:00
|
|
|
(defun doom--byte-compile-ignore-file-p (path)
|
|
|
|
(let ((filename (file-name-nondirectory path)))
|
|
|
|
(or (string-prefix-p "." filename)
|
|
|
|
(string-prefix-p "test-" filename)
|
2019-12-20 05:01:44 -05:00
|
|
|
(string-suffix-p ".example.el" filename)
|
2019-07-21 15:39:45 +02:00
|
|
|
(not (equal (file-name-extension path) "el"))
|
|
|
|
(member filename (list "packages.el" "doctor.el")))))
|
2018-12-06 15:56:36 -05:00
|
|
|
|
Rewrite core-cli
Highlights:
- 'doom purge' now purges builds, elpa packages, and repos by default.
Regrafting repos is now opt-in with the -g/--regraft switches.
Negation flags have been added for elpa/repos: -e/--no-elpa and
-r/--no-repos.
- Removed 'doom rebuild' (it is now just 'doom build' or 'doom b').
- Removed 'doom build's -f flag, this is now the default. Added the -r
flag instead, which only builds packages that need rebuilding.
- 'doom update' now updates packages synchronously, but produces more
informative output about the updating process.
- Straight can now prompt in batch mode, which resolves a lot of issues
with 'doom update' (and 'doom upgrade') freezing indefinitely or
throwing repo branch errors.
- 'bin/doom's switches are now positional. Switches aimed at `bin/doom`
must precede any subcommands. e.g.
Do: 'doom -yd upgrade'
Don't do: 'doom upgrade -yd'
- Moved 'doom doctor' from bin/doom-doctor to core/cli/doctor, and
integrated core/doctor.el into it, as to avoid naming conflicts
between it and Emacs doctor.
- The defcli! macro now has a special syntax for declaring flags, their
arguments and descriptions.
Addresses #1981, #1925, #1816, #1721, #1322
2019-11-07 15:59:56 -05:00
|
|
|
(cl-defun doom-cli-byte-compile (&optional modules recompile-p)
|
2018-09-07 21:49:49 -04:00
|
|
|
"Byte compiles your emacs configuration.
|
|
|
|
|
|
|
|
init.el is always byte-compiled by this.
|
|
|
|
|
|
|
|
If MODULES is specified (a list of module strings, e.g. \"lang/php\"), those are
|
|
|
|
byte-compiled. Otherwise, all enabled modules are byte-compiled, including Doom
|
|
|
|
core. It always ignores unit tests and files with `no-byte-compile' enabled.
|
|
|
|
|
|
|
|
WARNING: byte-compilation yields marginal gains and makes debugging new issues
|
|
|
|
difficult. It is recommended you don't use it unless you understand the
|
|
|
|
reprecussions.
|
|
|
|
|
|
|
|
Use `doom-clean-byte-compiled-files' or `make clean' to reverse
|
|
|
|
byte-compilation.
|
|
|
|
|
|
|
|
If RECOMPILE-P is non-nil, only recompile out-of-date files."
|
|
|
|
(let ((default-directory doom-emacs-dir)
|
2019-07-21 15:39:45 +02:00
|
|
|
(doom-modules (doom-modules))
|
|
|
|
(byte-compile-verbose doom-debug-mode)
|
|
|
|
(byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local))
|
|
|
|
|
|
|
|
;; In case it is changed during compile-time
|
|
|
|
(auto-mode-alist auto-mode-alist)
|
|
|
|
(noninteractive t)
|
|
|
|
|
2018-09-07 21:49:49 -04:00
|
|
|
targets)
|
2019-07-21 15:39:45 +02:00
|
|
|
|
|
|
|
(let (target-dirs)
|
|
|
|
(dolist (module (delete-dups modules))
|
|
|
|
(pcase module
|
|
|
|
(":core"
|
|
|
|
(push (doom-glob doom-emacs-dir "init.el") targets)
|
|
|
|
(push doom-core-dir target-dirs))
|
|
|
|
(":private"
|
|
|
|
(push doom-private-dir target-dirs))
|
|
|
|
((pred file-directory-p)
|
|
|
|
(push module target-dirs))
|
|
|
|
((pred (string-match "^\\([^/]+\\)/\\([^/]+\\)$"))
|
|
|
|
(push (doom-module-locate-path
|
|
|
|
(doom-keyword-intern (match-string 1 module))
|
|
|
|
(intern (match-string 2 module)))
|
2019-08-09 12:09:41 -04:00
|
|
|
target-dirs))
|
|
|
|
(_ (user-error "%S is not a valid target" module))))
|
2019-07-21 15:39:45 +02:00
|
|
|
|
|
|
|
(and (or (null modules) (member ":private" modules))
|
|
|
|
(not recompile-p)
|
|
|
|
(not (or doom-auto-accept
|
2018-09-09 16:44:02 -04:00
|
|
|
(y-or-n-p
|
|
|
|
(concat "Warning: byte compiling is for advanced users. It will interfere with your\n"
|
|
|
|
"efforts to debug issues. It is not recommended you do it if you frequently\n"
|
|
|
|
"tinker with your Emacs config.\n\n"
|
|
|
|
"Alternatively, use `bin/doom compile :core` instead to byte-compile only the\n"
|
|
|
|
"Doom core files, as these don't change often.\n\n"
|
|
|
|
"If you have issues, please make sure byte-compilation isn't the cause by using\n"
|
|
|
|
"`bin/doom clean` to clear out your *.elc files.\n\n"
|
2019-07-21 15:39:45 +02:00
|
|
|
"Byte-compile anyway?"))))
|
|
|
|
(user-error "Aborting"))
|
|
|
|
|
|
|
|
;; But first we must be sure that Doom and your private config have been
|
|
|
|
;; fully loaded. Which usually aren't so in an noninteractive session.
|
2019-09-03 00:36:42 -04:00
|
|
|
(let ((doom-interactive-mode 'byte-compile))
|
2019-11-23 00:12:26 -05:00
|
|
|
(doom-initialize)
|
|
|
|
(doom-initialize-packages)
|
2019-09-03 00:38:04 -04:00
|
|
|
(doom-initialize-core))
|
2019-07-21 15:39:45 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
(unless target-dirs
|
|
|
|
(push (doom-glob doom-emacs-dir "init.el") targets)
|
|
|
|
;; If no targets were supplied, then we use your module list.
|
|
|
|
(appendq! target-dirs
|
|
|
|
(list doom-core-dir)
|
2019-08-23 20:30:39 -04:00
|
|
|
(nreverse
|
2019-08-23 20:33:30 -04:00
|
|
|
(cl-remove-if-not
|
|
|
|
(lambda (path) (file-in-directory-p path doom-emacs-dir))
|
|
|
|
;; Omit `doom-private-dir', which is always first
|
|
|
|
(cdr (doom-module-load-path))))))
|
2019-07-21 15:39:45 +02:00
|
|
|
|
|
|
|
;; Assemble el files we want to compile; taking into account that MODULES
|
|
|
|
;; may be a list of MODULE/SUBMODULE strings from the command line.
|
|
|
|
(appendq! targets
|
|
|
|
(doom-files-in target-dirs
|
|
|
|
:match "\\.el$"
|
|
|
|
:filter #'doom--byte-compile-ignore-file-p)))
|
|
|
|
|
|
|
|
(unless targets
|
|
|
|
(print!
|
|
|
|
(if targets
|
|
|
|
(warn "Couldn't find any valid targets")
|
|
|
|
(info "No targets to %scompile" (if recompile-p "re" ""))))
|
|
|
|
(cl-return nil))
|
|
|
|
|
|
|
|
(print!
|
2019-12-08 00:57:10 -05:00
|
|
|
(start (if recompile-p
|
|
|
|
"Recompiling stale elc files..."
|
|
|
|
"Byte-compiling your config (may take a while)...")))
|
2019-07-21 15:39:45 +02:00
|
|
|
(print-group!
|
|
|
|
(require 'use-package)
|
|
|
|
(condition-case e
|
|
|
|
(let ((total-ok 0)
|
|
|
|
(total-fail 0)
|
|
|
|
(total-noop 0)
|
|
|
|
(use-package-defaults use-package-defaults)
|
|
|
|
(use-package-expand-minimally t)
|
|
|
|
kill-emacs-hook kill-buffer-query-functions)
|
|
|
|
;; Prevent packages from being loaded at compile time if they
|
|
|
|
;; don't meet their own predicates.
|
|
|
|
(push (list :no-require t
|
|
|
|
(lambda (_name args)
|
|
|
|
(or (when-let (pred (or (plist-get args :if)
|
|
|
|
(plist-get args :when)))
|
|
|
|
(not (eval pred t)))
|
|
|
|
(when-let (pred (plist-get args :unless))
|
|
|
|
(eval pred t)))))
|
|
|
|
use-package-defaults)
|
|
|
|
|
|
|
|
(unless recompile-p
|
|
|
|
(doom-clean-byte-compiled-files))
|
|
|
|
|
Rewrite core-cli
Highlights:
- 'doom purge' now purges builds, elpa packages, and repos by default.
Regrafting repos is now opt-in with the -g/--regraft switches.
Negation flags have been added for elpa/repos: -e/--no-elpa and
-r/--no-repos.
- Removed 'doom rebuild' (it is now just 'doom build' or 'doom b').
- Removed 'doom build's -f flag, this is now the default. Added the -r
flag instead, which only builds packages that need rebuilding.
- 'doom update' now updates packages synchronously, but produces more
informative output about the updating process.
- Straight can now prompt in batch mode, which resolves a lot of issues
with 'doom update' (and 'doom upgrade') freezing indefinitely or
throwing repo branch errors.
- 'bin/doom's switches are now positional. Switches aimed at `bin/doom`
must precede any subcommands. e.g.
Do: 'doom -yd upgrade'
Don't do: 'doom upgrade -yd'
- Moved 'doom doctor' from bin/doom-doctor to core/cli/doctor, and
integrated core/doctor.el into it, as to avoid naming conflicts
between it and Emacs doctor.
- The defcli! macro now has a special syntax for declaring flags, their
arguments and descriptions.
Addresses #1981, #1925, #1816, #1721, #1322
2019-11-07 15:59:56 -05:00
|
|
|
(dolist (target (delete-dups (delq nil targets)))
|
2019-07-21 15:39:45 +02:00
|
|
|
(cl-incf
|
|
|
|
(if (not (or (not recompile-p)
|
|
|
|
(let ((elc-file (byte-compile-dest-file target)))
|
|
|
|
(and (file-exists-p elc-file)
|
|
|
|
(file-newer-than-file-p target elc-file)))))
|
|
|
|
total-noop
|
2019-10-04 22:42:53 -04:00
|
|
|
(pcase (if (doom-file-cookie-p target "if" t)
|
2019-07-21 15:39:45 +02:00
|
|
|
(byte-compile-file target)
|
|
|
|
'no-byte-compile)
|
|
|
|
(`no-byte-compile
|
|
|
|
(print! (info "Ignored %s") (relpath target))
|
|
|
|
total-noop)
|
|
|
|
(`nil
|
|
|
|
(print! (error "Failed to compile %s") (relpath target))
|
|
|
|
total-fail)
|
|
|
|
(_
|
|
|
|
(print! (success "Compiled %s") (relpath target))
|
|
|
|
(load target t t)
|
|
|
|
total-ok)))))
|
|
|
|
(print! (class (if (= total-fail 0) 'success 'error)
|
|
|
|
"%s %d/%d file(s) (%d ignored)")
|
|
|
|
(if recompile-p "Recompiled" "Compiled")
|
|
|
|
total-ok (- (length targets) total-noop)
|
|
|
|
total-noop)
|
|
|
|
t)
|
|
|
|
((debug error)
|
|
|
|
(print! (error "\nThere were breaking errors.\n\n%s")
|
|
|
|
"Reverting changes...")
|
|
|
|
(signal 'doom-error (list 'byte-compile e)))))))
|
2018-09-07 21:49:49 -04:00
|
|
|
|
|
|
|
(defun doom-clean-byte-compiled-files ()
|
|
|
|
"Delete all the compiled elc files in your Emacs configuration and private
|
|
|
|
module. This does not include your byte-compiled, third party packages.'"
|
2019-11-08 16:12:25 -05:00
|
|
|
(require 'core-modules)
|
2019-07-21 15:39:45 +02:00
|
|
|
(print! (start "Cleaning .elc files"))
|
|
|
|
(print-group!
|
|
|
|
(cl-loop with default-directory = doom-emacs-dir
|
|
|
|
with success = nil
|
|
|
|
for path
|
|
|
|
in (append (doom-glob doom-emacs-dir "*.elc")
|
2019-07-21 23:31:42 +02:00
|
|
|
(doom-files-in doom-private-dir :match "\\.elc$" :depth 1)
|
|
|
|
(doom-files-in doom-core-dir :match "\\.elc$")
|
|
|
|
(doom-files-in doom-modules-dirs :match "\\.elc$" :depth 4))
|
2019-07-21 15:39:45 +02:00
|
|
|
if (file-exists-p path)
|
|
|
|
do (delete-file path)
|
|
|
|
and do (print! (success "Deleted %s") (relpath path))
|
|
|
|
and do (setq success t)
|
|
|
|
finally do
|
|
|
|
(print! (if success
|
|
|
|
(success "All elc files deleted")
|
2019-12-08 00:57:10 -05:00
|
|
|
(info "No elc files to clean"))))
|
|
|
|
t))
|