1 ;;; build-report.el --- Automatically formatted build reports for XEmacs
3 ;; Copyright (C) 1997-2001 Adrian Aichner
5 ;; Author: Adrian Aichner <adrian@xemacs.org>
8 ;; This file is part of XEmacs.
10 ;; XEmacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;;; Synched up with: Not synched.
30 ;; Let XEmacs report interesting aspects of how it was built.
33 ;; User creates an XEmacs Build Report by just calling
35 ;; which will initialize a mail buffer with relevant information
36 ;; derived from the XEmacs build process. Point is left at the
37 ;; beginning of the report for user to input some personal notes and
41 ;; This is the first `Proof of Concept'.
44 ;; Adrian Aichner, Teradyne GmbH Munich, Sun., Apr. 20, 1997.
51 (provide 'build-report)
53 ;;; Constant definitions used internally by `build-report'. These are not
54 ;;; anticipated to be changed by users of `build-report'.
55 ;;; If users do need to change the value of any of these, they need to do
56 ;;; it after `build-report' has been loaded (not just required). Please
57 ;;; report it to the maintainers of `build-report' when you think you
59 (defconst build-report-installation-version-regexp
60 "XEmacs\\s-+\\([0-9]+\\)\\.\\([0-9]+\\)\\(\\(-b\\|\\.\\)\\([0-9]+\\)\\)?\\s-+\\\\?\"\\([^\\\"]+\\)\\\\?\"\\s-+configured\\s-+for\\s-+`\\(.+\\)'\\."
61 "*REGEXP matching XEmacs Beta Version string in
62 `build-report-installation-file' file. This variable is used by
63 `build-report-installation-data'.")
65 (defconst build-report-version-file-regexp
66 "emacs_major_version\\s-*=\\s-*\\([0-9]+\\)
67 emacs_minor_version\\s-*=\\s-*\\([0-9]+\\)
68 emacs_beta_version\\s-*=\\s-*\\([0-9]+\\)?
69 xemacs_codename\\s-*=\\s-*\"\\([^\"]+\\)\""
70 "*REGEXP matching XEmacs Beta Version variable assignments in
71 `build-report-version-file' file. This variable is used by
72 `build-report-version-file-data'.")
74 (defconst build-report-installation-srcdir-regexp
75 "\\s-*Where should the build process find the source code\\?\\s-*\\(.*\\)$"
76 "REGEXP matching XEmacs Beta srcdir as the first substring match in
77 `build-report-installation-file' file. This variable is used by
78 `build-report-installation-data'.")
80 ;;; Customization support for build-report starts here.
82 (defgroup build-report nil
83 "Standardizes the Creation of XEmacs Build Reports."
87 (defcustom build-report-destination
89 "XEmacs Build Reports List <xemacs-buildreports@xemacs.org>"
90 "XEmacs Beta List <xemacs-beta@xemacs.org>")
91 "*The list of mail addresses XEmacs Build Reports should most likely
95 :documentation-shown t
99 (defcustom build-report-keep-regexp
101 "^\\(cd\\|n?make\\)\\s-"
104 "pure.*\\(space\\|size\\)"
108 "^Compil\\(ing\\s-+in\\|ation\\)"
111 "^While\\s-+compiling.*\\(\n\\s-+.+\\)*"
116 "*Regexp of make process output lines to keep in the report."
119 :documentation-shown t
121 :group 'build-report)
123 (defcustom build-report-delete-regexp
125 "confl.*with.*auto-inlining"
127 "(100%) tests successful")
128 "*Regexp of make process output lines to delete from the report."
131 :documentation-shown t
133 :group 'build-report)
135 (defcustom build-report-make-output-dir
137 ((equal system-type 'windows-nt)
138 (expand-file-name "nt"
139 (gethash 'blddir (config-value-hash-table))))
141 (gethash 'blddir (config-value-hash-table))))
142 "*Directory where the build report file is found.
143 If this is empty or nil, the default, it is replaced by the value of
144 the XEmacs build directory."
147 :documentation-shown t)
148 :group 'build-report)
150 (defcustom build-report-make-output-files
153 "xemacs-make-all.err"
154 "xemacs-make-check-temacs.err"
155 "xemacs-make-check.err"
156 "xemacs-make-install.err")
157 "*List of Filenames where stdout and stderr of XEmacs make process
158 have been stored. These are relative to
159 `build-report-make-output-dir`. You'll have to run make with output
160 redirection or use the `build' XEmacs package to save this output. You
161 may use following alias
163 alias mk 'make \!* >>&\! \!$.err &'
165 under csh, so that you get beta.err when you run `mk beta'."
168 :documentation-shown t
170 :group 'build-report)
172 (defcustom build-report-installation-file
173 (expand-file-name "Installation"
174 (gethash 'blddir (config-value-hash-table)))
175 "*Installation file produced by XEmacs configure process."
178 :documentation-shown t)
179 :group 'build-report)
181 (defcustom build-report-version-file
184 (gethash 'blddir (config-value-hash-table)))
185 "*version.sh file identifying XEmacs (Beta) Distribution."
188 :documentation-shown t)
189 :group 'build-report)
191 (defcustom build-report-installation-insert-all
193 "*Tell build-report to insert the whole Installation file
194 instead of just the last report."
196 :group 'build-report)
198 (defcustom build-report-subject
199 (concat "[%s] " emacs-version " on " system-configuration)
200 "*XEmacs Build Report Subject Line. %s-sequences will be substituted
201 with user input through `build-report' according to
202 `build-report-prompts' using `format'."
205 :documentation-shown t)
206 :group 'build-report)
208 (defcustom build-report-prompts
209 (quote (("Status?: " ("Success" "Failure"))))
210 "*XEmacs Build Report Prompt(s). This is a list of prompt-string
211 lists used by `build-report' in conjunction with
212 `build-report-subject'. Each list consists of a prompt string
213 followed by any number of strings which can be chosen via the history
217 :documentation-shown t
224 :group 'build-report)
226 (defcustom build-report-file-encoding
228 "*XEmacs Build Report File Encoding to be used when MIME support is
230 :group 'build-report)
232 ;; Symbol Name mappings from TM to SEMI serving as Compatibility
234 (when (featurep 'mime-setup)
235 ;; No (defvaralias ...) so far. Thanks to "Didier Verna"
236 ;; <didier@xemacs.org> for reporting my incorrect defvaraliasing of
237 ;; `mime-editor/insert-tag'.
238 ;; Thanks to Jens-Ulrik Holger Petersen
239 ;; <petersen@kurims.kyoto-u.ac.jp> for suggesting the conditional
240 ;; aliasing of SEMI functions.
241 (unless (fboundp 'mime-edit-content-beginning)
242 (defalias 'mime-edit-content-beginning 'mime-editor/content-beginning))
243 (unless (fboundp 'mime-edit-insert-tag)
244 (defalias 'mime-edit-insert-tag 'mime-editor/insert-tag))
245 (unless (fboundp 'mime-edit-insert-binary-file)
246 (defalias 'mime-edit-insert-binary-file
247 'mime-editor/insert-binary-file)))
249 (defun build-report-make-output-get ()
250 "Returns the filename the XEmacs make output is saved in."
252 (if (or (string-equal build-report-make-output-dir "")
253 (null build-report-make-output-dir))
259 (file-name-as-directory
260 (gethash 'blddir (config-value-hash-table))))))
261 build-report-make-output-files)
267 (file-name-as-directory build-report-make-output-dir))))
268 build-report-make-output-files)))
271 (defun build-report (&rest args)
272 "Report build information including Installation and make output.
274 Prompts for status (usually \"Success\" or \"Failure\"). Then uses
275 `compose-mail' to create a mail message. The Subject header contains
276 status and version information. Point is left at the beginning of the
277 mail text. Add some notes if you like, and send the report.
279 Looks for Installation and the make output file (`beta.err' by
280 default, customizable via `build-report-make-output-files') in the
281 build directory of the running XEmacs by default (customizable via
282 `build-report-make-output-dir'). The output from make is filtered
283 through `build-report-keep-regexp' and `build-report-delete-regexp'
284 before including in the message.
286 See also `mail-user-agent', `build-report-destination', and
287 `build-report-installation-file'."
288 ;; `interactive' form returns value for formal parameter `args'.
293 (prompts build-report-prompts))
297 (setq prompt (caar prompts))
298 (setq hist (cdar prompts))
299 ;; `build-report-prompts' used to be a list of lists, the
300 ;; first element of each list being the prompt, the rest being
301 ;; the history. The history is now in a separate list. We
302 ;; better check for that.
303 (if (listp (car hist))
304 (setq hist (car hist)))
305 (setq prompts (cdr prompts))
306 (setq arg (cons (read-string prompt "" 'hist) arg)))
309 (if (file-exists-p build-report-installation-file)
311 (major minor beta codename configuration)
312 (build-report-installation-data build-report-installation-file)
313 (setq build-report-subject
314 (format "[%%s] XEmacs %s.%s%s \"%s\", %s"
315 major minor beta codename configuration)))
317 (major minor beta codename)
318 (build-report-version-file-data build-report-version-file)
319 (setq build-report-subject
320 (format "[%%s] XEmacs %s.%s%s \"%s\", %s"
321 major minor beta codename system-configuration))))
323 ;; `build-report-destination' used to be a single string, so
324 ;; let's test if we really get a list of destinations.
325 (if (listp build-report-destination)
327 "Build Report Destination: "
328 (car build-report-destination)
329 'build-report-destination)
331 "Build Report Destination: "
332 build-report-destination)
334 (apply 'format build-report-subject args)
340 (let* ((report-begin (point))
341 (files (reverse (build-report-make-output-get)))
344 (if (file-exists-p file)
345 (insert (build-report-insert-make-output report-begin file))
346 (insert (format "%s not found!\n" file)))
348 (setq files (cdr files))
349 (setq file (car files)))
350 (if (file-exists-p build-report-installation-file)
351 (insert (build-report-insert-installation-file
353 build-report-installation-insert-all))
354 (insert (format "%s not found!\n" build-report-installation-file)))
355 ;;; (when (and (>= major 21) (>= minor 2) (or (null beta) (>= beta 32)))
357 ;;; (insert (build-report-insert-config-inc report-begin)))
359 (insert (build-report-insert-header report-begin))
360 (goto-char report-begin))))
362 (defun build-report-insert-header (where)
363 "Inserts the build-report-header at the point specified by `where'."
368 > XEmacs Build Report generated by emacs-version
370 > with system-configuration
372 > follows:\n\n" emacs-version system-configuration))
375 (defun build-report-insert-make-output (where file)
376 "Inserts the output of the XEmacs Beta make run in the
377 current buffer at position WHERE.
378 The make process output must have been saved in
379 `build-report-make-output-files' during the XEmacs Beta building."
382 (if (file-exists-p file)
384 (if (featurep 'mime-setup)
386 (mime-edit-insert-tag
390 "\nContent-Disposition: attachment;"
392 (file-name-nondirectory
395 (mime-edit-insert-binary-file
397 build-report-file-encoding))
398 (insert-file-contents file))
399 (when build-report-keep-regexp
400 (goto-char (point-min))
401 (delete-non-matching-lines (build-report-keep)))
402 (when build-report-delete-regexp
403 (goto-char (point-min))
404 (delete-matching-lines (build-report-delete)))
405 (goto-char (point-min))
406 (if build-report-keep-regexp
409 "> keeping lines matching
412 (build-report-keep))))
413 (if build-report-delete-regexp
416 "> %sdeleting lines matching
419 (if build-report-keep-regexp
422 (build-report-delete))))
424 (goto-char (point-min))
426 (format "> Contents of %s\n" file)))
428 " does not exist!\n\n"))
431 (defun build-report-insert-installation-file (where all)
432 "Inserts the contents of the `build-report-installation-file'
433 created by the XEmacs Beta configure process."
436 (if (file-exists-p build-report-installation-file)
437 (let (file-begin last-configure)
438 (insert "> Contents of "
439 build-report-installation-file
443 "> (Output from %s of ./configure)\n\n"
444 (if all "all runs" "most recent run")))
445 (if (featurep 'mime-setup)
447 (mime-edit-insert-tag
451 "\nContent-Disposition: attachment;"
453 (file-name-nondirectory
454 build-report-installation-file)
456 (mime-edit-insert-binary-file
457 build-report-installation-file
458 build-report-file-encoding)
459 (setq file-begin (mime-edit-content-beginning)))
460 (setq file-begin (point))
461 (insert-file-contents
462 build-report-installation-file))
465 (search-backward-regexp
466 "^\\(uname.*\\|osversion\\|OS\\):\\s-+" file-begin t))
467 (if (and file-begin last-configure)
468 (delete-region file-begin last-configure))))
469 (insert "> " build-report-installation-file
470 " does not exist!\n\n"))
473 (defun build-report-keep ()
474 "Concatenate elements of `build-report-keep-regexp' and a general
475 MIME tag REGEXP. The result is a REGEXP string matching either of the
476 REGEXPs in `build-report-keep-regexp' or a general MIME tag REGEXP."
477 (mapconcat #'identity
478 (cons "^--\\[\\[\\|\\]\\]$" build-report-keep-regexp) "\\|"))
480 (defun build-report-delete ()
481 "Concatenate elements of `build-report-delete-regexp' and a general
482 MIME tag REGEXP. The result is a REGEXP string matching either of the
483 REGEXPs in `build-report-delete-regexp' or a general MIME tag REGEXP."
484 (mapconcat '(lambda (item) item)
485 build-report-delete-regexp "\\|"))
487 (defun build-report-installation-data (&optional file)
488 "Return a list of XEmacs installation data containing MAJOR_NUMBER
489 MINOR_NUMBER BETA_STRING CODENAME CONFIGURATION SRCDIR from FILE,
490 which defaults to `build-report-installation-file'."
491 (interactive "fInstallation file: ")
493 (setq file build-report-installation-file))
495 (major minor beta codename configuration srcdir)
496 (save-window-excursion
497 (find-file-read-only file)
498 (goto-char (point-min))
499 (while (< (point) (point-max))
501 ((looking-at build-report-installation-version-regexp)
502 (goto-char (match-end 0))
503 (setq major (match-string 1))
504 (setq minor (match-string 2))
505 (setq beta (match-string 3))
506 (setq codename (match-string 6))
507 (setq configuration (match-string 7)))
508 ((looking-at build-report-installation-srcdir-regexp)
509 (goto-char (match-end 0))
510 (setq srcdir (match-string 1)))
511 ;; We avoid matching a potentially zero-length string to avoid
515 (goto-char (match-end 0)))
517 (goto-char (match-end 0)))))
518 (values major minor (or beta "") codename configuration srcdir))))
520 (defun build-report-version-file-data (&optional file)
521 "Return a list of XEmacs version information containing
522 MAJOR_NUMBER MINOR_NUMBER BETA_STRING CODENAME from FILE, which
523 defaults to `build-report-version-file'."
524 (interactive "fversion.sh file: ")
526 (setq file build-report-version-file))
528 (major minor beta codename)
529 (save-window-excursion
530 (find-file-read-only file)
531 (goto-char (point-min))
532 (while (< (point) (point-max))
534 ((looking-at build-report-version-file-regexp)
535 (goto-char (match-end 0))
536 (setq major (match-string 1))
537 (setq minor (match-string 2))
538 (setq beta (match-string 3))
539 (setq codename (match-string 4)))
540 ;; We avoid matching a potentially zero-length string to avoid
544 (goto-char (match-end 0)))
546 (goto-char (match-end 0)))))
547 (values major minor (or beta "") codename))))
549 ;;; build-report.el ends here