Skip to content

Commit 68c1a5d

Browse files
committed
[core] Install packages in order of declaration
In particular, do not install packages in alphabetical order. This means one can manually manage dependencies for packages installed via quelpa recipes, addressing #17176. This change should be safe, also the order of package installations was reversed before without obvious regressions (see previous commit). Note that we still use the alphabetically sorted list of packages in other contexts, such as when configuring packages, mostly for backward compatibility.
1 parent c2432dc commit 68c1a5d

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

core/core-configuration-layer.el

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ file. It can be overridden by users inside `dotspacemacs/user-init'.")
390390
"Hash map to index `cfgl-layer' objects by their names.")
391391

392392
(defvar configuration-layer--used-packages '()
393-
"An alphabetically sorted list of used package names.")
393+
"A list of used package names.")
394+
395+
(defvar configuration-layer--used-packages-sorted '()
396+
"Like `configuration-layer--used-packages', but sorted alphabetically.")
394397

395398
(defvar configuration-layer--indexed-packages (make-hash-table)
396399
"Hash map to index `cfgl-package' objects by their names.")
@@ -641,7 +644,7 @@ To prevent package from being installed or uninstalled set the variable
641644
(not (eq 'template spacemacs-load-dotspacemacs)))
642645
(configuration-layer/delete-orphan-packages packages))))
643646
;; configure used packages
644-
(configuration-layer//configure-packages configuration-layer--used-packages)
647+
(configuration-layer//configure-packages configuration-layer--used-packages-sorted)
645648
;; evaluate layer variables a second time to override default values set in
646649
;; packages configuration above
647650
(configuration-layer//set-layers-variables configuration-layer--used-layers)
@@ -922,7 +925,7 @@ a new object."
922925
"Describe a package in the context of the configuration layer system."
923926
(interactive
924927
(list (intern
925-
(completing-read "Package: " configuration-layer--used-packages))))
928+
(completing-read "Package: " configuration-layer--used-packages-sorted))))
926929
(help-setup-xref (list #'configuration-layer/describe-package
927930
pkg-symbol layer-list pkg-list)
928931
(called-interactively-p 'interactive))
@@ -1655,9 +1658,14 @@ RNAME is the name symbol of another existing layer."
16551658
(configuration-layer/make-packages-from-layers layers t)
16561659
(configuration-layer/make-packages-from-dotfile t)
16571660
(setq configuration-layer--used-packages
1658-
(sort (cl-delete-if-not #'configuration-layer/package-used-p
1659-
configuration-layer--used-packages)
1660-
#'string<))))
1661+
(cl-delete-if-not #'configuration-layer/package-used-p
1662+
;; Reverse such that we get the order in which
1663+
;; packages are declared in each layer of
1664+
;; `configuration-layer--used-layers' and
1665+
;; `dotspacemacs-additional-packages'.
1666+
(nreverse configuration-layer--used-packages))
1667+
configuration-layer--used-packages-sorted
1668+
(sort (cl-copy-list configuration-layer--used-packages) #'string<))))
16611669

16621670
(defun configuration-layer//load-layers-files (layer-names files)
16631671
"Load the files of list FILES for all passed LAYER-NAMES."
@@ -1754,10 +1762,10 @@ RNAME is the name symbol of another existing layer."
17541762
pkg-name)))
17551763
(oref layer packages)))))
17561764
(let ((last-buffer (current-buffer))
1757-
(sorted-pkg (sort inst-pkgs #'string<)))
1765+
(sorted-pkg (sort (cl-copy-list inst-pkgs) #'string<)))
17581766
(spacemacs-buffer/goto-buffer)
17591767
(goto-char (point-max))
1760-
(configuration-layer//install-packages sorted-pkg)
1768+
(configuration-layer//install-packages inst-pkgs)
17611769
(configuration-layer//configure-packages sorted-pkg)
17621770
(configuration-layer//load-layer-files layer '("keybindings"))
17631771
(oset layer lazy-install nil)
@@ -2134,7 +2142,7 @@ to update."
21342142
(configuration-layer/retrieve-package-archives nil 'force)
21352143
(setq configuration-layer--check-new-version-error-packages nil)
21362144
(let* ((distant-packages (configuration-layer//filter-distant-packages
2137-
configuration-layer--used-packages t))
2145+
configuration-layer--used-packages-sorted t))
21382146
(update-packages
21392147
(configuration-layer//get-packages-to-update distant-packages))
21402148
(skipped-count (length

doc/LAYERS.org

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,12 @@ The Spacemacs loading process can be summarized as follows:
413413

414414
Alternatively, if a package is part of the end user's
415415
=dotspacemacs-additional-packages=, it will also be installed.
416-
3. All packages which should be installed are installed in alphabetical order,
417-
=package.el= built-in Emacs library is in charge of implicit dependencies.
418-
Installed packages not following the rules of 2. are removed as well as
419-
their dependencies if possible. (This last behavior is optional but default.)
416+
3. New versions of built-in packages, and =bootstrap= and =pre= packages are
417+
installed first, then the remaining packages are installed in the order in
418+
which they are declared. The built-in Emacs library =package.el= is in charge
419+
of implicit dependencies. Installed packages not following the rules of 2.
420+
are removed as well as their dependencies if possible. (This last behavior is
421+
optional but default.)
420422
4. The =pre-init=, =init= and =post-init= functions for each installed package
421423
are executed in turn.
422424

0 commit comments

Comments
 (0)