Subject: bug#10125: 24.0.91; package.el (org): Macros in tar packages & order of byte compilation

From: Glenn Morris <[email-masked]>
Date: Thu, 24 Nov 2011 14:53:04 -0500

Glenn Morris wrote:

> fresh Emacs instance. There's no reason the "package manager" could not
> spawn a separate Emacs in batch-mode as a sub-job to do the compilation.

Very lightly tested version:

*** lisp/emacs-lisp/package.el	2011-11-20 03:48:53 +0000
--- lisp/emacs-lisp/package.el	2011-11-24 19:48:49 +0000
***************
*** 595,600 ****
--- 595,612 ----
  	(error "Package does not untar cleanly into directory %s/" dir))))
    (tar-untar-buffer))
  
+ (defun package-compile (directory)
+   "Compile the Lisp files in DIRECTORY."
+   (with-current-buffer (get-buffer-create "*package-compile*")
+     (goto-char (point-max))
+     (pop-to-buffer (current-buffer))
+     (or (zerop (call-process "emacs" nil t t "--batch" "--eval"
+ 			     (format
+ 			      "(progn (setq load-path (cons \"%s\" load-path))
+                                 (batch-byte-recompile-directory 0))" directory)
+ 			     directory))
+ 	(error "Compiling the package gave an error"))))
+ 
  (defun package-unpack (name version)
    (let* ((dirname (concat (symbol-name name) "-" version))
  	 (pkg-dir (expand-file-name dirname package-user-dir)))
***************
*** 603,610 ****
      (let* ((default-directory (file-name-as-directory package-user-dir)))
        (package-untar-buffer dirname)
        (package-generate-autoloads (symbol-name name) pkg-dir)
!       (let ((load-path (cons pkg-dir load-path)))
! 	(byte-recompile-directory pkg-dir 0 t)))))
  
  (defun package--write-file-no-coding (file-name)
    (let ((buffer-file-coding-system 'no-conversion))
--- 615,621 ----
      (let* ((default-directory (file-name-as-directory package-user-dir)))
        (package-untar-buffer dirname)
        (package-generate-autoloads (symbol-name name) pkg-dir)
!       (package-compile pkg-dir))))
  
  (defun package--write-file-no-coding (file-name)
    (let ((buffer-file-coding-system 'no-conversion))
***************
*** 645,652 ****
  	 pkg-file
  	 nil nil nil 'excl))
        (package-generate-autoloads file-name pkg-dir)
!       (let ((load-path (cons pkg-dir load-path)))
! 	(byte-recompile-directory pkg-dir 0 t)))))
  
  (defmacro package--with-work-buffer (location file &rest body)
    "Run BODY in a buffer containing the contents of FILE at LOCATION.
--- 656,662 ----
  	 pkg-file
  	 nil nil nil 'excl))
        (package-generate-autoloads file-name pkg-dir)
!       (package-compile pkg-dir))))
  
  (defmacro package--with-work-buffer (location file &rest body)
    "Run BODY in a buffer containing the contents of FILE at LOCATION.