fix(lib): doom/reload: on Windows

- cmd.exe chokes on the space in "C:\Program Files\...", but more
  importantly, doom.ps1 should be invoked with powershell, not cmd.exe.
- Windows has pwsh.exe and powershell.exe, which, while not identical,
  are close enough for our purposes, but needed to be accounted for.

Fix: #8098
This commit is contained in:
Henrik Lissner
2025-06-19 19:38:20 +02:00
parent a4d00445d2
commit 589fa73435
2 changed files with 46 additions and 34 deletions

View File

@ -1,12 +1,19 @@
# bin/doom.ps1 # bin/doom.ps1
# TODO: Use magic shebang (polyglot)?
if (!(Get-Command -Erroraction silentlycontinue emacs.exe)) { function Executable-Find {
echo "Couldn't find emacs.exe in your PATH." foreach ($exe in $args) {
exit 1 if ($exe) {
$path = Get-Command $exe -ErrorAction SilentlyContinue
if ($path) { return $path.Path; }
}
}
throw "Could not find in $PATH: $($args -join ', ')"
} }
$emacs = if ($env:EMACS) { $env:EMACS } else { Executable-Find "emacs.exe" }
$pwsh = Executable-Find "pwsh.exe" "powershell.exe"
$doom = "$PSScriptRoot/doom" $doom = "$PSScriptRoot/doom"
$emacs = if ($env:EMACS) { $env:EMACS } else { (Get-Command emacs.exe).Path }
$oldemacsdir = $env:EMACSDIR $oldemacsdir = $env:EMACSDIR
try { try {
@ -24,7 +31,8 @@ try {
& $emacs -q --no-site-file --batch --load "$doom" -- --no-color $args & $emacs -q --no-site-file --batch --load "$doom" -- --no-color $args
if ($LASTEXITCODE -eq 254) { if ($LASTEXITCODE -eq 254) {
& pwsh "$($env:temp)\doom.$($env:__DOOMPID).$($env:__DOOMSTEP).ps1" $PSCommandPath $args # TODO: Use Invoke-Command instead?
& $pwsh "$($env:temp)\doom.$($env:__DOOMPID).$($env:__DOOMSTEP).ps1" $PSCommandPath $args
$exit = $LASTEXITCODE $exit = $LASTEXITCODE
} }
exit $exit exit $exit

View File

@ -28,37 +28,41 @@
(defmacro doom--if-compile (command on-success &optional on-failure) (defmacro doom--if-compile (command on-success &optional on-failure)
(declare (indent 2)) (declare (indent 2))
`(let* ((doom-bin "doom") `(let* ((default-directory doom-emacs-dir)
(doom-bin-dir (expand-file-name "bin/" doom-emacs-dir)) (doom-bin "doom")
(default-directory doom-emacs-dir) (doom-bin-dir (expand-file-name "bin/"))
(exec-path (cons doom-bin-dir exec-path))) (emacs-bin (doom-path invocation-directory invocation-name))
(exec-path (cons doom-bin-dir exec-path))
(shell-file-name shell-file-name))
(when (and (featurep :system 'windows) (when (and (featurep :system 'windows)
(string-match-p "cmdproxy.exe$" shell-file-name)) (string-match-p "cmdproxy.exe$" shell-file-name))
(unless (executable-find "pwsh") (if-let* ((pwsh (or (executable-find "pwsh")
(user-error "Powershell 3.0+ is required, but pwsh.exe was not found in your $PATH")) (executable-find "powershell"))))
(setq doom-bin "doom.ps1")) (setq doom-bin "doom.ps1"
;; Ensure the bin/doom operates with the same environment as this shell-file-name pwsh)
;; running session. (user-error "Powershell 3.0+ is required for `doom/reload', but no pwsh.exe or powershell.exe found in your $PATH")))
(with-environment-variables ;; Ensure the bin/doom operates with the same environment as this running
(("PATH" (string-join exec-path path-separator)) ;; session.
("EMACS" (doom-path invocation-directory invocation-name)) (with-current-buffer
("EMACSDIR" doom-emacs-dir) (with-environment-variables
("DOOMDIR" doom-user-dir) (("PATH" (string-join exec-path path-separator))
("DOOMLOCALDIR" doom-local-dir) ("EMACS" emacs-bin)
("DEBUG" (if doom-debug-mode (number-to-string doom-log-level)))) ("EMACSDIR" doom-emacs-dir)
(with-current-buffer ("DOOMDIR" doom-user-dir)
(compile (format ,command (expand-file-name doom-bin doom-bin-dir)) t) ("DOOMLOCALDIR" doom-local-dir)
(let ((w (get-buffer-window (current-buffer)))) ("DEBUG" (if doom-debug-mode (number-to-string doom-log-level))))
(select-window w) (compile (format ,command (file-name-concat "bin" doom-bin)) t))
(add-hook (let ((w (get-buffer-window (current-buffer))))
'compilation-finish-functions (select-window w)
(lambda (_buf status) (add-hook
(if (equal status "finished\n") 'compilation-finish-functions
(progn (lambda (_buf status)
(delete-window w) (if (equal status "finished\n")
,on-success) (progn
,on-failure)) (delete-window w)
nil 'local)))))) ,on-success)
,on-failure))
nil 'local)))))
(defvar doom-reload-command (defvar doom-reload-command
(format "%s sync -B -e" (format "%s sync -B -e"