From: Robert Pluim <rpluim@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
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 16:19:49 +0200 [thread overview]
Message-ID: <87bkicjvne.fsf@gmail.com> (raw)
In-Reply-To: <jwv4jo4pkl4.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 22 May 2023 09:58:34 -0400")
>>>>> On Mon, 22 May 2023 09:58:34 -0400, Stefan Monnier <monnier@iro.umontreal.ca> said:
>> 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))))))
Stefan> The (car load-path) is intended to return an element
Stefan> that causes `add-to-list` to do nothing, but your patch makes it go
Stefan> through `directory-file-name` which risks changing the string and thus
Stefan> causing the kind of duplicate we're trying to avoid.
OK
Stefan> IOW, the `directory-file-name` should be directly around
Stefan> `file-name-directory` instead (tho I'm not 100% sure
Stefan> `file-name-directory` can never return nil here, so it might require an
Stefan> additional let binding and check).
Stefan> Admittedly, this exact problem was present before Philip's change
Stefan> (it was introduced by commit 4d3a595d8d3e in 2015) and is also present in
Stefan> `loaddefs-generate--rubric`.
Yes, `loaddefs-generate--rubric` needs fixing, but nothing currently
calls that branch as far as I can tell.
`file-name-directory' will return nil for names with no slashes in
them, but I donʼt know if thatʼs possible here.
I *think* we can use `when-let*' here, since subr.el is preloaded.
Stefan> In any case, some autoloads file use a trailing / and others don't,
Stefan> depending on which version of Emacs has been used to generate it, so we
Stefan> need the patch below, I think (which also reverts to adding just `pkg-dir`
Stefan> since that's what we used to do in Emacs-28 and this is old
Stefan> compatibility code anyway).
Ah, so thatʼs where the duplication was coming from. Eli, do you want
that on the release branch?
>> 1. Can `load-file-name' ever be nil here?
Stefan> It's always a possibility (e.g. if you open the autoloads file and do
Stefan> `eval-buffer`), tho some older versions of Emacs didn't bother to check
Stefan> for it. Not sure it's important.
Weʼre talking about emacs-29. Iʼm not about to risk having
`load-file-nameʼ be nil ';-)
>> 2. Should we just use $# instead of `load-file-nameʼ'?
Stefan> We used to use $# but that interacts poorly with compilation.
Stefan> Until recently we never compiled autoloads files, but it's becoming much
Stefan> more common.
OK, so, `loaddefs-generate--rubric' is probably worth changing (on master)
And hereʼs another reason to avoid it: I typoed '#$' as '$#' :D
Stefan> diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
Stefan> index 78017b77677..236a8e974e7 100644
Stefan> --- a/lisp/emacs-lisp/package.el
Stefan> +++ b/lisp/emacs-lisp/package.el
Stefan> @@ -902,7 +902,12 @@ package-activate-1
Stefan> (package--reload-previously-loaded pkg-desc))
Stefan> (with-demoted-errors "Error loading autoloads: %s"
Stefan> (load (package--autoloads-file-name pkg-desc) nil t))
Stefan> - (add-to-list 'load-path (directory-file-name pkg-dir)))
Stefan> + ;; FIXME: Since 2013 (commit 4fac34cee97a), the autoload files take
Stefan> + ;; care of changing the `load-path', so maybe it's time to
Stefan> + ;; remove this fallback code?
Stefan> + (unless (or (member (file-name-as-directory pkg-dir) load-path)
Stefan> + (member (directory-file-name pkg-dir) load-path))
Stefan> + (add-to-list 'load-path pkg-dir)))
Stefan> ;; Add info node.
Stefan> (when (file-exists-p (expand-file-name "dir" pkg-dir))
Stefan> ;; FIXME: not the friendliest, but simple.
Robert
--
next prev parent reply other threads:[~2023-05-22 14:19 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
2023-05-22 14:19 ` Robert Pluim [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bkicjvne.fsf@gmail.com \
--to=rpluim@gmail.com \
--cc=63625@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=philipk@posteo.net \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.