Make build process robust against interruptions

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.
This commit is contained in:
Andrea Corallo 2020-02-23 14:06:59 +00:00
parent 5153dc17f2
commit 1dc237f280
2 changed files with 25 additions and 12 deletions

View file

@ -571,13 +571,19 @@ Each element is (INDEX . VALUE)")
form) form)
(defvar byte-native-compiling nil (defvar byte-native-compiling nil
"Non nil while native compiling.") "Non nil while native compiling.")
(defvar byte-native-always-write-elc nil (defvar byte-native-for-bootstrap nil
"Always write the elc file also while native compiling.") "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 (defvar byte-to-native-lap nil
"A-list to accumulate LAP. "A-list to accumulate LAP.
Each pair is (NAME . LAP)") Each pair is (NAME . LAP)")
(defvar byte-to-native-top-level-forms nil (defvar byte-to-native-top-level-forms nil
"List of top level forms.") "List of top level forms.")
(defvar byte-to-native-output-file nil
"Temporary file containing the byte-compilation output.")
;;; The byte codes; this information is duplicated in bytecomp.c ;;; 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 ;; emacs-lisp files in the build tree are
;; recompiled). Previously this was accomplished by ;; recompiled). Previously this was accomplished by
;; deleting target-file before writing it. ;; deleting target-file before writing it.
(if (and byte-native-compiling (if byte-native-compiling
(null byte-native-always-write-elc)) (if byte-native-for-bootstrap
(delete-file tempfile) ;; Defer elc final renaming.
(rename-file tempfile target-file t))) (setf byte-to-native-output-file
(cons tempfile target-file))
(delete-file tempfile))
(rename-file tempfile target-file t)))
(or noninteractive (or noninteractive
byte-native-compiling byte-native-compiling
(message "Wrote %s" target-file))) (message "Wrote %s" target-file)))

View file

@ -2071,12 +2071,16 @@ Return the compilation unit file name."
(defun batch-byte-native-compile-for-bootstrap () (defun batch-byte-native-compile-for-bootstrap ()
"As `batch-byte-compile' but used for booststrap. "As `batch-byte-compile' but used for booststrap.
Always generate elc files too and handle native compiler expected errors." Always generate elc files too and handle native compiler expected errors."
;; FIXME remove when dynamic scope support is implemented. (let ((byte-native-for-bootstrap t)
(let ((byte-native-always-write-elc t)) (byte-to-native-output-file nil))
(condition-case _ (unwind-protect
(batch-native-compile) (condition-case _
(native-compiler-error-dyn-func) (batch-native-compile)
(native-compiler-error-empty-byte)))) (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 ;;;###autoload
(defun native-compile-async (input &optional jobs recursively) (defun native-compile-async (input &optional jobs recursively)