core: Split configuration-layer/make-packages-from-layers
Split the function in two functions: - configuration-layer/make-packages-from-layers - configuration-layer/make-packages-from-dotfile
This commit is contained in:
parent
f7668181d6
commit
7a9f031e2b
|
@ -397,7 +397,8 @@ If NO-INSTALL is non nil then install steps are skipped."
|
|||
(configuration-layer/declare-layer layer)
|
||||
(let* ((obj (configuration-layer/get-layer layer))
|
||||
(pkgs (when obj (oref obj :packages))))
|
||||
(configuration-layer/make-packages-from-layers (list layer))
|
||||
(configuration-layer/make-packages-from-layers
|
||||
(list layer))
|
||||
(dolist (pkg pkgs)
|
||||
(let ((pkg-name (if (listp pkg) (car pkg) pkg)))
|
||||
(add-to-list 'all-other-packages pkg-name))))))
|
||||
|
@ -557,10 +558,11 @@ If TOGGLEP is nil then `:toggle' parameter is ignored."
|
|||
layer-name pkg-name)))
|
||||
(post-init-func (intern (format "%S/post-init-%S"
|
||||
layer-name pkg-name)))
|
||||
(ownerp (or (eq 'dotfile layer-name)
|
||||
(fboundp init-func)))
|
||||
(copyp (not (null obj)))
|
||||
(obj (if obj obj (cfgl-package pkg-name-str :name pkg-name))))
|
||||
(obj (if obj obj (cfgl-package pkg-name-str :name pkg-name)))
|
||||
(ownerp (or (and (eq 'dotfile layer-name)
|
||||
(null (oref obj :owners)))
|
||||
(fboundp init-func))))
|
||||
(when min-version (oset obj :min-version (version-to-list min-version)))
|
||||
(when step (oset obj :step step))
|
||||
(when toggle (oset obj :toggle toggle))
|
||||
|
@ -869,8 +871,8 @@ USEDP if non-nil indicates that made packages are used packages."
|
|||
(configuration-layer/make-packages-from-layers
|
||||
(configuration-layer/get-layers-list) usedp))
|
||||
|
||||
(defun configuration-layer/make-packages-from-layers (layer-names
|
||||
&optional usedp dotfile)
|
||||
(defun configuration-layer/make-packages-from-layers
|
||||
(layer-names &optional usedp)
|
||||
"Read the package lists of layers with name LAYER-NAMES and create packages.
|
||||
USEDP if non-nil indicates that made packages are used packages.
|
||||
DOTFILE if non-nil will process the dotfile `dotspacemacs-additional-packages'
|
||||
|
@ -884,9 +886,11 @@ variable as well."
|
|||
(setq obj (configuration-layer/make-package pkg layer-name obj))
|
||||
(setq obj (configuration-layer/make-package pkg layer-name)))
|
||||
(configuration-layer//add-package obj (and (oref obj :owners)
|
||||
usedp))))))
|
||||
;; additional and excluded packages from dotfile
|
||||
(when dotfile
|
||||
usedp)))))))
|
||||
|
||||
(defun configuration-layer/make-packages-from-dotfile (&optional usedp)
|
||||
"Read the additonal packages declared in the dotfile and create packages.
|
||||
USEDP if non-nil indicates that made packages are used packages."
|
||||
(dolist (pkg dotspacemacs-additional-packages)
|
||||
(let* ((pkg-name (if (listp pkg) (car pkg) pkg))
|
||||
(obj (configuration-layer/get-package pkg-name)))
|
||||
|
@ -899,7 +903,7 @@ variable as well."
|
|||
(unless obj
|
||||
(setq obj (configuration-layer/make-package xpkg 'dotfile)))
|
||||
(configuration-layer//add-package obj usedp)
|
||||
(oset obj :excluded t)))))
|
||||
(oset obj :excluded t))))
|
||||
|
||||
(defun configuration-layer/lazy-install (layer-name &rest props)
|
||||
"Configure auto-installation of layer with name LAYER-NAME."
|
||||
|
@ -1181,8 +1185,8 @@ wether the declared layer is an used one or not."
|
|||
"Declare used packages contained in LAYERS."
|
||||
(setq configuration-layer--used-packages nil)
|
||||
(let* ((warning-minimum-level :error))
|
||||
;; first pass
|
||||
(configuration-layer/make-packages-from-layers layers t t)
|
||||
(configuration-layer/make-packages-from-layers layers t)
|
||||
(configuration-layer/make-packages-from-dotfile t)
|
||||
(setq configuration-layer--used-packages
|
||||
(configuration-layer//sort-packages
|
||||
configuration-layer--used-packages))))
|
||||
|
|
|
@ -611,6 +611,24 @@
|
|||
(should (equal expected
|
||||
(configuration-layer/make-package pkg 'layer1 obj)))))
|
||||
|
||||
(ert-deftest test-make-package--bootstrap-package-are-protected ()
|
||||
(let* (configuration-layer--used-layers
|
||||
(configuration-layer--indexed-layers (make-hash-table :size 1024))
|
||||
(pkg '(testpkg :step bootstrap))
|
||||
(expected (cfgl-package "testpkg"
|
||||
:name 'testpkg
|
||||
:owners '(layer-bootstrap-protected-1)
|
||||
:step 'bootstrap
|
||||
:protected t)))
|
||||
(defun layer-bootstrap-protected-1/init-testpkg nil)
|
||||
(helper--set-layers
|
||||
`(,(cfgl-layer "layer-bootstrap-protected-1"
|
||||
:name 'layer-bootstrap-protected-1)) t)
|
||||
(should
|
||||
(equal
|
||||
expected
|
||||
(configuration-layer/make-package pkg 'layer-bootstrap-protected-1)))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; configuration-layer//get-distant-packages
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
@ -893,52 +911,6 @@
|
|||
(equal (cfgl-package "pkg1" :name 'pkg1 :owners '(layer9))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg1))))))
|
||||
|
||||
(ert-deftest test-make-packages-from-layers--dotfile-excludes-pkg2-in-layer-11 ()
|
||||
(let* ((layer11 (cfgl-layer "layer11"
|
||||
:name 'layer11
|
||||
:dir "/path/"
|
||||
:packages '(pkg1 pkg2 pkg3)))
|
||||
(dotspacemacs-excluded-packages '(pkg2))
|
||||
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))
|
||||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(helper--set-layers (list layer11) t)
|
||||
(defun layer11/init-pkg1 nil)
|
||||
(defun layer11/init-pkg2 nil)
|
||||
(defun layer11/init-pkg3 nil)
|
||||
(configuration-layer/make-packages-from-layers '(layer11) 'used 'dotfile)
|
||||
(should
|
||||
(and (equal (cfgl-package "pkg3" :name 'pkg3 :owners '(layer11))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg3))
|
||||
(equal (cfgl-package "pkg2" :name 'pkg2 :owners '(layer11) :excluded t)
|
||||
(ht-get configuration-layer--indexed-packages 'pkg2))
|
||||
(equal (cfgl-package "pkg1" :name 'pkg1 :owners '(layer11))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg1))))))
|
||||
|
||||
(ert-deftest test-make-packages-from-layers--dotfile-declares-and-owns-one-additional-package ()
|
||||
(let* ((layer12 (cfgl-layer "layer12"
|
||||
:name 'layer12
|
||||
:dir "/path/"
|
||||
:packages '(pkg1 pkg2)))
|
||||
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))
|
||||
(dotspacemacs-additional-packages '(pkg3)))
|
||||
(helper--set-layers (list layer12) t)
|
||||
(defun layer12/init-pkg1 nil)
|
||||
(defun layer12/init-pkg2 nil)
|
||||
(configuration-layer/make-packages-from-layers '(layer12) 'used 'dotfile)
|
||||
(should
|
||||
(and (equal (cfgl-package "pkg3" :name 'pkg3 :owners '(dotfile))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg3))
|
||||
(equal (cfgl-package "pkg2" :name 'pkg2 :owners '(layer12))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg2))
|
||||
(equal (cfgl-package "pkg1" :name 'pkg1 :owners '(layer12))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg1))))))
|
||||
|
||||
(ert-deftest test-make-packages-from-layers--last-owner-can-overwrite-location ()
|
||||
(let* ((layer13 (cfgl-layer "layer13"
|
||||
:name 'layer13
|
||||
|
@ -1082,31 +1054,7 @@
|
|||
:toggle '(foo-toggle))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg1))))))
|
||||
|
||||
(ert-deftest test-make-packages-from-layers--new-owner-layer-can-override-toggle ()
|
||||
(let* ((layer22 (cfgl-layer "layer22"
|
||||
:name 'layer22
|
||||
:dir "/path/"
|
||||
:packages '((pkg1 :toggle (foo-toggle)))))
|
||||
(layer23 (cfgl-layer "layer23"
|
||||
:name 'layer23
|
||||
:dir "/path/"
|
||||
:packages '((pkg1 :toggle (bar-toggle)))))
|
||||
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))
|
||||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(helper--set-layers (list layer22 layer23) t)
|
||||
(defun layer22/init-pkg1 nil)
|
||||
(defun layer23/init-pkg1 nil)
|
||||
(configuration-layer/make-packages-from-layers '(layer22 layer23))
|
||||
(should (equal (cfgl-package "pkg1"
|
||||
:name 'pkg1
|
||||
:owners '(layer23 layer22)
|
||||
:toggle '(bar-toggle))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg1)))))
|
||||
|
||||
(ert-deftest test-make-packages-from-layers--dotfile-additional-pkg-can-override-toggle ()
|
||||
(ert-deftest test-make-packages-from-layers--layer-can-override-toggle ()
|
||||
(let* ((layer22 (cfgl-layer "layer22"
|
||||
:name 'layer22
|
||||
:dir "/path/"
|
||||
|
@ -1197,6 +1145,76 @@
|
|||
:location 'local)
|
||||
(ht-get configuration-layer--indexed-packages 'pkg2))))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; configuration-layer/make-packages-from-dotfile
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(ert-deftest test-make-packages-from-dotfile--dotfile-declares-and-owns-one-additional-package ()
|
||||
(let* ((layer-dotfile-1 (cfgl-layer "layer-dotfile-1"
|
||||
:name 'layer-dotfile-1
|
||||
:dir "/path/"
|
||||
:packages '(pkg1 pkg2)))
|
||||
(dotspacemacs-additional-packages '(pkg3))
|
||||
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)))
|
||||
(defun layer-dotfile-1/init-pkg1 nil)
|
||||
(defun layer-dotfile-1/init-pkg2 nil)
|
||||
(helper--set-layers (list layer-dotfile-1) t)
|
||||
(configuration-layer/make-packages-from-layers '(layer-dotfile-1) 'used)
|
||||
(configuration-layer/make-packages-from-dotfile 'used)
|
||||
(should
|
||||
(and (equal (cfgl-package "pkg3" :name 'pkg3 :owners '(dotfile))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg3))
|
||||
(equal (cfgl-package "pkg2" :name 'pkg2 :owners '(layer-dotfile-1))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg2))
|
||||
(equal (cfgl-package "pkg1" :name 'pkg1 :owners '(layer-dotfile-1))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg1))))))
|
||||
|
||||
(ert-deftest test-make-packages-from-dotfile--dotfile-cannot-own-package-owned-by-layer ()
|
||||
(let* ((layer-dotfile-2 (cfgl-layer "layer-dotfile-2"
|
||||
:name 'layer-dotfile-2
|
||||
:dir "/path/"
|
||||
:packages '(pkg1)))
|
||||
(dotspacemacs-additional-packages '(pkg1))
|
||||
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)))
|
||||
(defun layer-dotfile-2/init-pkg1 nil)
|
||||
(helper--set-layers (list layer-dotfile-2) t)
|
||||
(configuration-layer/make-packages-from-layers '(layer-dotfile-2) 'used)
|
||||
(configuration-layer/make-packages-from-dotfile 'used)
|
||||
(should
|
||||
(equal (cfgl-package "pkg1" :name 'pkg1 :owners '(layer-dotfile-2))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg1)))))
|
||||
|
||||
(ert-deftest test-make-packages-from-dotfile--dotfile-excludes-pkg2-in-layer-11 ()
|
||||
(let* ((layer-dotfile-3 (cfgl-layer "layer-dotfile-3"
|
||||
:name 'layer-dotfile-3
|
||||
:dir "/path/"
|
||||
:packages '(pkg1 pkg2 pkg3)))
|
||||
(dotspacemacs-excluded-packages '(pkg2))
|
||||
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))
|
||||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(defun layer-dotfile-3/init-pkg1 nil)
|
||||
(defun layer-dotfile-3/init-pkg2 nil)
|
||||
(defun layer-dotfile-3/init-pkg3 nil)
|
||||
(helper--set-layers (list layer-dotfile-3) t)
|
||||
(configuration-layer/make-packages-from-layers '(layer-dotfile-3) 'used)
|
||||
(configuration-layer/make-packages-from-dotfile 'used)
|
||||
(should
|
||||
(and (equal (cfgl-package "pkg3" :name 'pkg3 :owners '(layer-dotfile-3))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg3))
|
||||
(equal (cfgl-package "pkg2" :name 'pkg2 :owners '(layer-dotfile-3) :excluded t)
|
||||
(ht-get configuration-layer--indexed-packages 'pkg2))
|
||||
(equal (cfgl-package "pkg1" :name 'pkg1 :owners '(layer-dotfile-3))
|
||||
(ht-get configuration-layer--indexed-packages 'pkg1))))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; configuration-layer/make-all-packages
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue