From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.bugs Subject: bug#63625: 29.0.90; package-install inserts package directory into load-path twice. Date: Mon, 22 May 2023 16:19:49 +0200 Message-ID: <87bkicjvne.fsf@gmail.com> References: <4ACD9E26-B5A6-412E-8DFC-C09C05A4EACD@mac.com> <871qj8lp8u.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15487"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Philip Kaludercic , 63625@debbugs.gnu.org, todd smith To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 22 16:21:35 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q16Pm-0003g8-Q0 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 22 May 2023 16:21:34 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q16PI-0002cp-Dm; Mon, 22 May 2023 10:21:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q16PG-0002cM-WD for bug-gnu-emacs@gnu.org; Mon, 22 May 2023 10:21:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q16PG-00030r-I4 for bug-gnu-emacs@gnu.org; Mon, 22 May 2023 10:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q16PG-0002Ut-2p for bug-gnu-emacs@gnu.org; Mon, 22 May 2023 10:21:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Robert Pluim Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 22 May 2023 14:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63625 X-GNU-PR-Package: emacs Original-Received: via spool by 63625-submit@debbugs.gnu.org id=B63625.16847652049482 (code B ref 63625); Mon, 22 May 2023 14:21:02 +0000 Original-Received: (at 63625) by debbugs.gnu.org; 22 May 2023 14:20:04 +0000 Original-Received: from localhost ([127.0.0.1]:35474 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q16OI-0002Sn-I8 for submit@debbugs.gnu.org; Mon, 22 May 2023 10:20:04 -0400 Original-Received: from mail-wm1-f49.google.com ([209.85.128.49]:57627) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q16OD-0002Ry-4v for 63625@debbugs.gnu.org; Mon, 22 May 2023 10:20:01 -0400 Original-Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-3f606912ebaso8391835e9.3 for <63625@debbugs.gnu.org>; Mon, 22 May 2023 07:19:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684765191; x=1687357191; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=NpaMKGCUUYfs7ukAM6n9c00q07bSGjQmWH8kKzHNWIs=; b=AiTPbGNWb30kowewByH3czXBOH/6jDdfcM+ShhNV/NVNflmuWX6YF1ny6et3YAOatG xPrsNpxskYuk860HQq2w3Nuoe4LgGtaskAGOmIjs5N+0ulxydlVXWzBCeufhYaf/lJlL +Gpn9tqtV1cekgDOyUxvmIkU2nUI91fEKpYjWyXcqEer0WWOD+kodnnFyf2oVVFVXHlK ENequTdm7l/Rgz0/ApUSkNIfg94RrHThi45xqKE+RrQ+IGs5mWDDySDIochmWa7xP66x Awj0nHm4qu2fm7XKS/danxBWjXxB8/eF5CbIZFyfrXqpgjfxl6Byrsy/eAQNCvINv3Xa i5dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684765191; x=1687357191; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NpaMKGCUUYfs7ukAM6n9c00q07bSGjQmWH8kKzHNWIs=; b=VP9WWrLM+dh8rOwkv0Pzhb80DvD0xP3Rq57X7IbilMmr34CtHZ9wpX1bfe2aOzlCnZ kaUjEObNZFsNyzP+MmqaItp0EOOcComK5p96hk+htpic8MN05MxBkgM33wptvBLe7swW hKy1iT3EiSHClrPwHEK8P5mjXfsezJ0vM9CoGL37rDQzvlnEh2CjJedQOmwBYaj5Opff 9fH/1W34RZy7kMYdIChlr54HL+tznZakjK8qcUHFwI0T82p4RgSPp66NC+iBCS6y5EEU ku+lCV2XHC88Z1a7RHWqqekHrCR1mU+FxAAJ2DhCgy/jXATSfs3tidK3xoEQH/68pnh4 oaNw== X-Gm-Message-State: AC+VfDxtPmxZBBCaZHQ3uWrnr2/NmSS/0at/AvudSSY6RZRRBAAnOJvs a10p6yD575erzUW4vug3bGM= X-Google-Smtp-Source: ACHHUZ6f/I9MS/VJNGqFibgs1Y6EyVKNbB1PHUFLZUizWqjiqvmWaRaLT8l2Lm8HFjg1JLoYyPXkFw== X-Received: by 2002:a05:600c:ad0:b0:3f4:23df:c681 with SMTP id c16-20020a05600c0ad000b003f423dfc681mr7002850wmr.12.1684765191013; Mon, 22 May 2023 07:19:51 -0700 (PDT) Original-Received: from rltb ([82.66.8.55]) by smtp.gmail.com with ESMTPSA id f12-20020a5d58ec000000b00309257ad16csm7873863wrd.29.2023.05.22.07.19.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 07:19:50 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Mon, 22 May 2023 09:58:34 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:262158 Archived-At: >>>>> On Mon, 22 May 2023 09:58:34 -0400, Stefan Monnier said: >> This is because we didn=CA=BCt respect DRY. package.el should use the >> package support of `loaddefs-generate', but that doesn=CA=BCt expose= the >> requisite feature of `loaddefs-generate--rubric' (maybe on master it= does). >>=20 >> 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 i= t go Stefan> through `directory-file-name` which risks changing the string a= nd 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 re= quire an Stefan> additional let binding and check). Stefan> Admittedly, this exact problem was present before Philip's chan= ge 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=CA=BCt know if that=CA=BCs 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 do= n't, Stefan> depending on which version of Emacs has been used to generate i= t, so we Stefan> need the patch below, I think (which also reverts to adding jus= t `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=CA=BCs 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=CA=BCre talking about emacs-29. I=CA=BCm not about to risk having `load-file-name=CA=BC be nil ';-) >> 2. Should we just use $# instead of `load-file-name=CA=BC'? Stefan> We used to use $# but that interacts poorly with compilation. Stefan> Until recently we never compiled autoloads files, but it's beco= ming much Stefan> more common. OK, so, `loaddefs-generate--rubric' is probably worth changing (on master) And here=CA=BCs another reason to avoid it: I typoed '#$' as '$#' :D Stefan> diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/packa= ge.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 autolo= ad files take Stefan> + ;; care of changing the `load-path', so maybe it's tim= e to Stefan> + ;; remove this fallback code? Stefan> + (unless (or (member (file-name-as-directory pkg-dir) l= oad-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 --=20