From: lynbech@daimi.aau.dk (Christian Lynbech)
Subject: Proposed change to byte-recompile-directory
Keywords: bytecomp byte-recompile-directory 
Organization: DAIMI: Computer Science Department, Aarhus University, Denmark
Date: Tue, 15 Dec 92 09:12:34 GMT

I would like to propose the following change to the function
byte-recompile-directory in lisp/bytecomp/bytecomp.el

In the current implementation, a recompilation is aborted whenever a file fails
to be compiled. An error is generated and the rest of the files in the
specified directories is discarded.

Instead, I will suggest, it should be possible to continue to compile the rest
of the files. I hit this problem when I was trying to recompile the lucid lisp
distribution from scratch. There are files which cannot (and some should not)
be compiled, for instance some epoch related files, and as I maintain the lucid
distribution under cvs, I do not by default store the .elc files, and I would
like to be able to use the cvs export facility.

Below my signature is a patch included, containing my own attempt of
implementing the above functionality. Note that this has not been extensively
tested.

I have labelled this version as 2.08a so it may be distinguished from the
official versions.


------------------------------------------------------------------------------
Christian Lynbech

DAIMI						office: R0.32   phone: 5034
University of Aarhus,DK-Denmark                 email: lynbech@daimi.aau.dk
------------------------------------------------------------------------------
			  EMACS, The One True Editor                       


Hit the philistines three times over the head with the Elisp reference manual.

                                        - petonic@hal.com (Michael A. Petonic)



===================================================================
RCS file: /users/src/LucidEmacs-19/REPOSITORY/LucidEmacs/lisp/bytecomp/bytecomp.el,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 bytecomp.el
*** 1.1.1.1	1992/09/30 13:53:02
--- bytecomp.el	1992/12/15 08:58:20
***************
*** 4,11 ****
  
  ;; By Jamie Zawinski <jwz@lucid.com> and Hallvard Furuseth <hbf@ulrik.uio.no>.
  
! (defconst byte-compile-version "2.08; 27-aug-92.")
  
  ;; This file is part of GNU Emacs.
  
  ;; GNU Emacs is free software; you can redistribute it and/or modify
--- 4,14 ----
  
  ;; By Jamie Zawinski <jwz@lucid.com> and Hallvard Furuseth <hbf@ulrik.uio.no>.
  
! ;; byte-recompile-directory enhanced by
! ;; Christian Lynbech <lynbech@daimi.aau.dk>
  
+ (defconst byte-compile-version "2.08a; 15-Dec-92.")
+ 
  ;; This file is part of GNU Emacs.
  
  ;; GNU Emacs is free software; you can redistribute it and/or modify
***************
*** 53,58 ****
--- 56,62 ----
  ;;;  + correct compilation of nested defuns, defmacros, defvars and defsubsts;
  ;;;  + correct compilation of top-level uses of macros;
  ;;;  + the ability to generate a histogram of functions called.
+ ;;;  + recompilation can continue even if some files fails
  
  ;;; User customization variables:
  ;;;
***************
*** 106,111 ****
--- 110,118 ----
  ;;;				see also the function byte-compile-dest-file.
  ;;; byte-compile-overwrite-file	If nil, delete old .elc files before saving.
  ;;;
