Force straight to byte-compile packages in same session

Straight (on its develop branch) byte compiles packages in a child
process, isolated from the current session. This is a sensible approach
and I applaud it, but there's a problem:

Some packages don't load their compile-time dependencies at
compile-time, causing errors *at* compile-time. They unwittingly rely on
the fact that package.el compiles them in the same session as their
dependencies, which indirectly loads their macros for them. I can't
depend on package authors to do the right thing, but I can force
straight to revert to the old approach.
This commit is contained in:
Henrik Lissner 2021-02-05 22:40:16 -05:00
parent 95a603733a
commit 628f0a930f

View file

@ -751,45 +751,24 @@ See the docstrings of `defalias' and `make-obsolete' for more details."
`(progn (defalias ,obsolete-name ,current-name ,docstring) `(progn (defalias ,obsolete-name ,current-name ,docstring)
(make-obsolete ,obsolete-name ,current-name ,when))) (make-obsolete ,obsolete-name ,current-name ,when)))
(defadvice! doom--fix-wrong-number-of-args-during-byte-compile (recipe) (defadvice! doom--byte-compile-in-same-session-a (recipe)
"Straight recompiles packages from an Emacs child process. This is sensible,
but many packages don't properly load their macro dependencies, causing errors,
which we can't possibly police, so I revert straight to its old strategy of
compiling in the same session."
:override #'straight--build-compile :override #'straight--build-compile
(let* ((package (plist-get recipe :package)) (straight--with-plist recipe (package)
(dir (straight--build-dir package)) ;; These two `let' forms try very, very hard to make byte-compilation an
(program (concat invocation-directory invocation-name)) ;; invisible process. Lots of packages have byte-compile warnings; I
(args ;; don't need to know about them and neither do straight.el users.
`("-Q" "-L" ,dir (letf! (;; Prevent Emacs from asking the user to save all their
,@(apply #'append ;; files before compiling.
(mapcar (lambda (d) (#'save-some-buffers #'ignore))
(let ((d (straight--build-dir d))) (quiet!
(when (file-exists-p d) (list "-L" d)))) ;; Note that there is in fact no `byte-compile-directory' function.
(straight--get-dependencies package))) (byte-recompile-directory
"--batch" (straight--build-dir package)
"--eval" 0 'force))))))
,(prin1-to-string
'(progn
(defmacro define-obsolete-face-alias (obsolete-face current-face &optional when)
`(progn (put ,obsolete-face 'face-alias ,current-face)
(put ,obsolete-face 'obsolete-face (or (purecopy ,when) t))))
(defmacro define-obsolete-function-alias (obsolete-name current-name &optional when docstring)
`(progn (defalias ,obsolete-name ,current-name ,docstring)
(make-obsolete ,obsolete-name ,current-name ,when)))
(defmacro define-obsolete-variable-alias (obsolete-name current-name &optional when docstring)
`(progn (defvaralias ,obsolete-name ,current-name ,docstring)
(dolist (prop '(saved-value saved-variable-comment))
(and (get ,obsolete-name prop)
(null (get ,current-name prop))
(put ,current-name prop (get ,obsolete-name prop))))
(make-obsolete-variable ,obsolete-name ,current-name ,when)))))
"--eval"
,(format "(byte-recompile-directory %S 0 'force)" dir))))
(when straight-byte-compilation-buffer
(with-current-buffer (get-buffer-create straight-byte-compilation-buffer)
(insert "\n$ " (replace-regexp-in-string
"\\(-L [^z-a]*? \\)"
"\\1\\\\ \n "
(string-join `(,program ,@args) " "))
"\n")))
(apply #'call-process program nil straight-byte-compilation-buffer nil args))))
(provide 'core-lib) (provide 'core-lib)
;;; core-lib.el ends here ;;; core-lib.el ends here