Subject: Re: bug#63625: 29.0.90; package-install inserts package directory into load-path twice.

From: Robert Pluim <[email-masked]>
Date: Mon, 22 May 2023 10:55:13 +0200

>>>>> On Sat, 20 May 2023 16:45:34 -0500, todd smith via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email-masked]> said:

    Todd> 1) trash ~/.emacs.d     ;; i.e. remove .emacs.d (optional)

    Todd> 2) emacs -Q   (the -Q isn’t necessary,  I’ve observed the problem every way that I’ve started emacs)

    Todd> 3) in *scratch* buffer, type and execute "(package-insert ‘ack)”       (or run M-x package-install or install from M-x list-packages.
    Todd> Any and every package I’ve installed produces the problem, ack is just easy to type)

    Todd> 4) C-h v  load-path    (that is, run describe-variable on load-path to see its value, note the first two entries)

    Todd> Its value is
    Todd> ("/Users/todd/.emacs.d/elpa/ack-1.11"
    Todd> "/Users/todd/.emacs.d/elpa/ack-1.11/"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/vc"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/use-package"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/url"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/textmodes"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/progmodes"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/play"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/org"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/nxml"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/net"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/mh-e"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/mail"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/leim"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/language"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/international"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/image"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/gnus"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/eshell"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/erc"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/emulation"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/emacs-lisp"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/cedet"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/calendar"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/calc"
    Todd> "/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/emacs/29.0.90/lisp/obsolete")

This is because we didnʼt respect DRY. package.el should use the
package support of `loaddefs-generate', but that doesnʼt expose the
requisite feature of `loaddefs-generate--rubric' (maybe on master it does).

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 78017b77677..31e5e0809a8 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1107,8 +1107,9 @@ package-generate-autoloads
         ;; Add the directory that will contain the autoload file to
         ;; the load path.  We don't hard-code `pkg-dir', to avoid
         ;; issues if the package directory is moved around.
+        (directory-file-name
         (or (and load-file-name (file-name-directory load-file-name))
-            (car load-path)))))
+            (car load-path))))))
     (let ((buf (find-buffer-visiting output-file)))
       (when buf (kill-buffer buf)))
     auto-name))

Robert
--