Fix package! mutating package state at expansion time

Fixes an issue where package! declarations were read unconditionally at
compile time, whether or not they were on a reachable code path. e.g.
evil is always disabled by:

  (when nil
    (package! evil :disable t))
This commit is contained in:
Henrik Lissner 2019-10-25 02:36:02 -04:00
parent 54559d567a
commit f516d4c342
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 39 additions and 42 deletions

View file

@ -81,7 +81,7 @@
Excludes packages that have a non-nil :built-in property." Excludes packages that have a non-nil :built-in property."
(when-let (plist (doom-package-get package)) (when-let (plist (doom-package-get package))
(not (eval (plist-get plist :ignore) t)))) (not (plist-get plist :ignore) t)))
;;;###autoload ;;;###autoload
(defun doom-package-private-p (package) (defun doom-package-private-p (package)
@ -176,7 +176,7 @@ ones."
;; We load the private packages file twice to ensure disabled packages ;; We load the private packages file twice to ensure disabled packages
;; are seen ASAP, and a second time to ensure privately overridden ;; are seen ASAP, and a second time to ensure privately overridden
;; packages are properly overwritten. ;; packages are properly overwritten.
(doom--read-module-packages-file private-packages t t)) (doom--read-module-packages-file private-packages nil t))
(if all-p (if all-p
(mapc #'doom--read-module-packages-file (mapc #'doom--read-module-packages-file
(doom-files-in doom-modules-dir (doom-files-in doom-modules-dir

View file

@ -153,8 +153,8 @@ necessary package metadata is initialized and available for them."
(setq doom-disabled-packages nil (setq doom-disabled-packages nil
doom-packages (doom-package-list)) doom-packages (doom-package-list))
(cl-loop for (pkg . plist) in doom-packages (cl-loop for (pkg . plist) in doom-packages
for ignored = (eval (plist-get plist :ignore) t) for ignored = (plist-get plist :ignore)
for disabled = (eval (plist-get plist :disable) t) for disabled = (plist-get plist :disable)
if disabled if disabled
do (cl-pushnew pkg doom-disabled-packages) do (cl-pushnew pkg doom-disabled-packages)
else if (not ignored) else if (not ignored)
@ -221,48 +221,45 @@ Accepts the following properties:
Returns t if package is successfully registered, and nil if it was disabled Returns t if package is successfully registered, and nil if it was disabled
elsewhere." elsewhere."
(declare (indent defun)) (declare (indent defun))
(let ((old-plist (cdr (assq name doom-packages)))) `(let* ((name ',name)
;; Add current module to :modules (plist (cdr (assq name doom-packages))))
(let ((module-list (plist-get old-plist :modules)) (let ((module-list (plist-get plist :modules))
(module (doom-module-from-path))) (module ',(doom-module-from-path)))
(unless (member module module-list) (unless (member module module-list)
(plist-put! plist :modules (plist-put! plist :modules
(append module-list (append module-list
(list module) (list module)
nil)))) nil))))
;; Handle :built-in ;; Handle :built-in
(unless ignore (unless ,ignore
(when built-in (when-let (built-in ,built-in)
(doom-log "Ignoring built-in package %S" name) (doom-log "Ignoring built-in package %S" name)
(when (equal built-in '(quote prefer)) (when (eq built-in 'prefer)
(setq built-in `(locate-library ,(symbol-name name) nil doom--initial-load-path)))) (setq built-in '(locate-library ,(symbol-name name) nil doom--initial-load-path))))
(plist-put! plist :ignore built-in)) (plist-put! plist :ignore ,built-in))
;; DEPRECATED Translate :fetcher to :host ;; DEPRECATED Translate :fetcher to :host
(with-plist! plist (recipe) (with-plist! plist (recipe)
(with-plist! recipe (fetcher) (with-plist! recipe (fetcher)
(when fetcher (when fetcher
(message "%s\n%s" (message "%s\n%s"
(format "WARNING: The :fetcher property was used for the %S package." (format "WARNING: The :fetcher property was used for the %S package."
name) name)
"This property is deprecated. Replace it with :host.") "This property is deprecated. Replace it with :host.")
(plist-put! recipe :host fetcher) (plist-put! recipe :host fetcher)
(plist-delete! recipe :fetcher)) (plist-delete! recipe :fetcher))
(plist-put! plist :recipe recipe))) (plist-put! plist :recipe recipe)))
(doplist! ((prop val) plist) (doplist! ((prop val) ',plist plist)
(unless (null val) (unless (null val)
(plist-put! old-plist prop val))) (plist-put! plist prop val)))
(setq plist old-plist)
;; TODO Add `straight-use-package-pre-build-function' support (setf (alist-get name doom-packages) plist)
(macroexp-progn (if (not ,disable) t
(append `((setf (alist-get ',name doom-packages) ',plist)) (doom-log "Disabling package %S" name)
(when disable (cl-pushnew name doom-disabled-packages)
`((doom-log "Disabling package %S" ',name) nil)))
(add-to-list 'doom-disabled-packages ',name nil 'eq)
nil))))))
(defmacro disable-packages! (&rest packages) (defmacro disable-packages! (&rest packages)
"A convenience macro for disabling packages in bulk. "A convenience macro for disabling packages in bulk.