Skip to content

Commit 9da5105

Browse files
committed
Add PID to byte compilation log file to avoid data races
1 parent 863b336 commit 9da5105

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

async-bytecomp.el

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ all packages are always compiled asynchronously."
6060
(defvar async-bytecomp-load-variable-regexp "\\`load-path\\'"
6161
"The variable used by `async-inject-variables' when (re)compiling async.")
6262

63-
(defun async-bytecomp--file-to-comp-buffer (file-or-dir &optional quiet type)
63+
(defun async-bytecomp--file-to-comp-buffer (file-or-dir &optional quiet type log-file)
6464
(let ((bn (file-name-nondirectory file-or-dir))
6565
(action-name (pcase type
6666
('file "File")
6767
('directory "Directory"))))
68-
(if (file-exists-p async-byte-compile-log-file)
68+
(if (and log-file (file-exists-p log-file))
6969
(let ((buf (get-buffer-create byte-compile-log-buffer))
7070
(n 0))
7171
(with-current-buffer buf
7272
(goto-char (point-max))
7373
(let ((inhibit-read-only t))
74-
(insert-file-contents async-byte-compile-log-file)
74+
(insert-file-contents log-file)
7575
(compilation-mode))
7676
(display-buffer buf)
77-
(delete-file async-byte-compile-log-file)
77+
(delete-file log-file)
7878
(unless quiet
7979
(save-excursion
8080
(goto-char (point-min))
@@ -99,8 +99,8 @@ All *.elc files are systematically deleted before proceeding."
9999
;; This happen when recompiling its own directory.
100100
(load "async")
101101
(let ((call-back
102-
(lambda (&optional _ignore)
103-
(async-bytecomp--file-to-comp-buffer directory quiet 'directory))))
102+
(lambda (&optional log-file)
103+
(async-bytecomp--file-to-comp-buffer directory quiet 'directory log-file))))
104104
(async-start
105105
`(lambda ()
106106
(require 'bytecomp)
@@ -113,9 +113,12 @@ All *.elc files are systematically deleted before proceeding."
113113
(setq error-data (with-current-buffer byte-compile-log-buffer
114114
(buffer-substring-no-properties (point-min) (point-max))))
115115
(unless (string= error-data "")
116-
(with-temp-file ,async-byte-compile-log-file
117-
(erase-buffer)
118-
(insert error-data))))))
116+
(let ((log-file (format "%s.%s" ,async-byte-compile-log-file (emacs-pid))))
117+
(with-temp-file log-file
118+
(erase-buffer)
119+
(insert error-data)
120+
(buffer-file-name))
121+
log-file)))))
119122
call-back)
120123
(unless quiet (message "Started compiling asynchronously directory %s" directory))))
121124

@@ -178,7 +181,7 @@ Same as `byte-compile-file' but asynchronous."
178181
(interactive "fFile: ")
179182
(let ((call-back
180183
(lambda (&optional _ignore)
181-
(async-bytecomp--file-to-comp-buffer file nil 'file))))
184+
(async-bytecomp--file-to-comp-buffer file nil 'file log-file))))
182185
(async-start
183186
`(lambda ()
184187
(require 'bytecomp)
@@ -191,9 +194,11 @@ Same as `byte-compile-file' but asynchronous."
191194
(setq error-data (with-current-buffer byte-compile-log-buffer
192195
(buffer-substring-no-properties (point-min) (point-max))))
193196
(unless (string= error-data "")
194-
(with-temp-file ,async-byte-compile-log-file
197+
(let ((log-file (format "%s.%s" ,async-byte-compile-log-file (emacs-pid))))
198+
(with-temp-file log-file
195199
(erase-buffer)
196-
(insert error-data))))))
200+
(insert error-data))
201+
log-file)))))
197202
call-back)))
198203

199204
(provide 'async-bytecomp)

0 commit comments

Comments
 (0)