[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/package+vc 576593a2b2 2/9: Add new command to install a package
From: |
Philip Kaludercic |
Subject: |
feature/package+vc 576593a2b2 2/9: Add new command to install a package via symbolic linking |
Date: |
Wed, 12 Oct 2022 15:31:33 -0400 (EDT) |
branch: feature/package+vc
commit 576593a2b284e199c11394398a44ca28a4473cff
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add new command to install a package via symbolic linking
* lisp/emacs-lisp/package-vc.el (package-vc-unpack-1): Add new function.
(package-vc-unpack): Use 'package-vc-unpack-1'.
(package-vc-link-project): Add new command.
---
lisp/emacs-lisp/package-vc.el | 148 ++++++++++++++++++++++++------------------
1 file changed, 84 insertions(+), 64 deletions(-)
diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el
index fd8639e4c5..a9aa685402 100644
--- a/lisp/emacs-lisp/package-vc.el
+++ b/lisp/emacs-lisp/package-vc.el
@@ -43,6 +43,7 @@
(require 'vc)
(require 'seq)
(require 'xdg)
+(require 'project)
(defgroup package-vc nil
"Manage packages from VC checkouts."
@@ -153,6 +154,72 @@ The output is written out into PKG-FILE."
"\n")
nil pkg-file nil 'silent))))
+(defun package-vc-unpack-1 (pkg-desc pkg-dir)
+ "Install PKG-DESC that is already located in PKG-DIR."
+ ;; In case the package was installed directly from source, the
+ ;; dependency list wasn't know beforehand, and they might have
+ ;; to be installed explicitly.
+ (let (deps)
+ (dolist (file (directory-files pkg-dir t "\\.el\\'" t))
+ (with-temp-buffer
+ (insert-file-contents file)
+ (when-let* ((require-lines (lm-header-multiline "package-requires")))
+ (thread-last
+ (mapconcat #'identity require-lines " ")
+ package-read-from-string
+ package--prepare-dependencies
+ (nconc deps)
+ (setq deps)))))
+ (dolist (dep deps)
+ (cl-callf version-to-list (cadr dep)))
+ (package-download-transaction
+ (package-compute-transaction nil (delete-dups deps))))
+
+ (let ((default-directory (file-name-as-directory pkg-dir))
+ (name (package-desc-name pkg-desc))
+ (pkg-file (expand-file-name (package--description-file pkg-dir)
pkg-dir)))
+ ;; Generate autoloads
+ (package-generate-autoloads name pkg-dir)
+ (vc-ignore (concat "/" (file-relative-name
+ (expand-file-name (format "%s-autoloads.el" name))
+ default-directory)))
+
+ ;; Generate package file
+ (package-vc-generate-description-file pkg-desc pkg-file)
+ (vc-ignore (concat "/" (file-relative-name pkg-file default-directory)))
+
+ ;; Detect a manual
+ (when (executable-find "install-info")
+ ;; Only proceed if we can find an unambiguous TeXinfo file
+ (let ((texi-files (directory-files pkg-dir t "\\.texi\\'"))
+ (dir-file (expand-file-name "dir" pkg-dir)))
+ (when (length= texi-files 1)
+ (call-process "install-info" nil nil nil
+ (concat "--dir=" dir-file)
+ (car texi-files)))
+ (vc-ignore "/dir"))))
+
+ ;; Update package-alist.
+ (let ((new-desc (package-load-descriptor pkg-dir)))
+ ;; Activation has to be done before compilation, so that if we're
+ ;; upgrading and macros have changed we load the new definitions
+ ;; before compiling.
+ (when (package-activate-1 new-desc :reload :deps)
+ ;; FIXME: Compilation should be done as a separate, optional, step.
+ ;; E.g. for multi-package installs, we should first install all packages
+ ;; and then compile them.
+ (package--compile new-desc)
+ (when package-native-compile
+ (package--native-compile-async new-desc))
+ ;; After compilation, load again any files loaded by
+ ;; `activate-1', so that we use the byte-compiled definitions.
+ (package--reload-previously-loaded new-desc)))
+
+ ;; Mark package as selected
+ (package--save-selected-packages
+ (cons (package-desc-name pkg-desc)
+ package-selected-packages)))
+
(defun package-vc-unpack (pkg-desc)
"Install the package described by PKG-DESC."
(let* ((name (package-desc-name pkg-desc))
@@ -191,70 +258,9 @@ The output is written out into PKG-FILE."
(make-symbolic-link (file-name-concat repo-dir dir) pkg-dir))
(when-let ((default-directory repo-dir)
(rev (or (alist-get :rev attr) branch)))
- (vc-retrieve-tag pkg-dir rev))
-
- ;; In case the package was installed directly from source, the
- ;; dependency list wasn't know beforehand, and they might have
- ;; to be installed explicitly.
- (let (deps)
- (dolist (file (directory-files pkg-dir t "\\.el\\'" t))
- (with-temp-buffer
- (insert-file-contents file)
- (when-let* ((require-lines (lm-header-multiline
"package-requires")))
- (thread-last
- (mapconcat #'identity require-lines " ")
- package-read-from-string
- package--prepare-dependencies
- (nconc deps)
- (setq deps)))))
- (dolist (dep deps)
- (cl-callf version-to-list (cadr dep)))
- (package-download-transaction
- (package-compute-transaction nil (delete-dups deps)))))
-
- (let ((default-directory (file-name-as-directory pkg-dir))
- (name (package-desc-name pkg-desc))
- (pkg-file (expand-file-name (package--description-file pkg-dir)
pkg-dir)))
- ;; Generate autoloads
- (package-generate-autoloads name pkg-dir)
- (vc-ignore (concat "/" (file-relative-name
- (expand-file-name (format "%s-autoloads.el"
name))
- default-directory)))
-
- ;; Generate package file
- (package-vc-generate-description-file pkg-desc pkg-file)
- (vc-ignore (concat "/" (file-relative-name pkg-file default-directory)))
-
- ;; Detect a manual
- (when (executable-find "install-info")
- ;; Only proceed if we can find an unambiguous TeXinfo file
- (let ((texi-files (directory-files pkg-dir t "\\.texi\\'"))
- (dir-file (expand-file-name "dir" pkg-dir)))
- (when (length= texi-files 1)
- (call-process "install-info" nil nil nil
- (concat "--dir=" dir-file)
- (car texi-files)))
- (vc-ignore "/dir"))))
-
- ;; Update package-alist.
- (let ((new-desc (package-load-descriptor pkg-dir)))
- ;; Activation has to be done before compilation, so that if we're
- ;; upgrading and macros have changed we load the new definitions
- ;; before compiling.
- (when (package-activate-1 new-desc :reload :deps)
- ;; FIXME: Compilation should be done as a separate, optional, step.
- ;; E.g. for multi-package installs, we should first install all
packages
- ;; and then compile them.
- (package--compile new-desc)
- (when package-native-compile
- (package--native-compile-async new-desc))
- ;; After compilation, load again any files loaded by
- ;; `activate-1', so that we use the byte-compiled definitions.
- (package--reload-previously-loaded new-desc)))
-
- ;; Mark package as selected
- (package--save-selected-packages
- (cons name package-selected-packages))))
+ (vc-retrieve-tag pkg-dir rev)))
+
+ (package-vc-unpack-1 pkg-desc pkg-dir)))
(defun package-vc-sourced-packages-list ()
"Generate a list of packages with VC data."
@@ -325,6 +331,20 @@ be requested using REV."
;;;###autoload
(defalias 'package-checkout #'package-vc-install)
+(defun package-vc-link-project (dir)
+ "Install the package in DIR by linking it into the ELPA directory."
+ (interactive (list (project-prompt-project-dir)))
+ (unless (vc-responsible-backend dir)
+ (user-error "Directory %S is not under version control" dir))
+ (package--archives-initialize)
+ (let* ((name (file-name-base (directory-file-name dir)))
+ (pkg-dir (expand-file-name name package-user-dir)))
+ (make-symbolic-link dir pkg-dir)
+ (package-vc-unpack-1 (package-desc-create
+ :name (intern name)
+ :kind 'vc)
+ pkg-dir)))
+
(defun package-vc-read-pkg (prompt)
"Query for a source package description with PROMPT."
(cadr (assoc (completing-read
- feature/package+vc updated (8e6e6e6de5 -> 982c0e6c15), Philip Kaludercic, 2022/10/12
- feature/package+vc 0610e6f9f1 5/9: Rename 'package-vc-link-project' to 'package-vc-link-directory', Philip Kaludercic, 2022/10/12
- feature/package+vc 576593a2b2 2/9: Add new command to install a package via symbolic linking,
Philip Kaludercic <=
- feature/package+vc 7cdc11ee99 8/9: Document package-vc, Philip Kaludercic, 2022/10/12
- feature/package+vc 73669f73e6 7/9: Allow specifying a package name for 'package-vc-link-directory', Philip Kaludercic, 2022/10/12
- feature/package+vc 22d768a29d 4/9: Run 'package-vc-unpack-1' after updating source packages, Philip Kaludercic, 2022/10/12
- feature/package+vc 1a5e705dda 3/9: ; * lisp/vc/vc-cvs.el (vc-cvs-clone): Remove function, Philip Kaludercic, 2022/10/12
- feature/package+vc 982c0e6c15 9/9: * etc/NEWS: Mention package-vc additions, Philip Kaludercic, 2022/10/12
- feature/package+vc 4a25205ec1 1/9: Only use 'package-vc-repository-store' if necessary, Philip Kaludercic, 2022/10/12
- feature/package+vc 0e3b67e3a3 6/9: * lisp/emacs-lisp/package-vc.el (package-vc-refresh): Add function., Philip Kaludercic, 2022/10/12