aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Malabarba2015-12-03 14:50:09 +0000
committerArtur Malabarba2015-12-03 16:13:57 +0000
commit67c6906a5f2e79ef771a1d7c8abeb29eb633c659 (patch)
tree691c41d09d1f1e89974b7562dba943790e638b4e
parent44d6957767f4de200aab437166589652033f42fe (diff)
downloademacs-67c6906a5f2e79ef771a1d7c8abeb29eb633c659.tar.gz
emacs-67c6906a5f2e79ef771a1d7c8abeb29eb633c659.zip
* lisp/emacs-lisp/package.el: Refactor package activation code
(package-activate): Move code that activates dependencies into package-activate-1. (package--load-files-for-activation): New function. (package-activate-1): Add code for (optionally) activating dependencies, and move file-loading code into `package--load-files-for-activation'.
-rw-r--r--lisp/emacs-lisp/package.el63
1 files changed, 34 insertions, 29 deletions
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 91a6330d190..f94e7aaa741 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -646,8 +646,30 @@ PKG-DESC is a `package-desc' object."
646(defvar Info-directory-list) 646(defvar Info-directory-list)
647(declare-function info-initialize "info" ()) 647(declare-function info-initialize "info" ())
648 648
649(defun package-activate-1 (pkg-desc &optional reload) 649(defun package--load-files-for-activation (pkg-desc reload)
650 "Load files for activating a package given by PKG-DESC.
651Load the autoloads file, and ensure `load-path' is setup. If
652RELOAD is non-nil, also load all files in the package that
653correspond to previously loaded files."
654 (let* ((loaded-files-list (when reload
655 (package--list-loaded-files (package-desc-dir pkg-desc)))))
656 ;; Add to load path, add autoloads, and activate the package.
657 (package--activate-autoloads-and-load-path pkg-desc)
658 ;; Call `load' on all files in `package-desc-dir' already present in
659 ;; `load-history'. This is done so that macros in these files are updated
660 ;; to their new definitions. If another package is being installed which
661 ;; depends on this new definition, not doing this update would cause
662 ;; compilation errors and break the installation.
663 (with-demoted-errors "Error in package--load-files-for-activation: %s"
664 (mapc (lambda (feature) (load feature nil t))
665 ;; Skip autoloads file since we already evaluated it above.
666 (remove (file-truename (package--autoloads-file-name pkg-desc))
667 loaded-files-list)))))
668
669(defun package-activate-1 (pkg-desc &optional reload deps)
650 "Activate package given by PKG-DESC, even if it was already active. 670 "Activate package given by PKG-DESC, even if it was already active.
671If DEPS is non-nil, also activate its dependencies (unless they
672are already activated).
651If RELOAD is non-nil, also `load' any files inside the package which 673If RELOAD is non-nil, also `load' any files inside the package which
652correspond to previously loaded files (those returned by 674correspond to previously loaded files (those returned by
653`package--list-loaded-files')." 675`package--list-loaded-files')."
@@ -656,20 +678,15 @@ correspond to previously loaded files (those returned by
656 (unless pkg-dir 678 (unless pkg-dir
657 (error "Internal error: unable to find directory for `%s'" 679 (error "Internal error: unable to find directory for `%s'"
658 (package-desc-full-name pkg-desc))) 680 (package-desc-full-name pkg-desc)))
659 (let* ((loaded-files-list (when reload 681 ;; Activate its dependencies recursively.
660 (package--list-loaded-files pkg-dir)))) 682 ;; FIXME: This doesn't check whether the activated version is the
661 ;; Add to load path, add autoloads, and activate the package. 683 ;; required version.
662 (package--activate-autoloads-and-load-path pkg-desc) 684 (when deps
663 ;; Call `load' on all files in `pkg-dir' already present in 685 (dolist (req (package-desc-reqs pkg-desc))
664 ;; `load-history'. This is done so that macros in these files are updated 686 (unless (package-activate (car req))
665 ;; to their new definitions. If another package is being installed which 687 (error "Unable to activate package `%s'.\nRequired package `%s-%s' is unavailable"
666 ;; depends on this new definition, not doing this update would cause 688 name (car req) (package-version-join (cadr req))))))
667 ;; compilation errors and break the installation. 689 (package--load-files-for-activation pkg-desc reload)
668 (with-demoted-errors "Error in package-activate-1: %s"
669 (mapc (lambda (feature) (load feature nil t))
670 ;; Skip autoloads file since we already evaluated it above.
671 (remove (file-truename (package--autoloads-file-name pkg-desc))
672 loaded-files-list))))
673 ;; Add info node. 690 ;; Add info node.
674 (when (file-exists-p (expand-file-name "dir" pkg-dir)) 691 (when (file-exists-p (expand-file-name "dir" pkg-dir))
675 ;; FIXME: not the friendliest, but simple. 692 ;; FIXME: not the friendliest, but simple.
@@ -721,7 +738,7 @@ DIR, sorted by most recently loaded last."
721;; one was already activated. It also loads a features of this 738;; one was already activated. It also loads a features of this
722;; package which were already loaded. 739;; package which were already loaded.
723(defun package-activate (package &optional force) 740(defun package-activate (package &optional force)
724 "Activate package PACKAGE. 741 "Activate the package named PACKAGE.
725If FORCE is true, (re-)activate it if it's already activated. 742If FORCE is true, (re-)activate it if it's already activated.
726Newer versions are always activated, regardless of FORCE." 743Newer versions are always activated, regardless of FORCE."
727 (let ((pkg-descs (cdr (assq package package-alist)))) 744 (let ((pkg-descs (cdr (assq package package-alist))))
@@ -741,19 +758,7 @@ Newer versions are always activated, regardless of FORCE."
741 ((and (memq package package-activated-list) (not force)) 758 ((and (memq package package-activated-list) (not force))
742 t) 759 t)
743 ;; Otherwise, proceed with activation. 760 ;; Otherwise, proceed with activation.
744 (t 761 (t (package-activate-1 (car pkg-descs) nil 'deps)))))
745 (let* ((pkg-vec (car pkg-descs))
746 (fail (catch 'dep-failure
747 ;; Activate its dependencies recursively.
748 (dolist (req (package-desc-reqs pkg-vec))
749 (unless (package-activate (car req))
750 (throw 'dep-failure req))))))
751 (if fail
752 (warn "Unable to activate package `%s'.
753Required package `%s-%s' is unavailable"
754 package (car fail) (package-version-join (cadr fail)))
755 ;; If all goes well, activate the package itself.
756 (package-activate-1 pkg-vec force)))))))
757 762
758 763
759;;; Installation -- Local operations 764;;; Installation -- Local operations