unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Robert Pluim <rpluim@gmail.com>
Cc: Philip Kaludercic <philipk@posteo.net>,
	63625@debbugs.gnu.org, todd smith <toddasmith@mac.com>
Subject: bug#63625: 29.0.90; package-install inserts package directory into load-path  twice.
Date: Mon, 22 May 2023 09:58:34 -0400	[thread overview]
Message-ID: <jwv4jo4pkl4.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <871qj8lp8u.fsf@gmail.com> (Robert Pluim's message of "Mon, 22 May 2023 10:55:13 +0200")

> 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))))))

The (car load-path) is intended to return an element
that causes `add-to-list` to do nothing, but your patch makes it go
through `directory-file-name` which risks changing the string and thus
causing the kind of duplicate we're trying to avoid.

IOW, the `directory-file-name` should be directly around
`file-name-directory` instead (tho I'm not 100% sure
`file-name-directory` can never return nil here, so it might require an
additional let binding and check).
Admittedly, this exact problem was present before Philip's change
(it was introduced by commit 4d3a595d8d3e in 2015) and is also present in
`loaddefs-generate--rubric`.

In any case, some autoloads file use a trailing / and others don't,
depending on which version of Emacs has been used to generate it, so we
need the patch below, I think (which also reverts to adding just `pkg-dir`
since that's what we used to do in Emacs-28 and this is old
compatibility code anyway).

> 1. Can `load-file-name' ever be nil here?

It's always a possibility (e.g. if you open the autoloads file and do
`eval-buffer`), tho some older versions of Emacs didn't bother to check
for it.  Not sure it's important.

> 2. Should we just use $# instead of `load-file-nameʼ'?

We used to use $# but that interacts poorly with compilation.
Until recently we never compiled autoloads files, but it's becoming much
more common.


        Stefan


diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 78017b77677..236a8e974e7 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -902,7 +902,12 @@ package-activate-1
           (package--reload-previously-loaded pkg-desc))
         (with-demoted-errors "Error loading autoloads: %s"
           (load (package--autoloads-file-name pkg-desc) nil t))
-        (add-to-list 'load-path (directory-file-name pkg-dir)))
+        ;; FIXME: Since 2013 (commit 4fac34cee97a), the autoload files take
+        ;; care of changing the `load-path', so maybe it's time to
+        ;; remove this fallback code?
+        (unless (or (member (file-name-as-directory pkg-dir) load-path)
+                    (member (directory-file-name pkg-dir) load-path))
+          (add-to-list 'load-path pkg-dir)))
       ;; Add info node.
       (when (file-exists-p (expand-file-name "dir" pkg-dir))
         ;; FIXME: not the friendliest, but simple.






  parent reply	other threads:[~2023-05-22 13:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-20 21:45 bug#63625: 29.0.90; package-install inserts package directory into load-path twice todd smith via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-22  8:55 ` Robert Pluim
2023-05-22 11:25   ` Eli Zaretskii
2023-05-22 12:46     ` Robert Pluim
2023-05-22 13:18     ` Philip Kaludercic
2023-05-22 13:54       ` Robert Pluim
2023-05-22 13:58   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-05-22 14:19     ` Robert Pluim
2023-05-22 15:04       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-22 15:36         ` Robert Pluim
2023-05-22 15:53           ` Eli Zaretskii
2023-05-22 16:57             ` Robert Pluim
2023-05-23 12:06               ` Eli Zaretskii
2023-05-23 13:20                 ` Robert Pluim
2023-05-23 13:46                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-22 15:49       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv4jo4pkl4.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=63625@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=philipk@posteo.net \
    --cc=rpluim@gmail.com \
    --cc=toddasmith@mac.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).