1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 1998--2012 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
19 ;; Internationalisation: (_i "to be translated") gets an entry in the
20 ;; POT file; (gettext ...) must be invoked explicitly to do the actual
23 ;; (define-macro (_i x) x)
24 ;; (define-macro-public _i (x) x)
25 ;; (define-public-macro _i (x) x)
28 (defmacro-public _i (x) x)
30 ;;; Boolean thunk - are we integrating Guile V2.0 or higher with LilyPond?
31 (define-public (guile-v2)
32 (string>? (version) "1.9.10"))
34 (read-enable 'positions)
38 (debug-enable 'backtrace)
39 (debug-set! show-file-name #t)))
41 (define-public PLATFORM
44 (car (string-tokenize (utsname:sysname (uname)))))))
46 (define lilypond-declarations '())
48 (defmacro-public define-session (name value)
49 "This defines a variable @var{name} with the starting value
50 @var{value} that is reinitialized at the start of each session.
51 A@tie{}session basically corresponds to one LilyPond file on the
52 command line. The value is recorded at the start of the first session
53 after loading all initialization files and before loading the user
54 file and is reinstated for all of the following sessions. This
55 happens just by replacing the value, not by copying structures, so you
56 should not destructively modify them. For example, lists defined in
57 this manner should be changed within a session only be adding material
58 to their front or replacing them altogether, not by modifying parts of
59 them. It is an error to call @code{define-session} after the first
61 (define (add-session-variable name value)
62 (if (ly:undead? lilypond-declarations)
63 (ly:error (_ "define-session used after session start")))
64 (let ((var (make-variable value)))
65 (module-add! (current-module) name var)
66 (set! lilypond-declarations (cons var lilypond-declarations))))
67 `(,add-session-variable ',name ,value))
69 (defmacro-public define-session-public (name value)
70 "Like @code{define-session}, but also exports @var{name}."
72 (define-session ,name ,value)
75 (define (session-terminate)
76 (if (ly:undead? lilypond-declarations)
78 (lambda (p) (variable-set! (cadr p) (cddr p)))
79 (ly:get-undead lilypond-declarations))))
81 (define-public (session-initialize thunk)
82 "Initialize this session. The first session in a LilyPond run is
83 initialized by calling @var{thunk}, then recording the values of all
84 variables in the current module as well as those defined with
85 @code{define-session}. Subsequent calls of @code{session-initialize}
86 ignore @var{thunk} and instead just reinitialize all recorded
87 variables to their value after the initial call of @var{thunk}."
89 ;; We need to save the variables of the current module along with
90 ;; their values: functions defined in the module might refer to the
93 ;; The entries in lilypond-declarations consist of a cons* consisting
94 ;; of symbol, variable, and value. Variables defined with
95 ;; define-session have the symbol set to #f.
97 (if (ly:undead? lilypond-declarations)
103 (variable-set! var val)
105 (module-add! (current-module) (car p) var))))
106 (ly:get-undead lilypond-declarations)))
109 (let ((decl (map! (lambda (v)
110 (cons* #f v (variable-ref v)))
111 lilypond-declarations)))
114 (let ((val (variable-ref v)))
115 (if (not (ly:lily-parser? val))
121 (set! lilypond-declarations (ly:make-undead decl))))))
123 (define scheme-options-definitions
127 ;; - [subject-]object-object-verb +"ing"
128 ;; - [subject-]-verb-object-object
130 ;; Avoid overlong lines in `lilypond -dhelp'! Strings should not
131 ;; be longer than 48 characters per line.
134 "Render at higher resolution (using given factor)
135 and scale down result to prevent jaggies in
138 "Create .tex, .texi, .count files in the
141 "Select backend. Possible values: 'eps, 'null,
142 'ps, 'scm, 'socket, 'svg.")
143 (check-internal-types #f
144 "Check every property assignment for types.")
146 "Generate cut-out snippets of a score.")
148 "LilyPond prefix for data files (read-only).")
150 "Dump memory debugging statistics.")
151 (debug-gc-assert-parsed-dead #f
152 "For memory debugging: Ensure that all
153 references to parsed objects are dead. This is
154 an internal option, and is switched on
155 automatically for `-ddebug-gc'.")
157 "Debug the flex lexer.")
158 (debug-page-breaking-scoring #f
159 "Dump scores for many different page breaking
162 "Debug the bison parser.")
163 (debug-property-callbacks #f
164 "Debug cyclic callback chains.")
167 (delete-intermediate-files #t
168 "Delete unusable, intermediate PostScript files.")
170 "Dump memory and time information for each file.")
172 "Dump timing information (system-dependent).")
174 "Dump output signatures of each system. Used for
175 regression testing.")
177 "Pad left edge of the output EPS bounding box by
178 given amount (in mm).")
180 "Load fonts via Ghostscript.")
181 (gs-load-lily-fonts #f
182 "Load only LilyPond fonts via Ghostscript.")
184 "Run LilyPond from a GUI and redirect stderr to
188 (include-book-title-preview #t
189 "Include book titles in preview images.")
190 (include-eps-fonts #t
191 "Include fonts in separate-system EPS files.")
193 "Include file for global settings, included before the score is processed.")
195 "Process in parallel, using the given number of
198 "If string FOO is given as argument, redirect
199 output to log file `FOO.log'.")
200 (max-markup-depth 1024
201 "Maximum depth for the markup tree. If a markup has more levels,
202 assume it will not terminate on its own, print a warning and return a
203 null markup instead.")
204 (midi-extension ,(if (eq? PLATFORM 'windows)
207 "Set the default file extension for MIDI output
208 file to given string.")
209 (music-strings-to-paths #f
210 "Convert text strings to paths when glyphs belong
213 "Make \\relative mode for simultaneous music work
214 similar to chord syntax.")
216 "Add point & click links to PDF output.")
218 "Set default paper size.")
219 (pixmap-format "png16m"
220 "Set GhostScript's output format for pixel images.")
222 "Create preview images also.")
224 "Print pages in the normal way.")
225 (protected-scheme-parsing #t
226 "Continue when errors in inline scheme are caught
227 in the parser. If #f, halt on errors and print
229 (profile-property-accesses #f
230 "Keep statistics of get_property() calls.")
232 "Set resolution for generating PNG pixmaps to
233 given value (in dpi).")
235 "Specify name of a file which contains a list of
236 input files to be processed.")
237 (relative-includes #f
238 "When processing an \\include command, look for
239 the included file relative to the current file
240 (instead of the root file)")
242 "Run in safer mode.")
243 (separate-log-files #f
244 "For input files `FILE1.ly', `FILE2.ly', ...
245 output log data to files `FILE1.log',
247 (show-available-fonts #f
248 "List available font names.")
249 (strict-infinity-checking #f
250 "Force a crash on encountering Inf and NaN
251 floating point exceptions.")
253 "Don't use directories from input files while
254 constructing output file names.")
256 "Use woff font files in SVG backend.")
257 (trace-memory-frequency #f
258 "Record Scheme cell usage this many times per
259 second. Dump results to `FILE.stacks' and
261 (trace-scheme-coverage #f
262 "Record coverage of Scheme files in `FILE.cov'.")
263 (verbose ,(ly:verbose-output?)
264 "Verbose output, i.e. loglevel at least DEBUG (read-only).")
266 "Change all warning and programming_error
267 messages into errors.")
270 ;; Need to do this in the beginning. Other parts of the Scheme
271 ;; initialization depend on these options.
273 (for-each (lambda (x)
274 (ly:add-option (car x) (cadr x) (caddr x)))
275 scheme-options-definitions)
277 (for-each (lambda (x)
278 (ly:set-option (car x) (cdr x)))
279 (eval-string (ly:command-line-options)))
283 (if (defined? 'set-debug-cell-accesses!)
284 (set-debug-cell-accesses! #f))
286 ;;(set-debug-cell-accesses! 1000)
288 (use-modules (ice-9 regex)
300 (scm safe-utility-defs))
302 (define-public _ gettext)
303 ;;; There are new modules defined in Guile V2.0 which we need to use.
305 ;; Modules and scheme files loaded by lily.scm use currying
306 ;; in Guile V2 this needs a module which is not present in Guile V1.8
311 (ly:debug (_ "Using (ice-9 curried-definitions) module\n"))
312 (use-modules (ice-9 curried-definitions)))
314 (ly:debug (_ "Guile 1.8\n"))))
316 ;; TODO add in modules for V1.8.7 deprecated in V2.0 and integrated
317 ;; into Guile base code, like (ice-9 syncase).
320 (define-public fancy-format
323 (define-public (ergonomic-simple-format dest . rest)
324 "Like ice-9's @code{format}, but without the memory consumption."
326 (apply simple-format (cons #f (cons dest rest)))
327 (apply simple-format (cons dest rest))))
330 ergonomic-simple-format)
333 (define-public (myd k v)
340 (define-public (print . args)
341 (apply format (cons (current-output-port) args)))
344 ;;; General settings.
346 ;;; Debugging evaluator is slower. This should have a more sensible
350 (if (or (ly:get-option 'verbose)
351 (ly:get-option 'trace-memory-frequency)
352 (ly:get-option 'trace-scheme-coverage))
354 (ly:set-option 'protected-scheme-parsing #f)
355 (debug-enable 'backtrace)
356 (read-enable 'positions)))
358 (if (ly:get-option 'trace-scheme-coverage)
361 (define-public parser #f)
363 (define music-string-to-path-backends
366 (if (memq (ly:get-option 'backend) music-string-to-path-backends)
367 (ly:set-option 'music-strings-to-paths #t))
369 (define-public (ly:load x)
370 (let* ((file-name (%search-load-path x)))
371 (ly:debug "[~A" file-name)
373 (ly:error (_ "cannot find: ~A") x))
374 (primitive-load-path file-name) ;; to support Guile V2 autocompile
375 ;; TODO: Any chance to use ly:debug here? Need to extend it to prevent
376 ;; a newline in this case
377 (if (ly:get-option 'verbose)
378 (ly:progress "]\n"))))
381 (let ((platform (string-tokenize
382 (vector-ref (uname) 0) char-set:letter+digit)))
383 (if (null? (cdr platform)) #f
384 (member (string-downcase (cadr platform)) '("95" "98" "me")))))
387 (if (string-index x #\\)
389 (string-regexp-substitute
391 (string-regexp-substitute "\\\\" "/" x))))
393 (define-public (ly-getcwd)
394 (if (eq? PLATFORM 'windows)
398 (define-public (is-absolute? file-name)
399 (let ((file-name-length (string-length file-name)))
400 (if (= file-name-length 0)
402 (or (eq? (string-ref file-name 0) #\/)
403 (and (eq? PLATFORM 'windows)
404 (> file-name-length 2)
405 (eq? (string-ref file-name 1) #\:)
406 (eq? (string-ref file-name 2) #\/))))))
408 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
409 ;;; If necessary, emulate Guile V2 module_export_all! for Guile V1.8.n
412 (define (module-export-all! mod)
413 (define (fresh-interface!)
414 (let ((iface (make-module)))
415 (set-module-name! iface (module-name mod))
416 ;; for guile 2: (set-module-version! iface (module-version mod))
417 (set-module-kind! iface 'interface)
418 (set-module-public-interface! mod iface)
420 (let ((iface (or (module-public-interface mod)
421 (fresh-interface!))))
422 (set-module-obarray! iface (module-obarray mod))))))
425 (define-safe-public (lilypond-version)
427 (map (lambda (x) (if (symbol? x)
433 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
436 (ly:set-default-scale (ly:make-scale #(0 1 2 5/2 7/2 9/2 11/2)))
438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
442 ;; List of Scheme files to be loaded into the (lily) module.
444 ;; - Library definitions, need to be at the head of the list
445 (define init-scheme-files-lib
448 ;; - Files containing definitions used later by other files later in load
449 (define init-scheme-files-used
450 '("markup-macros.scm"
451 "parser-ly-from-scheme.scm"))
452 ;; - Main body of files to be loaded
453 (define init-scheme-files-body
455 "define-event-classes.scm"
456 "define-music-callbacks.scm"
457 "define-music-types.scm"
458 "define-note-names.scm"
462 "define-markup-commands.scm"
464 "modal-transforms.scm"
465 "chord-generic-names.scm"
466 "chord-ignatzek-names.scm"
467 "music-functions.scm"
470 "define-music-properties.scm"
471 "time-signature-settings.scm"
475 "ly-syntax-constructors.scm"
477 "define-context-properties.scm"
478 "translation-functions.scm"
492 "define-woodwind-diagrams.scm"
493 "display-woodwind-diagrams.scm"
494 "predefined-fretboards.scm"
495 "define-grob-properties.scm"
497 "define-grob-interfaces.scm"
498 "define-stencil-commands.scm"
499 "scheme-engravers.scm"
504 "backend-library.scm"
506 ;; - Files to be loaded last
507 (define init-scheme-files-tail
508 ;; - must be after everything has been defined
511 ;; Now construct the load list
513 (define init-scheme-files
514 (append init-scheme-files-lib
515 init-scheme-files-used
516 init-scheme-files-body
517 init-scheme-files-tail))
519 (for-each ly:load init-scheme-files)
521 (define-public r5rs-primary-predicates
522 `((,boolean? . "boolean")
523 (,char? . "character")
524 (,number? . "number")
527 (,procedure? . "procedure")
528 (,string? . "string")
529 (,symbol? . "symbol")
530 (,vector? . "vector")))
532 (define-public r5rs-secondary-predicates
533 `((,char-alphabetic? . "alphabetic character")
534 (,char-lower-case? . "lower-case character")
535 (,char-numeric? . "numeric character")
536 (,char-upper-case? . "upper-case character")
537 (,char-whitespace? . "whitespace character")
539 (,complex? . "complex number")
540 (,even? . "even number")
541 (,exact? . "exact number")
542 (,inexact? . "inexact number")
543 (,integer? . "integer")
544 (,negative? . "negative number")
545 (,odd? . "odd number")
546 (,positive? . "positive number")
547 (,rational? . "rational number")
548 (,real? . "real number")
554 (,input-port? . "input port")
555 (,output-port? . "output port")
557 ;; would this ever be used?
558 (,eof-object? . "end-of-file object")
561 (define-public guile-predicates
562 `((,hash-table? . "hash table")
565 (define-public lilypond-scheme-predicates
566 `((,boolean-or-symbol? . "boolean or symbol")
568 (,cheap-list? . "list")
569 (,fraction? . "fraction, as pair")
570 (,grob-list? . "list of grobs")
571 (,index? . "non-negative integer")
572 (,markup? . "markup")
573 (,markup-command-list? . "markup command list")
574 (,markup-list? . "markup list")
575 (,moment-pair? . "pair of moment objects")
576 (,number-list? . "number list")
577 (,number-or-grob? . "number or grob")
578 (,number-or-pair? . "number or pair")
579 (,number-or-string? . "number or string")
580 (,number-pair? . "pair of numbers")
581 (,rhythmic-location? . "rhythmic location")
582 (,scheme? . "any type")
583 (,string-or-pair? . "string or pair")
584 (,string-or-music? . "string or music")
585 (,string-or-symbol? . "string or symbol")
586 (,symbol-list? . "symbol list")
587 (,symbol-list-or-music? . "symbol list or music")
588 (,symbol-list-or-symbol? . "symbol list or symbol")
592 (define-public lilypond-exported-predicates
593 `((,ly:book? . "book")
595 (,ly:context? . "context")
596 (,ly:context-def? . "context definition")
597 (,ly:context-mod? . "context modification")
598 (,ly:dimension? . "dimension, in staff space")
599 (,ly:dir? . "direction")
600 (,ly:dispatcher? . "dispatcher")
601 (,ly:duration? . "duration")
602 (,ly:event? . "post event")
603 (,ly:font-metric? . "font metric")
604 (,ly:grob? . "graphical (layout) object")
605 (,ly:grob-array? . "array of grobs")
606 (,ly:input-location? . "input location")
608 (,ly:iterator? . "iterator")
609 (,ly:lily-lexer? . "lily-lexer")
610 (,ly:lily-parser? . "lily-parser")
611 (,ly:listener? . "listener")
612 (,ly:moment? . "moment")
613 (,ly:music? . "music")
614 (,ly:music-function? . "music function")
615 (,ly:music-list? . "list of music objects")
616 (,ly:music-output? . "music output")
617 (,ly:otf-font? . "OpenType font")
618 (,ly:output-def? . "output definition")
619 (,ly:page-marker? . "page marker")
620 (,ly:pango-font? . "pango font")
621 (,ly:paper-book? . "paper book")
622 (,ly:paper-system? . "paper-system Prob")
623 (,ly:pitch? . "pitch")
624 (,ly:prob? . "property object")
625 (,ly:score? . "score")
626 (,ly:simple-closure? . "simple closure")
627 (,ly:skyline? . "skyline")
628 (,ly:skyline-pair? . "pair of skylines")
629 (,ly:source-file? . "source file")
630 (,ly:spanner? . "spanner")
631 (,ly:spring? . "spring")
632 (,ly:stencil? . "stencil")
633 (,ly:stream-event? . "stream event")
634 (,ly:translator? . "translator")
635 (,ly:translator-group? . "translator group")
636 (,ly:unpure-pure-container? . "unpure/pure container")
640 (set! type-p-name-alist
641 (append r5rs-primary-predicates
642 r5rs-secondary-predicates
644 lilypond-scheme-predicates
645 lilypond-exported-predicates))
648 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
651 (define (profile-measurements)
654 (list (- (+ (tms:cutime t)
656 (assoc-get 'gc-time-taken stats))
657 (assoc-get 'total-cells-allocated stats 0))))
659 (define (dump-profile base last this)
660 (let* ((outname (format #f "~a.profile" (dir-basename base ".ly")))
661 (diff (map (lambda (y) (apply - y)) (zip this last))))
662 (ly:progress "\nWriting timing to ~a..." outname)
663 (format (open-file outname "w")
664 "time: ~a\ncells: ~a\n"
665 (if (ly:get-option 'dump-cpu-profile)
670 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
671 ;; debug memory leaks
676 (define gc-protect-stat-count
679 ;; Undead objects that should be ignored after the first time round
681 (make-weak-key-hash-table 0))
683 (define-public (dump-live-object-stats outfile)
684 (for-each (lambda (x)
685 (format outfile "~a: ~a\n" (car x) (cdr x)))
686 (sort (gc-live-object-stats)
688 (string<? (car x) (car y))))))
690 (define-public (dump-gc-protects)
691 (set! gc-protect-stat-count (1+ gc-protect-stat-count))
692 (let* ((protects (sort (hash-table->alist (ly:protects))
694 (< (object-address (car a))
695 (object-address (car b))))))
696 (out-file-name (string-append
697 "gcstat-" (number->string gc-protect-stat-count)
699 (outfile (open-file out-file-name "w")))
701 (ly:progress "Dumping GC statistics ~a...\n" out-file-name)
702 (for-each (lambda (y)
705 (format outfile "~a (~a) = ~a\n" (object-address x) c x)))
708 (not (symbol? (car x))))
710 (format outfile "\nprotected symbols: ~a\n"
711 (apply + (map (lambda (obj-count)
712 (if (symbol? (car obj-count))
717 ;; (display (ly:smob-protects))
719 (if (defined? 'gc-live-object-stats)
721 (ly:progress "Live object statistics: GC'ing\n")
725 (ly:progress "Asserting dead objects\n")
726 (ly:set-option 'debug-gc-assert-parsed-dead #t)
728 (ly:set-option 'debug-gc-assert-parsed-dead #f)
731 (if (not (hashq-ref gc-zombies x))
733 (ly:programming-error "Parsed object should be dead: ~a" x)
734 (hashq-set! gc-zombies x #t))))
735 (ly:parsed-undead-list!))
736 (set! stats (gc-live-object-stats))
737 (ly:progress "Dumping live object statistics.\n")
738 (dump-live-object-stats outfile)))
740 (let* ((stats (gc-stats)))
741 (for-each (lambda (sym)
742 (format outfile "~a ~a ~a\n"
743 gc-protect-stat-count
745 (assoc-get sym stats "?")))
746 '(protected-objects bytes-malloced cell-heap-size)))
748 (close-port outfile)))
750 (define (check-memory)
751 "Read `/proc/self' to check up on memory use."
752 (define (gulp-file name)
753 (let* ((file (open-input-file name))
754 (text (read-delimited "" file)))
758 (let* ((stat (gulp-file "/proc/self/status"))
759 (lines (string-split stat #\newline))
760 (interesting (filter identity
763 (string-match "^VmData:[ \t]*([0-9]*) kB" l))
765 (mem (string->number (match:substring (car interesting) 1))))
766 (format #t "VMDATA: ~a\n" mem)
770 (begin (dump-gc-protects)
773 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
775 (define (multi-fork count)
776 "Split this process into COUNT helpers. Returns either a list of
777 PIDs or the number of the process."
778 (define (helper count acc)
780 (let* ((pid (primitive-fork)))
783 (helper (1- count) (cons pid acc))))
788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
790 (define* (ly:exit status #:optional (silently #f))
791 "Exit function for lilypond"
794 ((0) (ly:basic-progress (_ "Success: compilation successfully completed")))
795 ((1) (ly:warning (_ "Compilation completed with warnings or errors")))
796 (else (ly:message ""))))
799 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
801 (define-public (lilypond-main files)
802 "Entry point for LilyPond."
803 (eval-string (ly:command-line-code))
804 (if (ly:get-option 'help)
805 (begin (ly:option-usage)
807 (if (ly:get-option 'show-available-fonts)
808 (begin (ly:font-config-display-fonts)
810 (if (ly:get-option 'gui)
815 (if (ly:get-option 'read-file-list)
818 (> (string-length s) 0))
821 (string-split (string-delete (ly:gulp-file f) #\cr) #\nl))
823 (if (and (number? (ly:get-option 'job-count))
824 (>= (length files) (ly:get-option 'job-count)))
825 (let* ((count (ly:get-option 'job-count))
826 (split-todo (split-list files count))
827 (joblist (multi-fork count))
829 (if (not (string-or-symbol? (ly:get-option 'log-file)))
830 (ly:set-option 'log-file "lilypond-multi-run"))
831 (if (number? joblist)
832 (begin (ly:set-option
833 'log-file (format #f "~a-~a"
834 (ly:get-option 'log-file) joblist))
835 (set! files (vector-ref split-todo joblist)))
836 (begin (ly:progress "\nForking into jobs: ~a\n" joblist)
839 (let* ((stat (cdr (waitpid pid))))
842 (acons (list-element-index joblist pid)
849 (logfile (format #f "~a-~a.log"
850 (ly:get-option 'log-file) job))
851 (log (ly:gulp-file logfile))
852 (len (string-length log))
853 (tail (substring log (max 0 (- len 1024)))))
854 (if (status:term-sig state)
857 (format #f (_ "job ~a terminated with signal: ~a")
858 job (status:term-sig state)))
860 (_ "logfile ~a (exit ~a):\n~a")
861 logfile (status:exit-val state) tail))))
864 (ly:error "Children ~a exited with errors."
866 ;; must overwrite individual entries
867 (if (ly:get-option 'dump-profile)
868 (dump-profile "lily-run-total"
869 '(0 0) (profile-measurements)))
874 (if (string-or-symbol? (ly:get-option 'log-file))
875 (ly:stderr-redirect (format #f "~a.log" (ly:get-option 'log-file)) "w"))
876 (let ((failed (lilypond-all files)))
877 (if (ly:get-option 'trace-scheme-coverage)
879 (coverage:show-all (lambda (f)
880 (string-contains f "lilypond")))))
882 (begin (ly:error (_ "failed files: ~S") (string-join failed))
888 (define-public (lilypond-all files)
890 (separate-logs (ly:get-option 'separate-log-files))
893 (if (string-or-symbol? (ly:get-option 'log-file))
894 (open-file (format #f "~a.log" (ly:get-option 'log-file))
897 (do-measurements (ly:get-option 'dump-profile))
898 (handler (lambda (key failed-file)
899 (set! failed (append (list failed-file) failed)))))
903 (let* ((start-measurements (if do-measurements
904 (profile-measurements)
906 (base (dir-basename x ".ly"))
907 (all-settings (ly:all-options)))
909 (ly:stderr-redirect (format #f "~a.log" base) "w"))
911 (format ping-log "Processing ~a\n" base))
912 (if (ly:get-option 'trace-memory-frequency)
913 (mtrace:start-trace (ly:get-option 'trace-memory-frequency)))
914 (lilypond-file handler x)
915 (ly:check-expected-warnings)
917 (if start-measurements
918 (dump-profile x start-measurements (profile-measurements)))
919 (if (ly:get-option 'trace-memory-frequency)
920 (begin (mtrace:stop-trace)
921 (mtrace:dump-results base)))
922 (for-each (lambda (s)
923 (ly:set-option (car s) (cdr s)))
925 (ly:set-option 'debug-gc-assert-parsed-dead #t)
927 (ly:set-option 'debug-gc-assert-parsed-dead #f)
930 (if (not (hashq-ref gc-zombies x))
932 (ly:programming-error "Parsed object should be dead: ~a" x)
933 (hashq-set! gc-zombies x #t))))
934 (ly:parsed-undead-list!))
935 (if (ly:get-option 'debug-gc)
937 (ly:reset-all-fonts))
941 ;; Ensure a notice re failed files is written to aggregate logfile.
943 (format ping-log "Failed files: ~a\n" failed))
944 (if (ly:get-option 'dump-profile)
945 (dump-profile "lily-run-total" '(0 0) (profile-measurements)))
948 (define (lilypond-file handler file-name)
949 (catch 'ly-file-failed
950 (lambda () (ly:parse-file file-name))
951 (lambda (x . args) (handler x file-name))))
953 (use-modules (scm editor))
955 (define-public (gui-main files)
957 (gui-no-files-handler))
958 (if (not (string? (ly:get-option 'log-file)))
959 (let* ((base (dir-basename (car files) ".ly"))
960 (log-name (string-append base ".log")))
961 (if (not (ly:get-option 'gui))
962 (ly:message (_ "Redirecting output to ~a...") log-name))
963 (ly:stderr-redirect log-name "w")
964 (ly:message "# -*-compilation-*-"))
965 (let ((failed (lilypond-all files)))
969 (ly:stderr-redirect "foo" "r")
970 (system (get-editor-command log-name 0 0 0))
971 (ly:error (_ "failed files: ~S") (string-join failed))
976 (define (gui-no-files-handler)
977 (let* ((ly (string-append (ly:effective-prefix) "/ly/"))
978 ;; FIXME: soft-code, localize
979 (welcome-ly (string-append ly "Welcome_to_LilyPond.ly"))
980 (cmd (get-editor-command welcome-ly 0 0 0)))
981 (ly:message (_ "Invoking `~a'...\n") cmd)