core: process all post-init function after all the init functions
With this commit, the new loading order for package configuration is: - pre-init functions for all packages - init function of all packages - post-init functions for all packages
This commit is contained in:
parent
80a10f79db
commit
4ecd015fe8
|
@ -1872,8 +1872,9 @@ RNAME is the name symbol of another existing layer."
|
|||
;; the packages in alphabetical order as usual.
|
||||
(push pkg packages-to-configure)
|
||||
(configuration-layer//pre-configure-package pkg)))))))
|
||||
;; actually configure packages in alphabetical order
|
||||
(mapc 'configuration-layer//configure-package (reverse packages-to-configure))))
|
||||
(setq packages-to-configure (reverse packages-to-configure))
|
||||
(mapc 'configuration-layer//configure-package packages-to-configure)
|
||||
(mapc 'configuration-layer//post-configure-package packages-to-configure)))
|
||||
|
||||
(defun configuration-layer/get-location-directory (pkg-name location owner)
|
||||
"Return the location on disk for PKG."
|
||||
|
@ -1935,13 +1936,17 @@ LAYER must not be the owner of PKG."
|
|||
(oref pkg :pre-layers))))
|
||||
|
||||
(defun configuration-layer//configure-package (pkg)
|
||||
"Configure PKG object (call their init function and post-init functions)."
|
||||
"Configure PKG object, i.e. call its post-init function."
|
||||
(let* ((pkg-name (oref pkg :name))
|
||||
(owner (car (oref pkg :owners))))
|
||||
;; init
|
||||
(spacemacs-buffer/message (format "%S -> init (%S)..." pkg-name owner))
|
||||
(funcall (intern (format "%S/init-%S" owner pkg-name)))
|
||||
;; post-init
|
||||
(funcall (intern (format "%S/init-%S" owner pkg-name)))))
|
||||
|
||||
(defun configuration-layer//post-configure-package (pkg)
|
||||
"Post-configure PKG object, i.e. call its post-init functions."
|
||||
(let* ((pkg-name (oref pkg :name))
|
||||
(owner (car (oref pkg :owners))))
|
||||
(mapc
|
||||
(lambda (layer)
|
||||
(when (configuration-layer/layer-used-p layer)
|
||||
|
|
|
@ -2084,6 +2084,24 @@
|
|||
(layer2/pre-init-pkg nil ((:output nil :occur 1))))
|
||||
(configuration-layer//pre-configure-package pkg))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; configuration-layer//post-configure-package
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(ert-deftest test-post-configure-package--post-init-is-evaluated ()
|
||||
(let ((pkg (cfgl-package "pkg" :name 'pkg :owners '(layer1) :post-layers '(layer2)))
|
||||
configuration-layer--used-layers
|
||||
(configuration-layer--indexed-layers (make-hash-table :size 1024))
|
||||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(helper--add-layers `(,(cfgl-layer "layer1" :name 'layer1)
|
||||
,(cfgl-layer "layer2" :name 'layer2)) t)
|
||||
(defun layer1/init-pkg nil)
|
||||
(defun layer2/post-init-pkg nil)
|
||||
(mocker-let
|
||||
((spacemacs-buffer/message (m) ((:output nil)))
|
||||
(layer2/post-init-pkg nil ((:output nil :occur 1))))
|
||||
(configuration-layer//post-configure-package pkg))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; configuration-layer//configure-package
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
@ -2100,35 +2118,6 @@
|
|||
(layer1/init-pkg nil ((:output nil :occur 1))))
|
||||
(configuration-layer//configure-package pkg))))
|
||||
|
||||
(ert-deftest test-configure-package--post-init-is-evaluated ()
|
||||
(let ((pkg (cfgl-package "pkg" :name 'pkg :owners '(layer1) :post-layers '(layer2)))
|
||||
configuration-layer--used-layers
|
||||
(configuration-layer--indexed-layers (make-hash-table :size 1024))
|
||||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(helper--add-layers `(,(cfgl-layer "layer1" :name 'layer1)
|
||||
,(cfgl-layer "layer2" :name 'layer2)) t)
|
||||
(defun layer1/init-pkg nil)
|
||||
(defun layer2/post-init-pkg nil)
|
||||
(mocker-let
|
||||
((spacemacs-buffer/message (m) ((:output nil)))
|
||||
(layer2/post-init-pkg nil ((:output nil :occur 1))))
|
||||
(configuration-layer//configure-package pkg))))
|
||||
|
||||
(ert-deftest test-configure-package--post-init-is-evaluated-after-init ()
|
||||
(let ((pkg (cfgl-package "pkg" :name 'pkg :owners '(layer1) :post-layers '(layer2)))
|
||||
configuration-layer--used-layers
|
||||
(configuration-layer--indexed-layers (make-hash-table :size 1024))
|
||||
(witness nil)
|
||||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(helper--add-layers `(,(cfgl-layer "layer1" :name 'layer1)
|
||||
,(cfgl-layer "layer2" :name 'layer2)) t)
|
||||
(defun layer1/init-pkg () (push 'init witness))
|
||||
(defun layer2/post-init-pkg () (push 'post-init witness))
|
||||
(mocker-let
|
||||
((spacemacs-buffer/message (m) ((:output nil))))
|
||||
(configuration-layer//configure-package pkg)
|
||||
(should (equal '(post-init init) witness)))))
|
||||
|
||||
(ert-deftest test-configure-package--disabled-for-does-not-call-pre-post-init ()
|
||||
(let ((pkg (cfgl-package "pkg" :name 'pkg :owners '(layer1)
|
||||
:pre-layers '(layer2)
|
||||
|
@ -2168,6 +2157,7 @@
|
|||
((spacemacs-buffer/message (m) ((:output nil))))
|
||||
(configuration-layer//pre-configure-package pkg)
|
||||
(configuration-layer//configure-package pkg)
|
||||
(configuration-layer//post-configure-package pkg)
|
||||
(should (equal '(post-init init pre-init) witness)))))
|
||||
|
||||
(ert-deftest test-configure-package--enabled-for-nil-does-not-call-pre-post-init ()
|
||||
|
@ -2233,6 +2223,24 @@
|
|||
(configuration-layer//configure-packages-2 `(,(oref pkg :name)))
|
||||
(should (equal '(init pre-init) witness)))))
|
||||
|
||||
(ert-deftest test-configure-packages-2--post-init-is-evaluated-after-init ()
|
||||
(let ((pkg (cfgl-package "pkg" :name 'pkg :owners '(layer1) :post-layers '(layer2)))
|
||||
configuration-layer--used-layers
|
||||
(configuration-layer--indexed-layers (make-hash-table :size 1024))
|
||||
configuration-layer--used-packages
|
||||
(configuration-layer--indexed-packages (make-hash-table :size 2048))
|
||||
(witness nil)
|
||||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(helper--add-layers `(,(cfgl-layer "layer1" :name 'layer1)
|
||||
,(cfgl-layer "layer2" :name 'layer2)) t)
|
||||
(helper--add-packages (list pkg) t)
|
||||
(defun layer1/init-pkg () (push 'init witness))
|
||||
(defun layer2/post-init-pkg () (push 'post-init witness))
|
||||
(mocker-let
|
||||
((spacemacs-buffer/loading-animation nil ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name)))
|
||||
(should (equal '(post-init init) witness)))))
|
||||
|
||||
(ert-deftest test-configure-packages-2--package-w/-layer-owner-is-configured()
|
||||
(let ((pkg (cfgl-package "pkg" :name 'pkg :owners '(layer1)))
|
||||
configuration-layer--used-packages
|
||||
|
|
Loading…
Reference in New Issue