Skip to content

Commit 4a2e2e5

Browse files
SpacemacsBotSpacemacsBot
andauthored
[bot] "built_in_updates" Fri Feb 20 18:28:45 UTC 2026 (#17236)
Co-authored-by: SpacemacsBot <not@an.actual.email.beep.boop>
1 parent d1ac570 commit 4a2e2e5

File tree

2 files changed

+203
-130
lines changed

2 files changed

+203
-130
lines changed

core/libs/package-build.el

Lines changed: 125 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ Otherwise do nothing. FORMAT-STRING and ARGS are as per that function."
327327
(when package-build-verbose
328328
(apply #'message format-string args)))
329329

330+
(define-error 'package-build-error "Package build error")
331+
330332
(defun package-build--error (package format-string &rest args)
331333
"Behave similar to `error' but with additional logging.
332334
Log the error to \"errors.log\" in `package-build-archive-dir'.
@@ -335,23 +337,49 @@ package. PACKAGE identifies a package, it must be a package
335337
name, a `package-recipe' object or nil, if the command is not
336338
being run for a particular package."
337339
(declare (indent defun))
338-
(let ((err (apply #'format-message format-string args)))
339-
;; That's a bit of an inconvenient interface...
340-
(with-temp-buffer
341-
(insert (format "%s %-25s %s\n"
342-
(format-time-string "%FT%T%z" nil t)
343-
(if (cl-typep package 'package-recipe)
344-
(oref package name)
345-
(or package "n/a"))
346-
err))
347-
(unless (eq (char-before) ?\n)
348-
(insert "\n"))
349-
(goto-char (point-min))
350-
(append-to-file
351-
(point)
352-
(1+ (line-end-position))
353-
(expand-file-name "errors.log" package-build-archive-dir)))
354-
(error "%s" err)))
340+
(let ((message (apply #'format-message format-string args)))
341+
(package-build--log package message)
342+
(signal 'package-build-error message)))
343+
344+
(defun package-build--log (package message)
345+
(with-temp-buffer
346+
(insert (format "%s %-25s %s\n"
347+
(format-time-string "%FT%T%z" nil t)
348+
(if (cl-typep package 'package-recipe)
349+
(oref package name)
350+
(or package "n/a"))
351+
message))
352+
(let ((file (expand-file-name "errors.log" package-build-archive-dir))
353+
(delay 0.1))
354+
(while (and (< delay 5)
355+
(condition-case err
356+
(progn (append-to-file (point-min) (point-max) file) nil)
357+
(file-locked (setq delay (* 2 delay)) :retry)
358+
(t (message "LOGGING ERROR: %s" err) nil)))))))
359+
360+
(defmacro package-build--static-if (condition then-form &rest else-forms)
361+
(declare (indent 2)
362+
(debug (sexp sexp &rest sexp)))
363+
(if (eval condition lexical-binding)
364+
then-form
365+
(cons 'progn else-forms)))
366+
367+
(defmacro package-build--log-errors (&rest body)
368+
(declare (indent 1))
369+
(package-build--static-if (fboundp 'handler-bind) ;Emacs >= 30.1
370+
`(handler-bind
371+
((error (lambda (err)
372+
(unless (eq (car err) 'package-build-error)
373+
(package-build--log name err)))))
374+
,@body)
375+
;; When using Emacs < 30.1 we have to choose between
376+
;; 1. Logging a summary to errors.log
377+
;; `(condition-case err
378+
;; (progn ,@body)
379+
;; (package-build-error nil)
380+
;; (error (package-build--log name err)))
381+
;; 2. Logging the (correct) backtrace to NAME.log and stdout.
382+
`(progn ,@body)))
355383

356384
;;; Version Handling
357385
;;;; Common
@@ -392,33 +420,33 @@ or snapshots are build.")
392420
(oset rcp revdesc revdesc))))
393421

394422
(cl-defmethod package-build--select-commit ((rcp package-git-recipe) rev exact)
395-
(if-let ((commit
396-
(car (apply #'process-lines
397-
"git" "log" "-n1" "--first-parent" "--no-show-signature"
398-
"--pretty=format:%H %cd" "--date=unix" rev
399-
(and (not exact)
400-
(cons "--" (package-build--spec-globs rcp)))))))
423+
(if-let* ((commit
424+
(car (apply #'process-lines
425+
"git" "log" "-n1" "--first-parent" "--no-show-signature"
426+
"--pretty=format:%H %cd" "--date=unix" rev
427+
(and (not exact)
428+
(cons "--" (package-build--spec-globs rcp)))))))
401429
(pcase-let ((`(,hash ,time) (split-string commit " ")))
402430
(list hash (string-to-number time)))
403-
(package-build--error (oref rcp name)
431+
(package-build--error rcp
404432
"No matching file(s) found in any reachable commit using %S files spec"
405433
(or (oref rcp files) 'default))))
406434

407435
(cl-defmethod package-build--select-commit ((rcp package-hg-recipe) rev exact)
408-
(if-let ((commit
409-
(car (apply #'process-lines
410-
;; The "date" keyword uses UTC. The "hgdate" filter
411-
;; returns two integers separated by a space; the
412-
;; unix timestamp and the timezone offset. We use
413-
;; "hgdate" because that makes it easier to discard
414-
;; the time zone offset, which doesn't interest us.
415-
"hg" "log" "--limit" "1"
416-
"--template" "{node} {date|hgdate}\n" "--rev" rev
417-
(and (not exact)
418-
(cons "--" (package-build--spec-globs rcp)))))))
436+
(if-let* ((commit
437+
(car (apply #'process-lines
438+
;; The "date" keyword uses UTC. The "hgdate" filter
439+
;; returns two integers separated by a space; the
440+
;; unix timestamp and the timezone offset. We use
441+
;; "hgdate" because that makes it easier to discard
442+
;; the time zone offset, which doesn't interest us.
443+
"hg" "log" "--limit" "1"
444+
"--template" "{node} {date|hgdate}\n" "--rev" rev
445+
(and (not exact)
446+
(cons "--" (package-build--spec-globs rcp)))))))
419447
(pcase-let ((`(,hash ,time ,_timezone) (split-string commit " ")))
420448
(list hash (string-to-number time)))
421-
(package-build--error (oref rcp name)
449+
(package-build--error rcp
422450
"No matching file(s) found in any reachable commit using %S files spec"
423451
(or (oref rcp files) 'default))))
424452

@@ -743,8 +771,8 @@ Return (COMMIT-HASH COMMITTER-DATE VERSION-STRING REVDESC) or nil.
743771
(list rcommit rtime (package-version-join version) rrevdesc tag)))))
744772

745773
(defun package-build--adjust-commit-count (rcp commit version ahead)
746-
(if-let ((previous (cdr (assq (intern (oref rcp name))
747-
(package-build-archive-alist)))))
774+
(if-let* ((previous (cdr (assq (intern (oref rcp name))
775+
(package-build-archive-alist)))))
748776
;; Because upstream may have rewritten history, we cannot be certain
749777
;; that appending the new count of commits would result in a version
750778
;; string that is greater than the version string used for the
@@ -1262,10 +1290,10 @@ is the same as the value of `export_file_name'."
12621290
(package-read-from-string
12631291
(string-join require-lines " ")))))))
12641292
(oset rcp webpage
1265-
(or (let ((site (cond ((fboundp 'lm-website)
1266-
(lm-website))
1267-
((fboundp 'lm-homepage)
1268-
(lm-homepage)))))
1293+
(or (and-let* ((site (cond ((fboundp 'lm-website)
1294+
(lm-website))
1295+
((fboundp 'lm-homepage)
1296+
(lm-homepage)))))
12691297
(if (string-match package-build--http-regexp site)
12701298
(replace-match "https" t t site 1)
12711299
site))
@@ -1304,17 +1332,17 @@ is the same as the value of `export_file_name'."
13041332
"Invalid package name in dependency: %S" pkg))
13051333
(list pkg ver))
13061334
(eval deps)))
1307-
(when-let ((v (or (alist-get :url plist)
1308-
(alist-get :homepage plist))))
1335+
(when-let* ((v (or (alist-get :url plist)
1336+
(alist-get :homepage plist))))
13091337
(oset rcp webpage
13101338
(if (string-match package-build--http-regexp v)
13111339
(replace-match "https" t t v 1)
13121340
v)))
1313-
(when-let ((v (alist-get :keywords plist)))
1341+
(when-let* ((v (alist-get :keywords plist)))
13141342
(oset rcp keywords v))
1315-
(when-let ((v (alist-get :maintainers plist)))
1343+
(when-let* ((v (alist-get :maintainers plist)))
13161344
(oset rcp maintainers v))
1317-
(when-let ((v (alist-get :authors plist)))
1345+
(when-let* ((v (alist-get :authors plist)))
13181346
(oset rcp authors v)))))))
13191347

