emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 388e0c18f4: Make the nativecomp test eln directory more reliably


From: Lars Ingebrigtsen
Subject: master 388e0c18f4: Make the nativecomp test eln directory more reliably be removed
Date: Tue, 24 May 2022 08:11:21 -0400 (EDT)

branch: master
commit 388e0c18f489fc7d4bee8278e21852eefa1dcf19
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make the nativecomp test eln directory more reliably be removed
    
    * lisp/startup.el (startup-redirect-eln-cache, normal-top-level):
    Don't create the nativecomp directory here, because this led to
    brittle deletions of the directory -- there would be several
    instances of the directory left over after a test run.
    
    * lisp/emacs-lisp/ert.el (ert-run-tests-batch-and-exit): Create
    the nativecomp directory.
---
 lisp/emacs-lisp/ert.el | 34 ++++++++++++++++++++++------------
 lisp/startup.el        | 38 +++++++-------------------------------
 src/emacs.c            |  4 ++++
 3 files changed, 33 insertions(+), 43 deletions(-)

diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 00da5c718c..0451be272a 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -1533,23 +1533,33 @@ Returns the stats object."
   "Like `ert-run-tests-batch', but exits Emacs when done.
 
 The exit status will be 0 if all test results were as expected, 1
-on unexpected results, or 2 if the tool detected an error outside
+son unexpected results, or 2 if the tool detected an error outside
 of the tests (e.g. invalid SELECTOR or bug in the code that runs
 the tests)."
   (or noninteractive
       (user-error "This function is only for use in batch mode"))
-  ;; Better crash loudly than attempting to recover from undefined
-  ;; behavior.
-  (setq attempt-stack-overflow-recovery nil
-        attempt-orderly-shutdown-on-fatal-signal nil)
-  (unwind-protect
-      (let ((stats (ert-run-tests-batch selector)))
-        (kill-emacs (if (zerop (ert-stats-completed-unexpected stats)) 0 1)))
+  (let ((eln-dir (and (featurep 'native-compile)
+                      (make-temp-file "test-nativecomp-cache-" t))))
+    (when eln-dir
+      (startup-redirect-eln-cache eln-dir))
+    ;; Better crash loudly than attempting to recover from undefined
+    ;; behavior.
+    (setq attempt-stack-overflow-recovery nil
+          attempt-orderly-shutdown-on-fatal-signal nil)
     (unwind-protect
-        (progn
-          (message "Error running tests")
-          (backtrace))
-      (kill-emacs 2))))
+        (let ((stats (ert-run-tests-batch selector)))
+          (when eln-dir
+            (ignore-errors
+              (delete-directory eln-dir t)))
+          (kill-emacs (if (zerop (ert-stats-completed-unexpected stats)) 0 1)))
+      (unwind-protect
+          (progn
+            (message "Error running tests")
+            (backtrace))
+        (when eln-dir
+          (ignore-errors
+            (delete-directory eln-dir t)))
+        (kill-emacs 2)))))
 
 (defvar ert-load-file-name nil
   "The name of the loaded ERT test file, a string.
diff --git a/lisp/startup.el b/lisp/startup.el
index 433a58bf2c..4b42cd236c 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -557,25 +557,12 @@ to `user-emacs-directory'.
 For best results, call this function in your early-init file,
 so that the rest of initialization and package loading uses
 the updated value."
-  (let ((tmp-dir (and (equal (getenv "HOME") "/nonexistent")
-                      (file-writable-p (expand-file-name
-                                        (or temporary-file-directory "")))
-                      (car native-comp-eln-load-path))))
-    (if tmp-dir
-        (setq native-comp-eln-load-path
-              (cdr native-comp-eln-load-path)))
-    ;; Remove the original eln-cache.
-    (setq native-comp-eln-load-path
-          (cdr native-comp-eln-load-path))
-    ;; Add the new eln-cache.
-    (push (expand-file-name (file-name-as-directory cache-directory)
-                            user-emacs-directory)
-          native-comp-eln-load-path)
-    (when tmp-dir
-      ;; Recompute tmp-dir, in case user-emacs-directory affects it.
-      (setq tmp-dir (make-temp-file "emacs-testsuite-" t))
-      (add-hook 'kill-emacs-hook (lambda () (delete-directory tmp-dir t)))
-      (push tmp-dir native-comp-eln-load-path))))
+  ;; Remove the original eln-cache.
+  (setq native-comp-eln-load-path (cdr native-comp-eln-load-path))
+  ;; Add the new eln-cache.
+  (push (expand-file-name (file-name-as-directory cache-directory)
+                          user-emacs-directory)
+        native-comp-eln-load-path))
 
 (defun startup--update-eln-cache ()
   "Update the user eln-cache directory due to user customizations."
@@ -619,18 +606,7 @@ It is the default value of the variable `top-level'."
             (unless (string= "" path)
               (push path native-comp-eln-load-path)))))
       (push (expand-file-name "eln-cache/" user-emacs-directory)
-            native-comp-eln-load-path)
-      ;; When $HOME is set to '/nonexistent' means we are running the
-      ;; testsuite, add a temporary folder in front to produce there
-      ;; new compilations.
-      (when (and (equal (getenv "HOME") "/nonexistent")
-                 ;; We may be running in a chroot environment where we
-                 ;; can't write anything.
-                 (file-writable-p (expand-file-name
-                                   (or temporary-file-directory ""))))
-        (let ((tmp-dir (make-temp-file "emacs-testsuite-" t)))
-          (add-hook 'kill-emacs-hook (lambda () (delete-directory tmp-dir t)))
-          (push tmp-dir native-comp-eln-load-path))))
+            native-comp-eln-load-path))
 
     ;; Look in each dir in load-path for a subdirs.el file.  If we
     ;; find one, load it, which will add the appropriate subdirs of
diff --git a/src/emacs.c b/src/emacs.c
index a9126e7be8..9197a19f36 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -2961,6 +2961,10 @@ shut_down_emacs (int sig, Lisp_Object stuff)
       check_message_stack ();
     }
 
+#ifdef HAVE_NATIVE_COMP
+  eln_load_path_final_clean_up ();
+#endif
+
 #ifdef MSDOS
   dos_cleanup ();
 #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]