Skip to content

Commit

Permalink
Byte compile in child process
Browse files Browse the repository at this point in the history
Separates byte-compilation from state of running Emacs.

See: radian-software#76, radian-software#624
  • Loading branch information
progfolio committed Dec 23, 2020
1 parent 35c0c33 commit 27839e2
Showing 1 changed file with 14 additions and 34 deletions.
48 changes: 14 additions & 34 deletions straight.el
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
(throw 'emacs-version-changed nil)))

;;;; Libraries

(require 'cl-lib)
(require 'subr-x)

Expand Down Expand Up @@ -4648,43 +4647,24 @@ individual package recipe."
(not (straight--plist-get recipe :no-byte-compile
straight-disable-byte-compilation)))

(cl-defun straight--byte-compile-package (recipe)
(defcustom straight-byte-compilation-buffer "*straight-byte-compilation*"
"Name of the byte compilation log buffer.
If nil, output is discarded."
:type '(or string nil))

(defun straight--byte-compile-package (recipe)
"Byte-compile files for the symlinked package specified by RECIPE.
RECIPE should be a straight.el-style plist. Note that this
function only modifies the build folder, not the original
repository."
(unless (straight--byte-compile-package-p recipe)
(cl-return-from straight--byte-compile-package))
;; We need to load `bytecomp' so that the `symbol-function'
;; assignments below are sure to work. Since we byte-compile this
;; file, we need to `require' the feature at compilation time too.
(eval-and-compile
(require 'bytecomp))
(straight--with-plist recipe
(package)
;; These two `let' forms try very, very hard to make
;; byte-compilation an invisible process. Lots of packages have
;; byte-compile warnings; I don't need to know about them and
;; neither do straight.el users.
(cl-letf (;; Prevent Emacs from asking the user to save all their
;; files before compiling.
((symbol-function #'save-some-buffers) #'ignore)
;; Die, byte-compile log, die!!!
((symbol-function #'byte-compile-log-1) #'ignore)
((symbol-function #'byte-compile-log-file) #'ignore)
((symbol-function #'byte-compile-log-warning) #'ignore))
(let (;; Suppress messages about byte-compilation progress.
(byte-compile-verbose nil)
;; Suppress messages about byte-compilation warnings.
(byte-compile-warnings nil)
;; Suppress the remaining messages.
(inhibit-message t)
(message-log-max nil))
;; Note that there is in fact no `byte-compile-directory'
;; function.
(byte-recompile-directory
(straight--build-dir package)
0 'force)))))
(when (straight--byte-compile-package-p recipe)
(let* ((package (plist-get recipe :package))
(dir (straight--build-dir package))
(form (format "(byte-recompile-directory %S 0 'force)" dir)))
(call-process
(concat invocation-directory invocation-name)
nil straight-byte-compilation-buffer nil
"-Q" "-L" dir "--batch" "--eval" form))))

;;;;; Native compilation

Expand Down

0 comments on commit 27839e2

Please sign in to comment.