13201348
(defun package-build--normalize-summary (summary)
@@ -1524,47 +1552,49 @@ are subsequently dumped."
15241552
(unless (file-exists-p package-build-archive-dir)
15251553
(package-build--message "Creating directory %s" package-build-archive-dir)
15261554
(make-directory package-build-archive-dir))
1527-
(let* ((start-time (current-time))
1528-
(rcp (package-recipe-lookup name))
1529-
(url (oref rcp url))
1530-
(repo (oref rcp repo))
1531-
(fetcher (package-recipe--fetcher rcp))
1532-
(version nil)
1533-
(msg (format "%s%s package %s"
1534-
(if noninteractive "" "")
1535-
(if package-build--inhibit-update "Fetching" "Building")
1536-
name)))
1537-
(cond ((and package-build-verbose (not noninteractive))
1538-
(message "%s..." msg)
1539-
(message "Package: %s" name)
1540-
(message "Fetcher: %s" fetcher)
1541-
(message "Source: %s\n" url))
1542-
((message "%s (from %s)..." msg
1543-
(if repo (format "%s:%s" fetcher repo) url))))
1544-
(package-build--fetch rcp)
1545-
(unless package-build--inhibit-update
1546-
(package-build--select-version rcp)
1547-
(setq version (oref rcp version))
1548-
(when version
1549-
(package-build--package rcp)
1550-
(when dump-archive-contents
1551-
(package-build-dump-archive-contents)))
1552-
(if (not version)
1553-
(message " ✗ Cannot determine version!")
1554-
(message " ✓ Success:")
1555-
(pcase-dolist (`(,file . ,attrs)
1556-
(directory-files-and-attributes
1557-
package-build-archive-dir nil
1558-
(format "\\`%s-[0-9]+" name)))
1559-
(message " %s %s"
1560-
(format-time-string
1561-
"%FT%T%z" (file-attribute-modification-time attrs) t)
1562-
file))))
1563-
(message "%s %s in %.3fs, finished at %s"
1564-
(if version "Built" "Fetched")
1565-
name
1566-
(float-time (time-since start-time))
1567-
(format-time-string "%FT%T%z" nil t))))
1555+
;; On Emacs < 30.1 this expands to just `progn'.
1556+
(package-build--log-errors
1557+
(let* ((start-time (current-time))
1558+
(rcp (package-recipe-lookup name))
1559+
(url (oref rcp url))
1560+
(repo (oref rcp repo))
1561+
(fetcher (package-recipe--fetcher rcp))
1562+
(version nil)
1563+
(msg (format "%s%s package %s"
1564+
(if noninteractive "" "")
1565+
(if package-build--inhibit-update "Fetching" "Building")
1566+
name)))
1567+
(cond ((and package-build-verbose (not noninteractive))
1568+
(message "%s..." msg)
1569+
(message "Package: %s" name)
1570+
(message "Fetcher: %s" fetcher)
1571+
(message "Source: %s\n" url))
1572+
((message "%s (from %s)..." msg
1573+
(if repo (format "%s:%s" fetcher repo) url))))
1574+
(package-build--fetch rcp)
1575+
(unless package-build--inhibit-update
1576+
(package-build--select-version rcp)
1577+
(setq version (oref rcp version))
1578+
(when version
1579+
(package-build--package rcp)
1580+
(when dump-archive-contents
1581+
(package-build-dump-archive-contents)))
1582+
(if (not version)
1583+
(message " ✗ Cannot determine version!")
1584+
(message " ✓ Success:")
1585+
(pcase-dolist (`(,file . ,attrs)
1586+
(directory-files-and-attributes
1587+
package-build-archive-dir nil
1588+
(format "\\`%s-[0-9]+" name)))
1589+
(message " %s %s"
1590+
(format-time-string
1591+
"%FT%T%z" (file-attribute-modification-time attrs) t)
1592+
file))))
1593+
(message "%s %s in %.3fs, finished at %s"
1594+
(if version "Built" "Fetched")
1595+
name
1596+
(float-time (time-since start-time))
1597+
(format-time-string "%FT%T%z" nil t)))))
15681598

