Skip to content

Commit aff4cf0

Browse files
authored
Rework treatment of built-in packages (#16938)
* Move transient to bootstrap layer Transient is a built-in package, and also a dependency of many other packages users might install. It makes more sense to always configure it, also when the git layer is not used. * [core] Correctly initialize location of built-in packages Previously, if no location was specified, it was set to the default `elpa`. This did not mean, however, that the packages where installed from ELPA; the built-in packages were used regardless (they might not even be published on an ELPA, of course). Now we correctly set the location to `built-in`, in preparation to making `:location elpa` take effect for built-in packages, too. * [core] Ensure built-in packages with different locations are updated We need to account for built-in packages when installing, checking availability of new versions, updating, and rolling back packages. Also refactor the last call site of configuration-layer//delete-package that used package names instead of pkg-desc objects (namely configuration-layer/rollback), such that we can simplify the function. * [org] Remove `:min-version` for org package The package will now get updated by `configuration-layer/update-packages`. We do not need to manually bump the version anymore. * [core] Prevent outdated built-in packages from being loaded
1 parent 5451c1f commit aff4cf0

File tree

4 files changed

+109
-55
lines changed

4 files changed

+109
-55
lines changed

core/core-configuration-layer.el

Lines changed: 93 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,11 @@ installation of initialization.")
426426
directory with a name starting with `+'.")
427427

428428
(defvar update-packages-alist '()
429-
"Used to collect information about rollback packages in the
430-
cache folder.")
429+
"List used to collect information about rollback packages in the
430+
cache folder.
431+
432+
Each element is a cons cell of the form (PACKAGE-NAME . DIRECTORY),
433+
where DIRECTORY may be nil for built-in packages.")
431434

432435
(defun configuration-layer/load-lock-file ()
433436
"Load the .lock file"
@@ -825,7 +828,7 @@ a new object."
825828
(oset obj excluded
826829
(and (configuration-layer/layer-used-p layer-name)
827830
(or excluded (oref obj excluded))))
828-
(when location
831+
(if location
829832
(if (and (listp location)
830833
(eq (car location) 'recipe)
831834
(eq (plist-get (cdr location) :fetcher) 'local))
@@ -838,7 +841,9 @@ a new object."
838841
(oset
839842
obj location `(recipe :fetcher file :path ,path))))
840843
((eq 'dotfile layer-name) nil))
841-
(oset obj location location)))
844+
(oset obj location location))
845+
(when (and ownerp (package-built-in-p pkg-name))
846+
(oset obj location 'built-in)))
842847
;; cannot override protected packages
843848
(unless copyp
844849
;; a bootstrap package is protected
@@ -1699,7 +1704,9 @@ RNAME is the name symbol of another existing layer."
16991704
not-inst-count)
17001705
t)
17011706
(spacemacs//redisplay)
1702-
(unless (package-installed-p pkg-name min-version)
1707+
(unless (and (package-installed-p pkg-name min-version)
1708+
(not (and (package-built-in-p pkg-name)
1709+
(not (eq location 'built-in)))))
17031710
(condition-case-unless-debug err
17041711
(cond
17051712
((or (null pkg) (eq 'elpa location))
@@ -1774,25 +1781,53 @@ RNAME is the name symbol of another existing layer."
17741781
;; installation
17751782
(when upkg-names
17761783
(spacemacs-buffer/set-mode-line "Installing packages..." t)
1784+
;; Prevent built-in org from being loaded when updating consult, for example.
1785+
(dolist (pkg-name configuration-layer--used-packages)
1786+
(when (and (package-built-in-p pkg-name)
1787+
(not (memq pkg-name upkg-names)))
1788+
(package-activate pkg-name)))
17771789
(let ((delayed-warnings-backup delayed-warnings-list))
17781790
(spacemacs-buffer/append
17791791
(format "Found %s new package(s) to install...\n"
17801792
not-inst-count))
17811793
(configuration-layer/retrieve-package-archives)
17821794
(setq installed-count 0)
17831795
(spacemacs//redisplay)
1784-
;; bootstrap and pre step packages first
1785-
(dolist (pkg-name upkg-names)
1786-
(let ((pkg (configuration-layer/get-package pkg-name)))
1787-
(when (and pkg (memq (oref pkg step) '(bootstrap pre)))
1788-
(setq installed-count (1+ installed-count))
1789-
(configuration-layer//install-package pkg pkg-name installed-count not-inst-count))))
1790-
;; then all other packages
1791-
(dolist (pkg-name upkg-names)
1792-
(let ((pkg (configuration-layer/get-package pkg-name)))
1793-
(unless (and pkg (memq (oref pkg step) '(bootstrap pre)))
1794-
(setq installed-count (1+ installed-count))
1796+
1797+
;; We sort the packages to be installed as follows:
1798+
;; 1. built-in packages
1799+
;; 2. bootstrap and pre packages
1800+
;; 3. all other packages
1801+
;; In particular, we install new versions of built-in packages first,
1802+
;; to avoid having the built-in package loaded instead of the new one
1803+
;; (for example when another package only depends on an older version;
1804+
;; or does not explicitly depend on it, but requires some of its
1805+
;; features somewhere).
1806+
;; FIXME Dependencies between built-in packages that should get updated
1807+
;; could still lead to errors due to built-in versions being loaded. For
1808+
;; example, if hypothetically, org (optionally) requires transient in
1809+
;; the future, we should take care to update transient before org.
1810+
(let* (built-in bootstrap-pre remaining
1811+
sorted-upkg-names)
1812+
(dolist (pkg-name upkg-names)
1813+
(let ((pkg (configuration-layer/get-package pkg-name)))
1814+
(push pkg-name
1815+
(cond ((package-built-in-p pkg-name)
1816+
built-in)
1817+
((and pkg (or (eq (oref pkg step) 'bootstrap)
1818+
(eq (oref pkg step) 'pre)))
1819+
bootstrap-pre)
1820+
(t
1821+
remaining)))))
1822+
(setq sorted-upkg-names
1823+
(append (nreverse built-in)
1824+
(nreverse bootstrap-pre)
1825+
(nreverse remaining)))
1826+
(dolist (pkg-name sorted-upkg-names)
1827+
(cl-incf installed-count)
1828+
(let ((pkg (configuration-layer/get-package pkg-name)))
17951829
(configuration-layer//install-package pkg pkg-name installed-count not-inst-count))))
1830+
17961831
(spacemacs-buffer/append "\n")
17971832
(unless init-file-debug
17981833
;; get rid of all delayed warnings when byte-compiling packages
@@ -1857,7 +1892,11 @@ RNAME is the name symbol of another existing layer."
18571892
pkg-names (lambda (x)
18581893
(let* ((pkg (configuration-layer/get-package x))
18591894
(min-version (when pkg (oref pkg min-version))))
1860-
(not (package-installed-p x min-version))))))
1895+
(or (and pkg
1896+
(package-built-in-p x)
1897+
(not (eq 'built-in (oref pkg location)))
1898+
(not (assq x package-alist)))
1899+
(not (package-installed-p x min-version)))))))
18611900

18621901
(defun configuration-layer//get-package-recipe (pkg-name)
18631902
"Return the recipe for PKG-NAME if it has one."
@@ -1874,7 +1913,11 @@ RNAME is the name symbol of another existing layer."
18741913
(cur-version (configuration-layer//get-package-version-string pkg-name))
18751914
(quelpa-upgrade-p t)
18761915
new-version)
1877-
(when cur-version
1916+
(when (and cur-version
1917+
;; Consider built-in packages, but only when
1918+
;; they are installed from a different location.
1919+
(or (not (package-built-in-p pkg-name))
1920+
(and pkg (not (eq 'built-in (oref pkg :location))))))
18781921
(setq new-version
18791922
(if recipe
18801923
(or (quelpa-checkout (configuration-layer//make-quelpa-recipe pkg)
@@ -2187,12 +2230,14 @@ in the back-up directory."
21872230
(dolist (pkg update-packages)
21882231
(unless (memq pkg dotspacemacs-frozen-packages)
21892232
(let* ((src-dir (configuration-layer//get-package-directory pkg))
2190-
(dest-dir (expand-file-name
2191-
(concat rollback-dir
2192-
(file-name-as-directory
2193-
(file-name-nondirectory src-dir))))))
2194-
(copy-directory src-dir dest-dir 'keeptime 'create 'copy-content)
2195-
(push (cons pkg (file-name-nondirectory src-dir))
2233+
(dest-dir (and src-dir
2234+
(expand-file-name
2235+
(concat rollback-dir
2236+
(file-name-as-directory
2237+
(file-name-nondirectory src-dir)))))))
2238+
(when src-dir
2239+
(copy-directory src-dir dest-dir 'keeptime 'create 'copy-content))
2240+
(push (cons pkg (and src-dir (file-name-nondirectory src-dir)))
21962241
update-packages-alist))))
21972242
(spacemacs/dump-vars-to-file
21982243
'(update-packages-alist)
@@ -2283,13 +2328,14 @@ Rollback slots are stored in
22832328
(spacemacs//redisplay)
22842329
(dolist (apkg update-packages-alist)
22852330
(let* ((pkg (car apkg))
2286-
(pkg-dir-name (cdr apkg))
2331+
(pkg-dir-name (cdr apkg)) ; nil for built-in packages
22872332
(installed-ver
22882333
(configuration-layer//get-package-version-string pkg))
22892334
(elpa-dir (file-name-as-directory package-user-dir))
2290-
(src-dir (expand-file-name
2291-
(concat rollback-dir (file-name-as-directory
2292-
pkg-dir-name))))
2335+
(src-dir (and pkg-dir-name
2336+
(expand-file-name
2337+
(concat rollback-dir (file-name-as-directory
2338+
pkg-dir-name)))))
22932339
(dest-dir (expand-file-name
22942340
(concat elpa-dir (file-name-as-directory
22952341
pkg-dir-name)))))
@@ -2303,9 +2349,15 @@ Rollback slots are stored in
23032349
(spacemacs-buffer/replace-last-line
23042350
(format "--> rolling back package %s... [%s/%s]"
23052351
pkg rollbacked-count rollback-count) t)
2306-
(configuration-layer//package-delete pkg)
2307-
(copy-directory src-dir dest-dir
2308-
'keeptime 'create 'copy-content)))
2352+
(let ((pkg-desc (cadr (assq pkg package-alist))))
2353+
(cond
2354+
(pkg-desc
2355+
(configuration-layer//package-delete pkg-desc))
2356+
((package-built-in-p pkg)
2357+
(message "Skipping deletion of package %s since it is built-in." pkg))))
2358+
(when src-dir
2359+
(copy-directory src-dir dest-dir
2360+
'keeptime 'create 'copy-content))))
23092361
(spacemacs//redisplay)))
23102362
(spacemacs-buffer/append
23112363
(format "\n--> %s packages rolled back.\n" rollbacked-count))
@@ -2357,8 +2409,10 @@ depends on it."
23572409
(gethash pkg-name dependencies))))
23582410

23592411
(defun configuration-layer//get-package-directory (pkg-name)
2360-
"Return the directory path for package with name PKG-NAME."
2361-
(let ((pkg-desc (cadr (assq pkg-name package-alist))))
2412+
"Return the directory path for package with name PKG-NAME.
2413+
2414+
Return nil when the package is built-in, and no other version is installed."
2415+
(and-let* ((pkg-desc (cadr (assq pkg-name package-alist))))
23622416
(package-desc-dir pkg-desc)))
23632417

23642418
(defun configuration-layer//get-package-deps-from-alist (pkg-name)
@@ -2380,8 +2434,11 @@ depends on it."
23802434

23812435
(defun configuration-layer//get-package-version-string (pkg-name)
23822436
"Return the version string for package with name PKG-NAME."
2383-
(and-let* ((pkg-desc (cadr (assq pkg-name package-alist))))
2384-
(package-version-join (package-desc-version pkg-desc))))
2437+
(and-let* ((pkg-version
2438+
(or (and-let* ((pkg-desc (cadr (assq pkg-name package-alist))))
2439+
(package-desc-version pkg-desc))
2440+
(alist-get pkg-name package--builtin-versions))))
2441+
(package-version-join pkg-version)))
23852442

23862443
(defun configuration-layer//get-latest-package-version-string (pkg-name)
23872444
"Return the version string for package with name PKG-NAME."
@@ -2402,9 +2459,7 @@ depends on it."
24022459
(if (configuration-layer//system-package-p pkg-desc)
24032460
(message "Would have removed package %s but this is a system package so it has not been changed."
24042461
(package-desc-name pkg-desc))
2405-
(if (package-desc-p pkg-desc)
2406-
(package-delete pkg-desc t t)
2407-
(package-delete (car (alist-get pkg-desc package-alist)) t t))))
2462+
(package-delete pkg-desc t t)))
24082463

24092464
(defun configuration-layer/delete-orphan-packages (packages &optional include-system)
24102465
"Delete PACKAGES if they are orphan.

layers/+distributions/spacemacs-bootstrap/packages.el

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
(spacemacs-theme :location built-in)
4444
(which-key-posframe :step pre :toggle (and (consp dotspacemacs-which-key-position)
4545
(eq (car dotspacemacs-which-key-position) 'posframe)))
46-
dash))
46+
dash
47+
(transient :location elpa)))
4748

4849
;; bootstrap packages
4950

@@ -689,3 +690,15 @@ Press \\[which-key-toggle-persistent] to hide."
689690
(intern (format "posframe-poshandler-frame-%s"
690691
(cdr dotspacemacs-which-key-position))))
691692
(which-key-posframe-mode)))
693+
694+
(defun spacemacs-bootstrap/init-transient ()
695+
(use-package transient
696+
:defer t
697+
:init
698+
(setq-default transient-history-file (expand-file-name "transient/history.el"
699+
spacemacs-cache-directory))
700+
(setq-default transient-levels-file (expand-file-name "transient/levels.el"
701+
spacemacs-cache-directory))
702+
;; Values are the users saved preferences so they should persist.
703+
(setq-default transient-values-file (expand-file-name "transient/values.el"
704+
dotspacemacs-directory))))

layers/+emacs/org/packages.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
htmlize
3434
;; ob, org, org-agenda and org-contacts are installed by `org-contrib'
3535
(ob :location built-in)
36-
(org :location elpa :min-version "9.7.8")
36+
(org :location elpa)
3737
(org-agenda :location built-in)
3838
(org-alert :toggle org-enable-notifications)
3939
(org-contacts :toggle org-enable-org-contacts-support)

layers/+source-control/git/packages.el

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
org
4747
(orgit :requires org)
4848
(orgit-forge :requires (org forge))
49-
smeargle
50-
transient))
49+
smeargle))
5150

5251

5352
(defun git/pre-init-golden-ratio ()
@@ -323,19 +322,6 @@
323322
"gHh" 'smeargle-commits
324323
"gHt" 'smeargle)))
325324

326-
(defun git/pre-init-transient ()
327-
(setq-default transient-history-file (expand-file-name "transient/history.el"
328-
spacemacs-cache-directory))
329-
(setq-default transient-levels-file (expand-file-name "transient/levels.el"
330-
spacemacs-cache-directory))
331-
;; Values are the users saved preferences so they should persist.
332-
(setq-default transient-values-file (expand-file-name "transient/values.el"
333-
dotspacemacs-directory)))
334-
335-
(defun git/init-transient ()
336-
(use-package transient
337-
:defer t))
338-
339325
(defun git/init-forge ()
340326
(use-package forge
341327
:after magit

0 commit comments

Comments
 (0)