]> git.eshelyaron.com Git - emacs.git/commitdiff
* Do not attempt to write .elc files when not necessary (bug#49118)
authorAndrea Corallo <akrl@sdf.org>
Mon, 21 Jun 2021 09:44:58 +0000 (11:44 +0200)
committerAndrea Corallo <akrl@sdf.org>
Mon, 21 Jun 2021 10:20:19 +0000 (12:20 +0200)
* lisp/emacs-lisp/bytecomp.el (byte-compile-file): Do not attempt to
write .elc files when not necessary.

lisp/emacs-lisp/bytecomp.el

index 472e0ba3ba3e9690dd46b04130cc9500bc2ec578..3e65db42421be4a78036184900bba6c1b6e7d186 100644 (file)
@@ -2066,73 +2066,73 @@ See also `emacs-lisp-byte-compile-and-load'."
          (message "Compiling %s...done" filename))
        (kill-buffer input-buffer)
        (with-current-buffer output-buffer
-         (goto-char (point-max))
-         (insert "\n")                 ; aaah, unix.
-         (cond
-          ((null target-file) nil)     ;We only wanted the warnings!
-          ((and (or (null byte-native-compiling)
-                     (and byte-native-compiling byte+native-compile))
-                 (file-writable-p target-file)
-                ;; We attempt to create a temporary file in the
-                ;; target directory, so the target directory must be
-                ;; writable.
-                (file-writable-p
-                 (file-name-directory
-                  ;; Need to expand in case TARGET-FILE doesn't
-                  ;; include a directory (Bug#45287).
-                  (expand-file-name target-file))))
-           ;; We must disable any code conversion here.
-           (let* ((coding-system-for-write 'no-conversion)
-                  ;; Write to a tempfile so that if another Emacs
-                  ;; process is trying to load target-file (eg in a
-                  ;; parallel bootstrap), it does not risk getting a
-                  ;; half-finished file.  (Bug#4196)
-                  (tempfile
-                   (make-temp-file (when (file-writable-p target-file)
-                                      (expand-file-name target-file))))
-                  (default-modes (default-file-modes))
-                  (temp-modes (logand default-modes #o600))
-                  (desired-modes (logand default-modes #o666))
-                  (kill-emacs-hook
-                   (cons (lambda () (ignore-errors
-                                 (delete-file tempfile)))
-                         kill-emacs-hook)))
-             (unless (= temp-modes desired-modes)
-               (set-file-modes tempfile desired-modes 'nofollow))
-             (write-region (point-min) (point-max) tempfile nil 1)
-             ;; This has the intentional side effect that any
-             ;; hard-links to target-file continue to
-             ;; point to the old file (this makes it possible
-             ;; for installed files to share disk space with
-             ;; the build tree, without causing problems when
-             ;; emacs-lisp files in the build tree are
-             ;; recompiled).  Previously this was accomplished by
-             ;; deleting target-file before writing it.
-             (if byte-native-compiling
-                  ;; Defer elc final renaming.
-                  (setf byte-to-native-output-file
-                        (cons tempfile target-file))
-                (rename-file tempfile target-file t)))
-           (or noninteractive
-               byte-native-compiling
-               (message "Wrote %s" target-file)))
-           ((file-writable-p target-file)
-            ;; In case the target directory isn't writable (see e.g. Bug#44631),
-            ;; try writing to the output file directly.  We must disable any
-            ;; code conversion here.
-            (let ((coding-system-for-write 'no-conversion))
-              (with-file-modes (logand (default-file-modes) #o666)
-                (write-region (point-min) (point-max) target-file nil 1)))
-            (or noninteractive (message "Wrote %s" target-file)))
-          (t
-           ;; This is just to give a better error message than write-region
-           (let ((exists (file-exists-p target-file)))
-             (signal (if exists 'file-error 'file-missing)
-                     (list "Opening output file"
-                           (if exists
-                               "Cannot overwrite file"
-                             "Directory not writable or nonexistent")
-                           target-file)))))
+          (when (and target-file
+                     (or (not byte-native-compiling)
+                         (and byte-native-compiling byte+native-compile)))
+           (goto-char (point-max))
+           (insert "\n")                       ; aaah, unix.
+           (cond
+            ((and (file-writable-p target-file)
+                  ;; We attempt to create a temporary file in the
+                  ;; target directory, so the target directory must be
+                  ;; writable.
+                  (file-writable-p
+                   (file-name-directory
+                    ;; Need to expand in case TARGET-FILE doesn't
+                    ;; include a directory (Bug#45287).
+                    (expand-file-name target-file))))
+             ;; We must disable any code conversion here.
+             (let* ((coding-system-for-write 'no-conversion)
+                    ;; Write to a tempfile so that if another Emacs
+                    ;; process is trying to load target-file (eg in a
+                    ;; parallel bootstrap), it does not risk getting a
+                    ;; half-finished file.  (Bug#4196)
+                    (tempfile
+                     (make-temp-file (when (file-writable-p target-file)
+                                        (expand-file-name target-file))))
+                    (default-modes (default-file-modes))
+                    (temp-modes (logand default-modes #o600))
+                    (desired-modes (logand default-modes #o666))
+                    (kill-emacs-hook
+                     (cons (lambda () (ignore-errors
+                                   (delete-file tempfile)))
+                           kill-emacs-hook)))
+               (unless (= temp-modes desired-modes)
+                 (set-file-modes tempfile desired-modes 'nofollow))
+               (write-region (point-min) (point-max) tempfile nil 1)
+               ;; This has the intentional side effect that any
+               ;; hard-links to target-file continue to
+               ;; point to the old file (this makes it possible
+               ;; for installed files to share disk space with
+               ;; the build tree, without causing problems when
+               ;; emacs-lisp files in the build tree are
+               ;; recompiled).  Previously this was accomplished by
+               ;; deleting target-file before writing it.
+               (if byte-native-compiling
+                    ;; Defer elc final renaming.
+                    (setf byte-to-native-output-file
+                          (cons tempfile target-file))
+                  (rename-file tempfile target-file t)))
+             (or noninteractive
+                 byte-native-compiling
+                 (message "Wrote %s" target-file)))
+             ((file-writable-p target-file)
+              ;; In case the target directory isn't writable (see e.g. Bug#44631),
+              ;; try writing to the output file directly.  We must disable any
+              ;; code conversion here.
+              (let ((coding-system-for-write 'no-conversion))
+                (with-file-modes (logand (default-file-modes) #o666)
+                  (write-region (point-min) (point-max) target-file nil 1)))
+              (or noninteractive (message "Wrote %s" target-file)))
+            (t
+             ;; This is just to give a better error message than write-region
+             (let ((exists (file-exists-p target-file)))
+               (signal (if exists 'file-error 'file-missing)
+                       (list "Opening output file"
+                             (if exists
+                                 "Cannot overwrite file"
+                               "Directory not writable or nonexistent")
+                             target-file))))))
          (kill-buffer (current-buffer)))
        (if (and byte-compile-generate-call-tree
                 (or (eq t byte-compile-generate-call-tree)