15691599
;;;###autoload
15701600
(defun package-build--package (rcp)
@@ -1584,11 +1614,11 @@ in `package-build-archive-dir'."
15841614
(package-build--message "Running %s" command)
15851615
(package-build--call-sandboxed
15861616
rcp shell-file-name shell-command-switch command))
1587-
(when-let ((_ package-build-run-recipe-make-targets)
1588-
(targets (oref rcp make-targets)))
1617+
(when-let* ((_ package-build-run-recipe-make-targets)
1618+
(targets (oref rcp make-targets)))
15891619
(package-build--message "Running make %s" (string-join targets " "))
15901620
(apply #'package-build--call-sandboxed rcp "make" targets))
1591-
(if-let ((files (package-build-expand-files-spec rcp t)))
1621+
(if-let* ((files (package-build-expand-files-spec rcp t)))
15921622
(funcall (or package-build-build-function
15931623
'package-build--legacy-build)
15941624
rcp files)
@@ -1601,7 +1631,8 @@ in `package-build-archive-dir'."
16011631

16021632
(defun package-build--build-package (rcp files)
16031633
(pcase-let* (((eieio name version) rcp)
1604-
(tmpdir (file-name-as-directory (make-temp-file name t)))
1634+
(tmpdir (file-name-as-directory
1635+
(make-temp-file (concat name "-") t)))
16051636
(target (expand-file-name (concat name "-" version) tmpdir)))
16061637
(unless (rassoc (concat name ".el") files)
16071638
(package-build--error name
@@ -1649,7 +1680,8 @@ in `package-build-archive-dir'."
16491680
(defun package-build--build-multi-file-package (rcp files)
16501681
(declare (obsolete package-build--build-package "Package-Build 5.0.0"))
16511682
(pcase-let* (((eieio name version) rcp)
1652-
(tmpdir (file-name-as-directory (make-temp-file name t)))
1683+
(tmpdir (file-name-as-directory
1684+
(make-temp-file (concat name "-") t)))
16531685
(target (expand-file-name (concat name "-" version) tmpdir)))
16541686
(unless (or (rassoc (concat name ".el") files)
16551687
(rassoc (concat name "-pkg.el") files))

0 commit comments

Comments
 (0)