aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2017-05-06 17:58:20 -0700
committerGlenn Morris2017-05-06 17:58:20 -0700
commit7f3d63908cd05fb34347d942e435c2964cd8b249 (patch)
tree3754fe9bb3be3da23196601a2908b112e0434122
parent03d941982fbdf96260fc47d1cafbdda78c1d128e (diff)
downloademacs-7f3d63908cd05fb34347d942e435c2964cd8b249.tar.gz
emacs-7f3d63908cd05fb34347d942e435c2964cd8b249.zip
Write autoloads file atomically
* lisp/emacs-lisp/autoload.el (autoload--save-buffer): New function, to save buffer atomically. (autoload-save-buffers, update-directory-autoloads): Use autoload--save-buffer. * lisp/Makefile.in ($(lisp)/loaddefs.el): No longer write to a temp file by hand.
-rw-r--r--lisp/Makefile.in13
-rw-r--r--lisp/emacs-lisp/autoload.el22
2 files changed, 19 insertions, 16 deletions
diff --git a/lisp/Makefile.in b/lisp/Makefile.in
index cbbea78a00f..1da8814370a 100644
--- a/lisp/Makefile.in
+++ b/lisp/Makefile.in
@@ -203,28 +203,17 @@ $(lisp)/finder-inf.el:
203# batch-update-autoloads, which only updates the autoloads whose 203# batch-update-autoloads, which only updates the autoloads whose
204# sources have changed. 204# sources have changed.
205 205
206# Write to a temporary file in case we're doing a parallel build and a
207# CANNOT_DUMP-mode Emacs needs to read loaddefs at startup.
208# (FIXME: This seems like something that batch-update-autoloads should
209# do internally, then it would Just Work for all loaddefs files.)
210# We start by copying an existing loaddefs.el to loaddefs.tmp to avoid
211# regenerating the entire file anew, which is slow; starting from an
212# almost-correct content will enable the "only update where necessary"
213# feature of batch-update-autoloads.
214
215# Use expand-file-name rather than $abs_scrdir so that Emacs does not 206# Use expand-file-name rather than $abs_scrdir so that Emacs does not
216# get confused when it compares file-names for equality. 207# get confused when it compares file-names for equality.
217 208
218autoloads .PHONY: $(lisp)/loaddefs.el 209autoloads .PHONY: $(lisp)/loaddefs.el
219$(lisp)/loaddefs.el: gen-lisp $(LOADDEFS) 210$(lisp)/loaddefs.el: gen-lisp $(LOADDEFS)
220 @echo Directories for loaddefs: ${SUBDIRS_ALMOST} 211 @echo Directories for loaddefs: ${SUBDIRS_ALMOST}
221 @if test -f $@ ; then cp $@ $(lisp)/loaddefs.tmp ; fi
222 $(AM_V_GEN)$(emacs) -l autoload \ 212 $(AM_V_GEN)$(emacs) -l autoload \
223 --eval '(setq autoload-ensure-writable t)' \ 213 --eval '(setq autoload-ensure-writable t)' \
224 --eval '(setq autoload-builtin-package-versions t)' \ 214 --eval '(setq autoload-builtin-package-versions t)' \
225 --eval '(setq generated-autoload-file (expand-file-name (unmsys--file-name "$(lisp)/loaddefs.tmp")))' \ 215 --eval '(setq generated-autoload-file (expand-file-name (unmsys--file-name "$@")))' \
226 -f batch-update-autoloads ${SUBDIRS_ALMOST} 216 -f batch-update-autoloads ${SUBDIRS_ALMOST}
227 $(top_srcdir)/build-aux/move-if-change $(lisp)/loaddefs.tmp $@
228 217
229# autoloads only runs when loaddefs.el is nonexistent, although it 218# autoloads only runs when loaddefs.el is nonexistent, although it
230# generates a number of different files. Provide a force option to enable 219# generates a number of different files. Provide a force option to enable
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el
index 9865b3198b2..8ad5e6b823d 100644
--- a/lisp/emacs-lisp/autoload.el
+++ b/lisp/emacs-lisp/autoload.el
@@ -866,11 +866,26 @@ FILE's modification time."
866 (error "%s:0:0: error: %s: %s" file (car err) (cdr err))) 866 (error "%s:0:0: error: %s: %s" file (car err) (cdr err)))
867 )) 867 ))
868 868
869;; For parallel builds, to stop another process reading a half-written file.
870(defun autoload--save-buffer ()
871 "Save current buffer to its file, atomically."
872 ;; Copied from byte-compile-file.
873 (let* ((version-control 'never)
874 (tempfile (make-temp-name buffer-file-name))
875 (kill-emacs-hook
876 (cons (lambda () (ignore-errors (delete-file tempfile)))
877 kill-emacs-hook)))
878 (write-region (point-min) (point-max) tempfile nil 1)
879 (backup-buffer)
880 (rename-file tempfile buffer-file-name t)
881 (set-buffer-modified-p nil)
882 (set-visited-file-modtime)
883 (or noninteractive (message "Wrote %s" buffer-file-name))))
884
869(defun autoload-save-buffers () 885(defun autoload-save-buffers ()
870 (while autoload-modified-buffers 886 (while autoload-modified-buffers
871 (with-current-buffer (pop autoload-modified-buffers) 887 (with-current-buffer (pop autoload-modified-buffers)
872 (let ((version-control 'never)) 888 (autoload--save-buffer))))
873 (save-buffer)))))
874 889
875;; FIXME This command should be deprecated. 890;; FIXME This command should be deprecated.
876;; See http://debbugs.gnu.org/22213#41 891;; See http://debbugs.gnu.org/22213#41
@@ -1110,8 +1125,7 @@ write its autoloads into the specified file instead."
1110 ;; dependencies don't trigger unnecessarily. 1125 ;; dependencies don't trigger unnecessarily.
1111 (if (not changed) 1126 (if (not changed)
1112 (set-buffer-modified-p nil) 1127 (set-buffer-modified-p nil)
1113 (let ((version-control 'never)) 1128 (autoload--save-buffer))
1114 (save-buffer)))
1115 1129
1116 ;; In case autoload entries were added to other files because of 1130 ;; In case autoload entries were added to other files because of
1117 ;; file-local autoload-generated-file settings. 1131 ;; file-local autoload-generated-file settings.