# HG changeset patch
# User Aidan Kehoe <kehoea@parhasard.net>
# Date 1656333099 -3600
#      Mon Jun 27 13:31:39 2022 +0100
# Node ID c6966a009d0dc3b546c9d843141c1fb5daa89b9e
# Parent  16e37125d7ea85048e89197ce8fe83f44b00ccc5
Don't create a lock file when generating finder-inf.el

lisp/ChangeLog addition:

2022-06-27  Aidan Kehoe  <kehoea@parhasard.net>

	* finder.el (finder-compile-keywords):
	Don't use the save-buffer infrastructure when generating
	finder-inf.el, since that leads to lock files, making parallel
	builds less likely to work. Thank you Mats Lidell and the Gentoo
	users!

src/ChangeLog addition:

2022-06-27  Aidan Kehoe  <kehoea@parhasard.net>

	* Makefile.in.in ($(LISP)/finder-inf.el):
	Don't remove finder-inf.el before regenerating it, Lisp will
	overwrite it.

diff -r 16e37125d7ea -r c6966a009d0d lisp/finder.el
--- a/lisp/finder.el	Sun Jun 26 19:14:02 2022 +0300
+++ b/lisp/finder.el	Mon Jun 27 13:31:39 2022 +0100
@@ -151,7 +151,7 @@
 arguments compiles from `load-path'."
   (save-excursion
     ;; XEmacs change
-    (find-file (expand-file-name "finder-inf.el" lisp-directory))
+    (set-buffer (generate-new-buffer "finder-inf.el"))
     (let ((processed nil)
 	  (directory-abbrev-alist
 	   (append
@@ -160,11 +160,12 @@
                                      "")))
 		    finder-abbreviate-directory-list)
 	    directory-abbrev-alist))
-	  (using-load-path))
+	  using-load-path second-line-marker finder-scratch)
       (or dirs (setq dirs load-path))
       (setq using-load-path (equal dirs load-path))
       (erase-buffer)
       (insert ";;; finder-inf.el --- keyword-to-package mapping\n")
+      (setq second-line-marker (point-marker))
       (insert ";; Keywords: help\n")
       (insert ";;; Commentary:\n")
       (insert ";; Don't edit this file.  It's generated by finder.el\n\n")
@@ -180,7 +181,8 @@
 		(if (not finder-compile-keywords-quiet)
 		    (message "Processing %s ..." f))
 		(save-excursion
-		  (set-buffer (get-buffer-create "*finder-scratch*"))
+		  (set-buffer (setq finder-scratch
+                                    (get-buffer-create "*finder-scratch*")))
 		  (buffer-disable-undo (current-buffer))
 		  (erase-buffer)
 		  (insert-file-contents (expand-file-name f d))
@@ -210,10 +212,23 @@
 	    (directory-files d nil "^[^=].*\\.el$"))))
        dirs)
       (insert "))\n\n(provide 'finder-inf)\n\n;;; finder-inf.el ends here\n")
-      (kill-buffer "*finder-scratch*")
+      (if finder-scratch (kill-buffer finder-scratch))
       (unless noninteractive
 	(eval-current-buffer)) ; So we get the new keyword list immediately
-      (basic-save-buffer))))
+      (goto-char (point-min))
+      (if (re-search-forward "[^\x00-\x7f]" nil t)
+          (progn
+            (goto-char (point-min))
+            (if (re-search-forward "[^\x00-\xff]" nil t)
+                (progn (goto-char second-line-marker)
+                       (insert ";;; -*- coding: escape-quoted -*-\n")
+                       (setq buffer-file-coding-system 'iso-8859-1-unix))
+              (goto-char second-line-marker)
+              (insert ";;; -*- coding: iso-8859-1 -*-\n")
+              (setq buffer-file-coding-system 'escape-quoted-unix)))
+        (setq buffer-file-coding-system 'no-conversion-unix))
+      (write-region (point-min) (point-max)
+                    (expand-file-name "finder-inf.el" lisp-directory)))))
 
 (defun finder-compile-keywords-make-dist ()
   "Regenerate `finder-inf.el' for the Emacs distribution."
diff -r 16e37125d7ea -r c6966a009d0d src/Makefile.in.in
--- a/src/Makefile.in.in	Sun Jun 26 19:14:02 2022 +0300
+++ b/src/Makefile.in.in	Mon Jun 27 13:31:39 2022 +0100
@@ -590,7 +590,6 @@
 
 $(LISP)/finder-inf.el: update-elc-2
 	@echo "Building finder database ..."
-	$(RM) $(LISP)/finder-inf.el
 	$(XEMACS_BATCH)	-eval "(setq finder-compile-keywords-quiet t)" \
 		-eval "(setq lisp-directory \"$(LISP)\")" \
 		-l finder -f finder-compile-keywords