+ ;;; byte-compile-recompile-continue     Determine what should happen when a
+ ;;;                             file fails compilation.
+ ;;;                             
  ;;; Most of the above parameters can also be set on a file-by-file basis; see
  ;;; the documentation of the `byte-compiler-options' macro.
  
***************
*** 162,167 ****
--- 169,179 ----
  ;;;  o  If you run byte-compile-file on a filename which is visited in a 
  ;;;     buffer, and that buffer is modified, you are asked whether you want
  ;;;     to save the buffer before compiling.
+ ;;;
+ ;;;  o  If you run byte-recompile-directory and a file fails compilation
+ ;;;     there are several options for handling this, including continuing.
+ ;;;     See variable byte-compile-recompile-continue for further information.
+ ;;;
  
  (or (fboundp 'defsubst)
      ;; This really ought to be loaded already!
***************
*** 325,330 ****
--- 337,350 ----
  is a symbolic link will be turned into a normal file, instead of the file
  which the link points to being overwritten.")
  
+ (defvar byte-compile-recompile-continue nil
+   "*If this variable is nil, recompilation is stopped with an error if any
+ file fails compilation.
+ If it is t, recompilation is just continued with the remaining files.
+ If not nil and not t, ask for confirmation before continuing.
+ If recompilation is continued, a note is made int the buffer
+ `*Recompile Log*', describing which file failed and what the error was.")
+ 
  (defvar byte-compile-constants nil
    "list of all constants encountered during compilation of this form")
  (defvar byte-compile-variables nil
***************
*** 1096,1107 ****
  If the `.elc' file does not exist, normally the `.el' file is *not* compiled.
  But a prefix argument (optional second arg) means ask user,
  for each such `.el' file, whether to compile it.  Prefix argument 0 means
! don't ask and compile the file anyway."
    (interactive "DByte recompile directory: \nP")
    (save-some-buffers)
    (set-buffer-modified-p (buffer-modified-p))  ;Update the mode line.
    (let ((directories (list (expand-file-name directory)))
  	(file-count 0)
  	(dir-count 0)
  	last-dir)
      (displaying-byte-compile-warnings
--- 1116,1133 ----
  If the `.elc' file does not exist, normally the `.el' file is *not* compiled.
  But a prefix argument (optional second arg) means ask user,
  for each such `.el' file, whether to compile it.  Prefix argument 0 means
! don't ask and compile the file anyway.
! 
! What should happen if a file fails compilation is determined by the variable
! byte-compile-recompile-continue. See this for a further explanation."
    (interactive "DByte recompile directory: \nP")
    (save-some-buffers)
    (set-buffer-modified-p (buffer-modified-p))  ;Update the mode line.
+   (and (get-buffer "*Recompile Log*")
+        (kill-buffer "*Recompile Log*"))	;remove old recompilation log
    (let ((directories (list (expand-file-name directory)))
  	(file-count 0)
+ 	(fail-count 0)
  	(dir-count 0)
  	last-dir)
      (displaying-byte-compile-warnings
***************
*** 1127,1134 ****
  			(and arg
  			     (or (eq 0 arg)
  				 (y-or-n-p (concat "Compile " source "? "))))))
! 		 (progn (byte-compile-file source)
! 			(setq file-count (1+ file-count))
  			(if (not (eq last-dir directory))
  			    (setq last-dir directory
  				  dir-count (1+ dir-count)))
--- 1153,1172 ----
  			(and arg
  			     (or (eq 0 arg)
  				 (y-or-n-p (concat "Compile " source "? "))))))
! 		 (progn (condition-case err
! 			    (progn (byte-compile-file source)
! 				   (setq file-count (1+ file-count)))
! 			  (error (if (or
! 				      (null byte-compile-recompile-continue)
! 				      (and (not (equal t byte-compile-recompile-continue))
! 					   (not (y-or-n-p "Continue recompilation? "))))
! 				     (error "Compilation error %s" (cdr err))
! 				   (setq fail-count (1+ fail-count))
! 				   (save-excursion
! 				     (set-buffer (get-buffer-create
! 						  "*Recompile Log*"))
! 				     (insert (format "** Error in file %s\n\t%s\n\n"
! 						     source err))))))
  			(if (not (eq last-dir directory))
  			    (setq last-dir directory
  				  dir-count (1+ dir-count)))
***************
*** 1135,1143 ****
  			)))
  	   (setq files (cdr files))))
         (setq directories (cdr directories))))
!     (message "Done (Total of %d file%s compiled%s)"
  	     file-count (if (= file-count 1) "" "s")
! 	     (if (> dir-count 1) (format " in %d directories" dir-count) ""))))
  
  (defun byte-compile-file (filename &optional load)
    "Compile a file of Lisp code named FILENAME into a file of byte code.
--- 1173,1188 ----
  			)))
  	   (setq files (cdr files))))
         (setq directories (cdr directories))))
!     (and (get-buffer "*Recompile Log*")
! 	 (display-buffer "*Recompile Log*"))
!     (message "Done (Total of %d file%s compiled%s%s)"
  	     file-count (if (= file-count 1) "" "s")
! 	     (if (> dir-count 1) (format " in %d directories" dir-count) "")
! 	     (if (> fail-count 0)
! 		 (format ". %d file%s failed compilation"
! 			 fail-count (if (> fail-count 1) "s" ""))
! 	       "")
!     )))
  
  (defun byte-compile-file (filename &optional load)
    "Compile a file of Lisp code named FILENAME into a file of byte code.