]> code.delx.au - gnu-emacs/commitdiff
* lisp/emacs-lisp/package.el (package-unpack): Load before compiling
authorArtur Malabarba <bruce.connor.am@gmail.com>
Thu, 3 Dec 2015 15:24:51 +0000 (15:24 +0000)
committerArtur Malabarba <bruce.connor.am@gmail.com>
Thu, 3 Dec 2015 16:13:57 +0000 (16:13 +0000)
Reload any previously loaded package files before compiling
the package (also reload the same files after compiling).
This ensures that we have the most recent definitions during
compilation, and avoids generating bad elc files when a macro
changes and it is used in a different file from the one it's
defined in.

lisp/emacs-lisp/package.el
test/automated/data/package/macro-problem-package-1.0/macro-aux.el [new file with mode: 0644]
test/automated/data/package/macro-problem-package-1.0/macro-problem.el [new file with mode: 0644]
test/automated/data/package/macro-problem-package-2.0/macro-aux.el [new file with mode: 0644]
test/automated/data/package/macro-problem-package-2.0/macro-problem.el [new file with mode: 0644]
test/automated/package-test.el

index f94e7aaa741a91caa3b93458e8547bd3cfb7a94e..6b5a20249584ffabe6f4ff96dd9128f0cc0d40bc 100644 (file)
@@ -830,12 +830,17 @@ untar into a directory named DIR; otherwise, signal an error."
     ;; 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))
-    ;; Try to activate it.
-    (package-activate name 'force)
+      (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))
 
 (defun package-generate-description-file (pkg-desc pkg-file)
diff --git a/test/automated/data/package/macro-problem-package-1.0/macro-aux.el b/test/automated/data/package/macro-problem-package-1.0/macro-aux.el
new file mode 100644 (file)
index 0000000..9d14a21
--- /dev/null
@@ -0,0 +1,31 @@
+;;; macro-aux.el --- laksd                                  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2015  Artur Malabarba
+
+;; Author: Artur Malabarba <emacs@endlessparentheses.com>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(defun macro-aux-1 ( &rest forms)
+  "Description"
+  `(progn ,@forms))
+
+(provide 'macro-aux)
+;;; macro-aux.el ends here
diff --git a/test/automated/data/package/macro-problem-package-1.0/macro-problem.el b/test/automated/data/package/macro-problem-package-1.0/macro-problem.el
new file mode 100644 (file)
index 0000000..a44074c
--- /dev/null
@@ -0,0 +1,40 @@
+;;; macro-problem.el --- laksd                                  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2015  Artur Malabarba
+
+;; Author: Artur Malabarba <emacs@endlessparentheses.com>
+;; Keywords: tools
+;; Version: 1.0
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'macro-aux)
+
+(defmacro macro-problem-1 ( &rest forms)
+  "Description"
+  `(progn ,@forms))
+
+(defun macro-problem-func ()
+  ""
+  (macro-problem-1 'a 'b)
+  (macro-aux-1 'a 'b))
+
+(provide 'macro-problem)
+;;; macro-problem.el ends here
diff --git a/test/automated/data/package/macro-problem-package-2.0/macro-aux.el b/test/automated/data/package/macro-problem-package-2.0/macro-aux.el
new file mode 100644 (file)
index 0000000..4785cd7
--- /dev/null
@@ -0,0 +1,35 @@
+;;; macro-aux.el --- laksd                                  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2015  Artur Malabarba
+
+;; Author: Artur Malabarba <emacs@endlessparentheses.com>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(defmacro macro-aux-1 ( &rest forms)
+  "Description"
+  `(progn ,@forms))
+
+(defmacro macro-aux-3 ( &rest _)
+  "Description"
+  90)
+
+(provide 'macro-aux)
+;;; macro-aux.el ends here
diff --git a/test/automated/data/package/macro-problem-package-2.0/macro-problem.el b/test/automated/data/package/macro-problem-package-2.0/macro-problem.el
new file mode 100644 (file)
index 0000000..ead3d29
--- /dev/null
@@ -0,0 +1,49 @@
+;;; macro-problem.el --- laksd                                  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2015  Artur Malabarba
+
+;; Author: Artur Malabarba <emacs@endlessparentheses.com>
+;; Keywords: tools
+;; Version: 2.0
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'macro-aux)
+
+(defmacro macro-problem-1 ( &rest forms)
+  "Description"
+  `(progn ,(cadr (car forms))))
+
+
+(defun macro-problem-func ()
+  ""
+  (list (macro-problem-1 '1 'b)
+        (macro-aux-1 'a 'b)))
+
+(defmacro macro-problem-3 (&rest _)
+  "Description"
+  10)
+
+(defun macro-problem-10-and-90 ()
+  ""
+  (list (macro-problem-3 haha) (macro-aux-3 hehe)))
+
+(provide 'macro-problem)
+;;; macro-problem.el ends here
index de41c3bc8e417fc3bb7c7917edf1b28877483219..8401d1879aec4eddc2d232e8b2557a10b40e9e8f 100644 (file)
@@ -242,6 +242,20 @@ Must called from within a `tar-mode' buffer."
     (should (package-installed-p 'simple-single))
     (should (package-installed-p 'simple-depend))))
 
+(ert-deftest package-test-macro-compilation ()
+  "Install a package which includes a dependency."
+  (with-package-test (:basedir "data/package")
+    (package-install-file (expand-file-name "macro-problem-package-1.0/"))
+    (require 'macro-problem)
+    ;; `macro-problem-func' uses a macro from `macro-aux'.
+    (should (equal (macro-problem-func) '(progn a b)))
+    (package-install-file (expand-file-name "macro-problem-package-2.0/"))
+    ;; After upgrading, `macro-problem-func' depends on a new version
+    ;; of the macro from `macro-aux'.
+    (should (equal (macro-problem-func) '(1 b)))
+    ;; `macro-problem-10-and-90' depends on an entirely new macro from `macro-aux'.
+    (should (equal (macro-problem-10-and-90) '(10 90)))))
+
 (ert-deftest package-test-install-two-dependencies ()
   "Install a package which includes a dependency."
   (with-package-test ()