diff --git a/lisp/cli/sync.el b/lisp/cli/sync.el index 2e6998534..49d91db0a 100644 --- a/lisp/cli/sync.el +++ b/lisp/cli/sync.el @@ -56,58 +56,67 @@ OPTIONS: during the execution of this command. Use --rebuild as well to do so for all packages." :benchmark t - (when (doom-profiles-bootloadable-p) - (call! '(profile sync "--all" "--reload"))) (when aot? (after! straight (setq straight--native-comp-available t))) (when jobs (setq native-comp-async-jobs-number (truncate jobs))) - (run-hooks 'doom-before-sync-hook) - (add-hook 'kill-emacs-hook #'doom-sync--abort-warning-h) - (print! (item "Using Emacs %s @ %s") emacs-version (path invocation-directory invocation-name)) - (print! (start "Synchronizing %S profile..." ) (or (car doom-profile) "default")) - (unwind-protect - (print-group! - ;; If the user has up/downgraded Emacs since last sync, or copied their - ;; config to a different system, then their packages need to be - ;; recompiled. This is necessary because Emacs byte-code is not - ;; necessarily back/forward compatible across major versions, and many - ;; packages bake in hardcoded data at compile-time. - (pcase-let ((`(,old-version . ,hash) - (doom-file-read doom-sync-info-file :by 'read :noerror t)) - (to-rebuild nil)) - (when (and old-version (not (equal old-version emacs-version))) - (print! (warn "Emacs version has changed since last sync (from %s to %s)") old-version emacs-version) - (setq to-rebuild t)) - (when (and (stringp hash) - (not (equal hash (doom-sync--system-hash)))) - (print! (warn "Your system has changed since last sync")) - (setq to-rebuild t)) - (when (and to-rebuild (not rebuild?) (not (doom-cli-context-suppress-prompts-p context))) - (cond (nobuild? - (print! (warn "Packages must be rebuilt, but -B has prevented it. Skipping..."))) - ((doom-cli-context-get context 'upgrading) - (print! (warn "Packages will be rebuilt")) - (setq rebuild? t)) - ((y-or-n-p (format! " %s" "Installed packages must be rebuilt. Do so now?")) - (setq rebuild? t)) - ((exit! 0))))) - (when (and (not noenvvar?) - (file-exists-p doom-env-file)) - (call! '(env))) - (doom-packages-ensure rebuild?) - (unless noupdate? (doom-packages-update (not update?))) - (doom-packages-purge purge? purge? purge? purge? purge?) - (when (doom-profile-generate) - (print! (item "Restart Emacs for changes to take effect")) - (run-hooks 'doom-after-sync-hook)) - (when (or rebuild? (not (file-exists-p doom-sync-info-file))) - (with-temp-file doom-sync-info-file - (prin1 (cons emacs-version (doom-sync--system-hash)) - (current-buffer)))) - t) - (remove-hook 'kill-emacs-hook #'doom-sync--abort-warning-h))) + (let ((emacs-running? + (cl-loop for pid in (remove (emacs-pid) (list-system-processes)) + for attrs = (process-attributes pid) + for args = (alist-get 'args attrs "") + if (string-match-p "^\\([^ ]+/\\)?[eE]macs" args) + if (not (string-match-p " --batch" args)) + if (not (string-match-p " --script" args)) + collect pid))) + (when (doom-profiles-bootloadable-p) + (call! '(profile sync "--all" "--reload"))) + (run-hooks 'doom-before-sync-hook) + (add-hook 'kill-emacs-hook #'doom-sync--abort-warning-h) + (print! (item "Using Emacs %s @ %s") emacs-version (path invocation-directory invocation-name)) + (print! (start "Synchronizing %S profile..." ) (or (car doom-profile) "default")) + (unwind-protect + (print-group! + ;; If the user has up/downgraded Emacs since last sync, or copied their + ;; config to a different system, then their packages need to be + ;; recompiled. This is necessary because Emacs byte-code is not + ;; necessarily back/forward compatible across major versions, and many + ;; packages bake in hardcoded data at compile-time. + (pcase-let ((`(,old-version . ,hash) + (doom-file-read doom-sync-info-file :by 'read :noerror t)) + (to-rebuild nil)) + (when (and old-version (not (equal old-version emacs-version))) + (print! (warn "Emacs version has changed since last sync (from %s to %s)") old-version emacs-version) + (setq to-rebuild t)) + (when (and (stringp hash) + (not (equal hash (doom-sync--system-hash)))) + (print! (warn "Your system has changed since last sync")) + (setq to-rebuild t)) + (when (and to-rebuild (not rebuild?) (not (doom-cli-context-suppress-prompts-p context))) + (cond (nobuild? + (print! (warn "Packages must be rebuilt, but -B has prevented it. Skipping..."))) + ((doom-cli-context-get context 'upgrading) + (print! (warn "Packages will be rebuilt")) + (setq rebuild? t)) + ((y-or-n-p (format! " %s" "Installed packages must be rebuilt. Do so now?")) + (setq rebuild? t)) + ((exit! 0))))) + (when (and (not noenvvar?) + (file-exists-p doom-env-file)) + (call! '(env))) + (doom-packages-ensure rebuild?) + (unless noupdate? (doom-packages-update (not update?))) + (doom-packages-purge purge? purge? purge? purge? purge?) + (when (doom-profile-generate) + (when emacs-running? + (print! (item "Restart Emacs for changes to take effect"))) + (run-hooks 'doom-after-sync-hook)) + (when (or rebuild? (not (file-exists-p doom-sync-info-file))) + (with-temp-file doom-sync-info-file + (prin1 (cons emacs-version (doom-sync--system-hash)) + (current-buffer)))) + t) + (remove-hook 'kill-emacs-hook #'doom-sync--abort-warning-h)))) ;;