]> git.eshelyaron.com Git - emacs.git/commitdiff
Make build process robust against interruptions
authorAndrea Corallo <akrl@sdf.org>
Sun, 23 Feb 2020 14:06:59 +0000 (14:06 +0000)
committerAndrea Corallo <akrl@sdf.org>
Sun, 23 Feb 2020 16:50:15 +0000 (16:50 +0000)
During boo-strap we produce both the .eln and the .elc together.
Because the make target is the later this has to be produced as last
to be resilient to build interruptions.

lisp/emacs-lisp/bytecomp.el
lisp/emacs-lisp/comp.el

index 1f64626a993bc4512a5386ea87324b79727bd761..b3bd6879b6946b0af4573d3e38111b3147f6e902 100644 (file)
@@ -571,13 +571,19 @@ Each element is (INDEX . VALUE)")
               form)
 (defvar byte-native-compiling nil
   "Non nil while native compiling.")
-(defvar byte-native-always-write-elc nil
-  "Always write the elc file also while native compiling.")
+(defvar byte-native-for-bootstrap nil
+  "Non nil while compiling for bootstrap."
+  ;; During boostrap we produce both the .eln and the .elc together.
+  ;; Because the make target is the later this has to be produced as
+  ;; last to be resilient against build interruptions.
+)
 (defvar byte-to-native-lap nil
   "A-list to accumulate LAP.
 Each pair is (NAME . LAP)")
 (defvar byte-to-native-top-level-forms nil
   "List of top level forms.")
+(defvar byte-to-native-output-file nil
+  "Temporary file containing the byte-compilation output.")
 
 \f
 ;;; The byte codes; this information is duplicated in bytecomp.c
@@ -2035,10 +2041,13 @@ The value is non-nil if there were no errors, nil if errors."
                  ;; emacs-lisp files in the build tree are
                  ;; recompiled).  Previously this was accomplished by
                  ;; deleting target-file before writing it.
-                  (if (and byte-native-compiling
-                           (null byte-native-always-write-elc))
-                      (delete-file tempfile)
-                   (rename-file tempfile target-file t)))
+                  (if byte-native-compiling
+                      (if byte-native-for-bootstrap
+                          ;; Defer elc final renaming.
+                          (setf byte-to-native-output-file
+                                (cons tempfile target-file))
+                        (delete-file tempfile))
+                    (rename-file tempfile target-file t)))
                (or noninteractive
                     byte-native-compiling
                     (message "Wrote %s" target-file)))
index edbc98f190b2045ff98b4a5768eb92b4d0c6c2ab..c13844c70b7e8d43a47b0d26126271aa24b932f2 100644 (file)
@@ -2071,12 +2071,16 @@ Return the compilation unit file name."
 (defun batch-byte-native-compile-for-bootstrap ()
   "As `batch-byte-compile' but used for booststrap.
 Always generate elc files too and handle native compiler expected errors."
-  ;; FIXME remove when dynamic scope support is implemented.
-  (let ((byte-native-always-write-elc t))
-    (condition-case _
-        (batch-native-compile)
-      (native-compiler-error-dyn-func)
-      (native-compiler-error-empty-byte))))
+  (let ((byte-native-for-bootstrap t)
+        (byte-to-native-output-file nil))
+    (unwind-protect
+        (condition-case _
+            (batch-native-compile)
+          (native-compiler-error-dyn-func)
+          (native-compiler-error-empty-byte))
+      (pcase byte-to-native-output-file
+        (`(,tempfile . ,target-file)
+         (rename-file tempfile target-file t))))))
 
 ;;;###autoload
 (defun native-compile-async (input &optional jobs recursively)