core: remove 'private value for :location

While doing the tests I encountered an edge case where a package owned
by the dotfile could be passed either a 'private or 'local location
which is ambiguous (moreover where do we put packages with 'local
location ?).

We remove the ambiguity by removing the 'private value and push the
path ~/.emacs.d/private/local/pkg/ when the owner of a local
package PKG is the dotfile.

When the owner of a local package is a layer then the load path is
in the "local" subdirectory of the layer directory. It adds no value
to use the old 'private location in this case.
This commit is contained in:
syl20bnr 2015-09-20 00:49:18 -04:00
parent 1fc73d671f
commit f294ba3887
2 changed files with 106 additions and 25 deletions

View File

@ -102,7 +102,7 @@
(location :initarg :location
:initform elpa
:type (satisfies (lambda (x)
(or (member x '(local elpa private))
(or (member x '(local elpa))
(and (listp x) (eq 'recipe (car x))))))
:documentation "Location of the package.")
(step :initarg :step
@ -363,7 +363,7 @@ Properties that can be copied are `:location', `:step' and `:excluded'."
"Return the distant packages (ie to be intalled) that are effectively used."
(configuration-layer/filter-objects
packages (lambda (x) (and (not (null (oref x :owner)))
(not (memq (oref x :location) '(local private)))
(not (eq (oref x :location) 'local))
(not (oref x :excluded))))))
(defun configuration-layer//get-private-layer-dir (name)
@ -739,22 +739,6 @@ path."
(dolist (pkg packages)
(spacemacs-buffer/loading-animation)
(let ((pkg-name (oref pkg :name)))
;; load-path
(pcase (oref pkg :location)
(`local
(when (oref pkg :owner)
(let* ((owner (object-assoc (oref pkg :owner)
:name configuration-layer--layers))
(dir (oref owner :dir)))
(unless (eq owner 'dotfile)
(push (format "%slocal/%S/" dir pkg-name) load-path)
;; TODO remove extensions in 0.105.0
(push (format "%sextensions/%S/" dir pkg-name) load-path)))))
(`private
(push (configuration-layer//get-private-layer-dir
(symbol-name (oref pkg :name)))
load-path)))
;; configuration
(cond
((oref pkg :excluded)
(spacemacs-buffer/message
@ -762,13 +746,31 @@ path."
((null (oref pkg :owner))
(spacemacs-buffer/message
(format "%S ignored since it has no owner layer." pkg-name)))
((eq 'dotfile (oref pkg :owner))
(configuration-layer//activate-package pkg-name)
(spacemacs-buffer/message
(format "%S is configured in the dotfile." pkg-name)))
(t
(configuration-layer//activate-package pkg-name)
(configuration-layer//configure-package pkg))))))
;; load-path
(when (eq 'local (oref pkg :location))
(if (eq 'dotfile (oref pkg :owner))
;; local packages owned by dotfile are stored in private/local
(push (file-name-as-directory
(concat configuration-layer-private-directory
"local/"
(symbol-name (oref pkg :name))))
load-path)
(let* ((owner (object-assoc (oref pkg :owner)
:name configuration-layer--layers))
(dir (when owner (oref owner :dir))))
(push (format "%slocal/%S/" dir pkg-name) load-path)
;; TODO remove extensions in 0.105.0
(push (format "%sextensions/%S/" dir pkg-name) load-path))))
;; configuration
(cond
((eq 'dotfile (oref pkg :owner))
(configuration-layer//activate-package pkg-name)
(spacemacs-buffer/message
(format "%S is configured in the dotfile." pkg-name)))
(t
(configuration-layer//activate-package pkg-name)
(configuration-layer//configure-package pkg))))))))
(defun configuration-layer//configure-package (pkg)
"Configure PKG."

View File

@ -496,7 +496,6 @@
;; configuration-layer//configure-package
;; ---------------------------------------------------------------------------
(ert-deftest test-configure-package--init-is-evaluated ()
(let ((pkg (cfgl-package "pkg" :name 'pkg :owner 'layer1))
(configuration-layer--layers `(,(cfgl-layer "layer1" :name 'layer1)))
@ -579,6 +578,86 @@
(configuration-layer//configure-package pkg)
(should (equal '(init) witness)))))
;; ---------------------------------------------------------------------------
;; configuration-layer//configure-packages-2
;; ---------------------------------------------------------------------------
(ert-deftest test-configure-packages-2--package-w/-layer-owner-is-configured()
(let ((pkg (cfgl-package "pkg" :name 'pkg :owner 'layer1))
(mocker-mock-default-record-cls 'mocker-stub-record))
(mocker-let
((configuration-layer//configure-package (p) ((:occur 1)))
(spacemacs-buffer/loading-animation nil ((:output nil))))
(configuration-layer//configure-packages-2 `(,pkg)))))
(ert-deftest test-configure-packages-2--excluded-package-is-not-configured()
(let ((pkg (cfgl-package "pkg" :name 'pkg :owner 'layer1 :excluded t))
(mocker-mock-default-record-cls 'mocker-stub-record))
(mocker-let
((configuration-layer//configure-package (p) nil)
(spacemacs-buffer/loading-animation nil ((:output nil)))
(spacemacs-buffer/message (m) ((:output nil))))
(configuration-layer//configure-packages-2 `(,pkg)))))
(ert-deftest test-configure-packages-2--package-w/o-owner-is-not-configured()
(let ((pkg (cfgl-package "pkg" :name 'pkg :owner nil))
(mocker-mock-default-record-cls 'mocker-stub-record))
(mocker-let
((configuration-layer//configure-package (p) nil)
(spacemacs-buffer/loading-animation nil ((:output nil)))
(spacemacs-buffer/message (m) ((:output nil))))
(configuration-layer//configure-packages-2 `(,pkg)))))
(ert-deftest
test-configure-packages-2--package-owned-by-dotfile-is-not-configured()
(let ((pkg (cfgl-package "pkg" :name 'pkg :owner 'dotfile))
(mocker-mock-default-record-cls 'mocker-stub-record))
(mocker-let
((configuration-layer//configure-package (p) nil)
(spacemacs-buffer/loading-animation nil ((:output nil)))
(spacemacs-buffer/message (m) ((:output nil))))
(configuration-layer//configure-packages-2 `(,pkg)))))
(ert-deftest
test-configure-packages-2--local-package-w/-layer-owner-update-load-path()
(let ((pkg (cfgl-package "pkg" :name 'pkg :owner 'layer1 :location 'local))
(configuration-layer--layers `(,(cfgl-layer "layer1"
:name 'layer1
:dir "/a/path/")))
(expected-load-path load-path)
(mocker-mock-default-record-cls 'mocker-stub-record))
(mocker-let
((spacemacs-buffer/loading-animation nil ((:output nil)))
(configuration-layer//configure-package (p) ((:occur 1))))
(configuration-layer//configure-packages-2 `(,pkg))
(push "/a/path/local/pkg/" expected-load-path)
(push "/a/path/extensions/pkg/" expected-load-path)
(should (equal expected-load-path load-path)))))
(ert-deftest
test-configure-packages-2--local-package-w/-dotfile-owner-update-load-path()
(let ((pkg (cfgl-package "pkg" :name 'pkg :owner 'dotfile :location 'local))
(expected-load-path load-path)
(mocker-mock-default-record-cls 'mocker-stub-record))
(mocker-let
((spacemacs-buffer/loading-animation nil ((:output nil))))
(configuration-layer//configure-packages-2 `(,pkg))
(push (file-name-as-directory
(concat configuration-layer-private-directory "local/pkg"))
expected-load-path)
(should (equal expected-load-path load-path)))))
(ert-deftest
test-configure-packages-2--local-package-w/o-owner-doesnt-update-load-path()
(let ((pkg (cfgl-package "pkg" :name 'pkg :owner nil :location 'local))
(old-load-path load-path)
(mocker-mock-default-record-cls 'mocker-stub-record))
(mocker-let
((spacemacs-buffer/loading-animation nil ((:output nil)))
(spacemacs-buffer/message (m) ((:output nil))))
(configuration-layer//configure-packages-2 `(,pkg))
(should (equal load-path old-load-path)))))
;; ---------------------------------------------------------------------------
;; configuration-layer//sort-packages
;; ---------------------------------------------------------------------------