- (defun package-activate-1 (pkg-desc &optional reload deps)
- "Activate package given by PKG-DESC, even if it was already active.
-If DEPS is non-nil, also activate its dependencies (unless they
-are already activated).
-If RELOAD is non-nil, also `load' any files inside the package which
-correspond to previously loaded files (those returned by
-`package--list-loaded-files')."
- (let* ((name (package-desc-name pkg-desc))
- (pkg-dir (package-desc-dir pkg-desc)))
- (unless pkg-dir
- (error "Internal error: unable to find directory for `%s'"
- (package-desc-full-name pkg-desc)))
- ;; Activate its dependencies recursively.
- ;; FIXME: This doesn't check whether the activated version is the
- ;; required version.
- (when deps
- (dolist (req (package-desc-reqs pkg-desc))
- (unless (package-activate (car req))
- (error "Unable to activate package `%s'.\nRequired package `%s-%s' is unavailable"
- name (car req) (package-version-join (cadr req))))))
- (package--load-files-for-activation pkg-desc reload)
- ;; Add info node.
- (when (file-exists-p (expand-file-name "dir" pkg-dir))
- ;; FIXME: not the friendliest, but simple.
- (require 'info)
- (info-initialize)
- (push pkg-dir Info-directory-list))
- (push name package-activated-list)
- ;; Don't return nil.
- t))
-
- (defun package-activate (package &optional force)
- "Activate the package named PACKAGE.
-If FORCE is true, (re-)activate it if it's already activated.
-Newer versions are always activated, regardless of FORCE."
- (let ((pkg-descs (cdr (assq package package-alist))))
- ;; Check if PACKAGE is available in `package-alist'.
- (while
- (when pkg-descs
- (let ((available-version (package-desc-version (car pkg-descs))))
- (or (package-disabled-p package available-version)
- ;; Prefer a builtin package.
- (package-built-in-p package available-version))))
- (setq pkg-descs (cdr pkg-descs)))
- (cond
- ;; If no such package is found, maybe it's built-in.
- ((null pkg-descs)
- (package-built-in-p package))
- ;; If the package is already activated, just return t.
- ((and (memq package package-activated-list) (not force))
- t)
- ;; Otherwise, proceed with activation.
- (t (package-activate-1 (car pkg-descs) nil 'deps)))))
-
- (defun package-unpack (pkg-desc)
- "Install the contents of the current buffer as a package."
- (let* ((name (package-desc-name pkg-desc))
- (dirname (package-desc-full-name pkg-desc))
- (pkg-dir (expand-file-name dirname package-user-dir)))
- (pcase (package-desc-kind pkg-desc)
- (`dir
- (make-directory pkg-dir t)
- (let ((file-list
- (directory-files
- default-directory 'full "\\`[^.].*\\.el\\'" 'nosort)))
- (dolist (source-file file-list)
- (let ((target-el-file
- (expand-file-name (file-name-nondirectory source-file) pkg-dir)))
- (copy-file source-file target-el-file t)))
- ;; Now that the files have been installed, this package is
- ;; indistinguishable from a `tar' or a `single'. Let's make
- ;; things simple by ensuring we're one of them.
- (setf (package-desc-kind pkg-desc)
- (if (> (length file-list) 1) 'tar 'single))))
- (`tar
- (make-directory package-user-dir t)
- ;; FIXME: should we delete PKG-DIR if it exists?
- (let* ((default-directory (file-name-as-directory package-user-dir)))
- (package-untar-buffer dirname)))
- (`single
- (let ((el-file (expand-file-name (format "%s.el" name) pkg-dir)))
- (make-directory pkg-dir t)
- (package--write-file-no-coding el-file)))
- (kind (error "Unknown package kind: %S" kind)))
- (package--make-autoloads-and-stuff pkg-desc pkg-dir)
- ;; Update package-alist.
- (let ((new-desc (package-load-descriptor pkg-dir)))
- ;; FIXME: Check that `new-desc' matches `desc'!
- ;; Activation has to be done before compilation, so that if we're
- ;; upgrading and macros have changed we load the new definitions
- ;; before compiling.
- (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)
- ;; After compilation, load again any files loaded by
- ;; `activate-1', so that we use the byte-compiled definitions.
- (package--load-files-for-activation new-desc :reload))
- pkg-dir))
-
- )
+ \f
+;;; 24.1, 24.2, 24.3
+ (defadvice package--make-autoloads-and-compile (around fix-package--make-autoloads-and-compile
+ (name pkg-dir) activate)
+ "Fixed `package--make-autoloads-and-compile'.
+Behave the same as `package--make-autoloads-and-compile', except
+it uses `package-fixes--load-files-for-activation' instead of just
+loading the autoloads file."
+ (package-generate-autoloads name pkg-dir)
+ (package-fixes--load-files-for-activation pkg-desc :reload)
+ (let ((load-path (cons pkg-dir load-path)))
+ ;; We must load the autoloads file before byte compiling, in
+ ;; case there are magic cookies to set up non-trivial paths.
+ (byte-recompile-directory pkg-dir 0 t)))
+
+;;; 24.4, 24.5
+ (defadvice package--compile (after fix-package--compile (pkg-desc) activate)
+ "Like `package--compile', but reload package first.
+Uses `package-fixes--load-files-for-activation' to reload files."
+ (package-activate-1 pkg-desc)
+ (package-fixes--load-files-for-activation pkg-desc :reload)
+ (byte-recompile-directory (package-desc-dir pkg-desc) 0 t)))