Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with package-quickstart #771

Open
monnier opened this issue Jun 8, 2024 · 4 comments
Open

Incompatibility with package-quickstart #771

monnier opened this issue Jun 8, 2024 · 4 comments

Comments

@monnier
Copy link
Contributor

monnier commented Jun 8, 2024

if you create a ~/.emacs.d/package-quickstart.elfile withM-x package-quickstart-refresh`, you may see startup error messages like:

Error during quickstart: (file-missing "Cannot open load file" "Aucun fichier ou dossier de ce type" "<...>/.emacs.d/generic/proof-site")

This is because of the use of load-file-name within an eval-and-compile inside an autoloaded chunk of code.
The patch below seems to fix it (and it also takes advantage of macroexp-file-name when available).

diff --git a/proof-general.el b/proof-general.el
index c1f4c9127f..b948fe2172 100644
--- a/proof-general.el
+++ b/proof-general.el
@@ -3,7 +3,7 @@
 ;; This file is part of Proof General.
 
 ;; Portions © Copyright 1994-2012  David Aspinall and University of Edinburgh
-;; Portions © Copyright 2003-2022  Free Software Foundation, Inc.
+;; Portions © Copyright 2003-2024  Free Software Foundation, Inc.
 ;; Portions © Copyright 2001-2017  Pierre Courtieu
 ;; Portions © Copyright 2010, 2016  Erik Martin-Dorel
 ;; Portions © Copyright 2011-2013, 2016-2017  Hendrik Tews
@@ -55,19 +55,21 @@
 ;;   mostly mode hooks and autoloads).
 
 ;;;###autoload
-(eval-and-compile
-  (defvar pg-init--script-full-path
-    (or (bound-and-true-p byte-compile-current-file)
-        (and load-in-progress load-file-name)
+(defmacro pg-init--pg-root ()
+  `(file-name-directory
+    ,(if (fboundp 'macroexp-file-name) ;; Emacs≥28
+         `(macroexp-file-name)
+       `(or (bound-and-true-p byte-compile-current-file)
+            (and load-in-progress load-file-name)
+            buffer-file-name))))
 
-        (buffer-file-name)))
-  (defvar pg-init--pg-root
-    (file-name-directory pg-init--script-full-path)))
 
 ;;;###autoload
 (unless (bound-and-true-p byte-compile-current-file)
-  ;; This require breaks compilation, so it must only run when loading the package.
-  (require 'proof-site (expand-file-name "generic/proof-site" pg-init--pg-root)))
+  ;; This `require' breaks compilation, so it must run only when loading
+  ;; the package.
+  (require 'proof-site (expand-file-name "generic/proof-site"
+                                         (pg-init--pg-root))))
 
 (eval-when-compile
   ;; FIXME: [ This is used during installation of the ELPA package ]
@@ -81,7 +83,7 @@
            "coq" "easycrypt" "pghaskell" "pgocaml" "pgshell" "phox" "qrhl"
            )))
     (dolist (dir byte-compile-directories)
-      (add-to-list 'load-path (expand-file-name dir pg-init--pg-root)))))
+      (add-to-list 'load-path (expand-file-name dir (pg-init--pg-root))))))
 
 (provide 'proof-general)
 ;;; proof-general.el ends here
@monnier
Copy link
Contributor Author

monnier commented Jun 8, 2024

Nah, scratch that, it doesn't fix it either.

@monnier
Copy link
Contributor Author

monnier commented Jun 8, 2024

OK, this one seems to fare better (and I believe my test does now test what I intended):

diff --git a/proof-general.el b/proof-general.el
index c1f4c9127f..72945239e2 100644
--- a/proof-general.el
+++ b/proof-general.el
@@ -3,7 +3,7 @@
 ;; This file is part of Proof General.
 
 ;; Portions © Copyright 1994-2012  David Aspinall and University of Edinburgh
-;; Portions © Copyright 2003-2022  Free Software Foundation, Inc.
+;; Portions © Copyright 2003-2024  Free Software Foundation, Inc.
 ;; Portions © Copyright 2001-2017  Pierre Courtieu
 ;; Portions © Copyright 2010, 2016  Erik Martin-Dorel
 ;; Portions © Copyright 2011-2013, 2016-2017  Hendrik Tews
@@ -54,20 +54,15 @@
 ;; * Loading a minimal PG setup on startup (not all of Proof General, of course;
 ;;   mostly mode hooks and autoloads).
 
-;;;###autoload
-(eval-and-compile
-  (defvar pg-init--script-full-path
-    (or (bound-and-true-p byte-compile-current-file)
-        (and load-in-progress load-file-name)
-
-        (buffer-file-name)))
-  (defvar pg-init--pg-root
-    (file-name-directory pg-init--script-full-path)))
-
 ;;;###autoload
 (unless (bound-and-true-p byte-compile-current-file)
-  ;; This require breaks compilation, so it must only run when loading the package.
-  (require 'proof-site (expand-file-name "generic/proof-site" pg-init--pg-root)))
+  ;; This require breaks compilation, so it must run only when loading
+  ;; the package.
+  (require 'proof-site
+           (expand-file-name "generic/proof-site"
+                             (file-name-directory
+                              (or (and load-in-progress load-file-name)
+                                  buffer-file-name)))))
 
 (eval-when-compile
   ;; FIXME: [ This is used during installation of the ELPA package ]
@@ -76,12 +71,17 @@
   ;; session, so we here add to load-path all the subdirectories so
   ;; that files in (say) coq/ can (require 'coq-foo) and the compiler will find
   ;; the corresponding file.
-  (let ((byte-compile-directories
+  (let ((pg-root
+         (file-name-directory
+          (or (bound-and-true-p byte-compile-current-file)
+              (and load-in-progress load-file-name)
+              buffer-file-name)))
+        (byte-compile-directories
          '("generic" "lib"
            "coq" "easycrypt" "pghaskell" "pgocaml" "pgshell" "phox" "qrhl"
            )))
     (dolist (dir byte-compile-directories)
-      (add-to-list 'load-path (expand-file-name dir pg-init--pg-root)))))
+      (add-to-list 'load-path (expand-file-name dir pg-root)))))
 
 (provide 'proof-general)
 ;;; proof-general.el ends here

@erikmd
Copy link
Member

erikmd commented Jun 15, 2024

Hi @monnier, thanks for your report and the patches!

The code you touched was initially written by @cpitclaudel so I Cc him in case he'd like to comment as well.


AFAIAC, I wasn't aware of package-quickstart but I see this is a new emacs feature (since 27.1) that is documented here.

I believe it'd be nice indeed to refactor this startup code provided this is backed up by CI tests.

So I have 2 questions (Cc @hendriktews, feel free to comment if you have an opinion!)

  1. what test should we add to the CI to test that the refactor indeed fixes the issue?

  2. is it needed to add some specific tests to ensure the refactor does not break existing "workflows"? (including MELPA's build (for instance, I've been told about this project: https://github.com/riscy/melpazoid (developed by one of the MELPA maintainers))), or not and I'm just worrying too much.

@monnier
Copy link
Contributor Author

monnier commented Jun 16, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants