From 0ce8e868b9c704f5f8630e0b8df5550ecadb0e95 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Sat, 28 Jan 2012 16:14:24 +0800 Subject: [PATCH] Fix package.el dependency handling so that `require' calls work. * lisp/emacs-lisp/package.el (package-maybe-load-descriptor): New function, split from package-maybe-load-descriptor. (package-maybe-load-descriptor): Use it. (package-download-transaction): Fully load required packages inside the loop, so that `require' calls work. (package-install): No need to call package-initialize now. Fixes: debbugs:10593 --- lisp/ChangeLog | 9 ++++++ lisp/emacs-lisp/package.el | 61 ++++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e94120f566e..887959d2fe0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2012-01-28 Chong Yidong + + * emacs-lisp/package.el (package-maybe-load-descriptor): New + function, split from package-maybe-load-descriptor. + (package-maybe-load-descriptor): Use it. + (package-download-transaction): Fully load required packages + inside the loop, so that `require' calls work (Bug#10593). + (package-install): No need to call package-initialize now. + 2012-01-28 Chong Yidong * tooltip.el (tooltip-mode): Doc fix. diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 881760216c3..7e56c5534ec 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -382,30 +382,37 @@ controls which package subdirectories may be loaded. In each valid package subdirectory, this function loads the description file containing a call to `define-package', which updates `package-alist' and `package-obsolete-alist'." - (let ((all (memq 'all package-load-list)) - (regexp (concat "\\`" package-subdirectory-regexp "\\'")) - name version force) + (let ((regexp (concat "\\`" package-subdirectory-regexp "\\'"))) (dolist (dir (cons package-user-dir package-directory-list)) (when (file-directory-p dir) (dolist (subdir (directory-files dir)) - (when (and (file-directory-p (expand-file-name subdir dir)) - (string-match regexp subdir)) - (setq name (intern (match-string 1 subdir)) - version (match-string 2 subdir) - force (assq name package-load-list)) - (when (cond - ((null force) - all) ; not in package-load-list - ((null (setq force (cadr force))) - nil) ; disabled - ((eq force t) - t) - ((stringp force) ; held - (version-list-= (version-to-list version) - (version-to-list force))) - (t - (error "Invalid element in `package-load-list'"))) - (package-load-descriptor dir subdir)))))))) + (when (string-match regexp subdir) + (package-maybe-load-descriptor (match-string 1 subdir) + (match-string 2 subdir) + dir))))))) + +(defun package-maybe-load-descriptor (name version dir) + "Maybe load a specific package from directory DIR. +NAME and VERSION are the package's name and version strings. +This function checks `package-load-list', before actually loading +the package by calling `package-load-descriptor'." + (let ((force (assq (intern name) package-load-list)) + (subdir (concat name "-" version))) + (and (file-directory-p (expand-file-name subdir dir)) + ;; Check `package-load-list': + (cond ((null force) + (memq 'all package-load-list)) + ((null (setq force (cadr force))) + nil) ; disabled + ((eq force t) + t) + ((stringp force) ; held + (version-list-= (version-to-list version) + (version-to-list force))) + (t + (error "Invalid element in `package-load-list'"))) + ;; Actually load the descriptor: + (package-load-descriptor dir subdir)))) (defsubst package-desc-vers (desc) "Extract version from a package description vector." @@ -861,7 +868,13 @@ using `package-compute-transaction'." (package-desc-doc desc) (package-desc-reqs desc))) (t - (error "Unknown package kind: %s" (symbol-name kind))))))) + (error "Unknown package kind: %s" (symbol-name kind)))) + ;; If package A depends on package B, then A may `require' B + ;; during byte compilation. So we need to activate B before + ;; unpacking A. + (package-maybe-load-descriptor (symbol-name elt) v-string + package-user-dir) + (package-activate elt (version-to-list v-string))))) (defvar package--initialized nil) @@ -889,9 +902,7 @@ archive in `package-archives'. Interactively, prompt for NAME." (symbol-name name))) (package-download-transaction (package-compute-transaction (list name) - (package-desc-reqs (cdr pkg-desc))))) - ;; Try to activate it. - (package-initialize)) + (package-desc-reqs (cdr pkg-desc)))))) (defun package-strip-rcs-id (str) "Strip RCS version ID from the version string STR. -- 2.39.2