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 lilypond-interfaces #f)
83 (define-public (session-initialize thunk)
84 "Initialize this session. The first session in a LilyPond run is
85 initialized by calling @var{thunk}, then recording the values of all
86 variables in the current module as well as those defined with
87 @code{define-session}. Subsequent calls of @code{session-initialize}
88 ignore @var{thunk} and instead just reinitialize all recorded
89 variables to their value after the initial call of @var{thunk}."
91 ;; We need to save the variables of the current module along with
92 ;; their values: functions defined in the module might refer to the
95 ;; The entries in lilypond-declarations consist of a cons* consisting
96 ;; of symbol, variable, and value. Variables defined with
97 ;; define-session have the symbol set to #f.
99 (if (ly:undead? lilypond-declarations)
101 (module-use-interfaces! (current-module) (reverse lilypond-interfaces))
106 (variable-set! var val)
108 (module-add! (current-module) (car p) var))))
109 (ly:get-undead lilypond-declarations)))
112 (set! lilypond-interfaces
113 (filter (lambda (m) (eq? 'interface (module-kind m)))
114 (module-uses (current-module))))
115 (let ((decl (map! (lambda (v)
116 (cons* #f v (variable-ref v)))
117 lilypond-declarations)))
120 (let ((val (variable-ref v)))
121 (if (not (ly:lily-parser? val))
127 (set! lilypond-declarations (ly:make-undead decl))))))
129 (define scheme-options-definitions
133 ;; - [subject-]object-object-verb +"ing"
134 ;; - [subject-]-verb-object-object
136 ;; Avoid overlong lines in `lilypond -dhelp'! Strings should not
137 ;; be longer than 48 characters per line.
140 "Render at higher resolution (using given factor)
141 and scale down result to prevent jaggies in
144 "Create .tex, .texi, .count files in the
147 "Select backend. Possible values: 'eps, 'null,
148 'ps, 'scm, 'socket, 'svg.")
149 (check-internal-types #f
150 "Check every property assignment for types.")
152 "Generate cut-out snippets of a score.")
154 "LilyPond prefix for data files (read-only).")
156 "Dump memory debugging statistics.")
157 (debug-gc-assert-parsed-dead #f
158 "For memory debugging: Ensure that all
159 references to parsed objects are dead. This is
160 an internal option, and is switched on
161 automatically for `-ddebug-gc'.")
163 "Debug the flex lexer.")
164 (debug-page-breaking-scoring #f
165 "Dump scores for many different page breaking
168 "Debug the bison parser.")
169 (debug-property-callbacks #f
170 "Debug cyclic callback chains.")
173 (delete-intermediate-files #t
174 "Delete unusable, intermediate PostScript files.")
176 "Dump memory and time information for each file.")
178 "Dump timing information (system-dependent).")
180 "Dump output signatures of each system. Used for
181 regression testing.")
183 "Pad left edge of the output EPS bounding box by
184 given amount (in mm).")
186 "Load fonts via Ghostscript.")
187 (gs-load-lily-fonts #f
188 "Load only LilyPond fonts via Ghostscript.")
190 "Run LilyPond from a GUI and redirect stderr to
194 (include-book-title-preview #t
195 "Include book titles in preview images.")
196 (include-eps-fonts #t
197 "Include fonts in separate-system EPS files.")
199 "Include file for global settings, included before the score is processed.")
201 "Process in parallel, using the given number of
204 "If string FOO is given as argument, redirect
205 output to log file `FOO.log'.")
206 (max-markup-depth 1024
207 "Maximum depth for the markup tree. If a markup has more levels,
208 assume it will not terminate on its own, print a warning and return a
209 null markup instead.")
210 (midi-extension ,(if (eq? PLATFORM 'windows)
213 "Set the default file extension for MIDI output
214 file to given string.")
215 (music-strings-to-paths #f
216 "Convert text strings to paths when glyphs belong
219 "Add point & click links to PDF output.")
221 "Set default paper size.")
222 (pixmap-format "png16m"
223 "Set GhostScript's output format for pixel images.")
225 "Create preview images also.")
227 "Print pages in the normal way.")
228 (protected-scheme-parsing #t
229 "Continue when errors in inline scheme are caught
230 in the parser. If #f, halt on errors and print
232 (profile-property-accesses #f
233 "Keep statistics of get_property() calls.")
235 "Set resolution for generating PNG pixmaps to
236 given value (in dpi).")
238 "Specify name of a file which contains a list of
239 input files to be processed.")
240 (relative-includes #f
241 "When processing an \\include command, look for
242 the included file relative to the current file
243 (instead of the root file)")
245 "Run in safer mode.")
246 (separate-log-files #f
247 "For input files `FILE1.ly', `FILE2.ly', ...
248 output log data to files `FILE1.log',
250 (show-available-fonts #f
251 "List available font names.")
252 (strict-infinity-checking #f
253 "Force a crash on encountering Inf and NaN
254 floating point exceptions.")
256 "Don't use directories from input files while
257 constructing output file names.")
259 "Use woff font files in SVG backend.")
260 (trace-memory-frequency #f
261 "Record Scheme cell usage this many times per
262 second. Dump results to `FILE.stacks' and
264 (trace-scheme-coverage #f
265 "Record coverage of Scheme files in `FILE.cov'.")
266 (verbose ,(ly:verbose-output?)
267 "Verbose output, i.e. loglevel at least DEBUG (read-only).")
269 "Change all warning and programming_error
270 messages into errors.")
273 ;; Need to do this in the beginning. Other parts of the Scheme
274 ;; initialization depend on these options.
276 (for-each (lambda (x)
277 (ly:add-option (car x) (cadr x) (caddr x)))
278 scheme-options-definitions)
280 (for-each (lambda (x)
281 (ly:set-option (car x) (cdr x)))
282 (eval-string (ly:command-line-options)))
286 (if (defined? 'set-debug-cell-accesses!)
287 (set-debug-cell-accesses! #f))
289 ;;(set-debug-cell-accesses! 1000)
291 (use-modules (ice-9 regex)
303 (scm safe-utility-defs))
305 (define-public _ gettext)
306 ;;; There are new modules defined in Guile V2.0 which we need to use.
308 ;; Modules and scheme files loaded by lily.scm use currying
309 ;; in Guile V2 this needs a module which is not present in Guile V1.8
314 (ly:debug (_ "Using (ice-9 curried-definitions) module\n"))
315 (use-modules (ice-9 curried-definitions)))
317 (ly:debug (_ "Guile 1.8\n"))))
319 ;; TODO add in modules for V1.8.7 deprecated in V2.0 and integrated
320 ;; into Guile base code, like (ice-9 syncase).
323 (define-public fancy-format
326 (define-public (ergonomic-simple-format dest . rest)
327 "Like ice-9's @code{format}, but without the memory consumption."
329 (apply simple-format (cons #f (cons dest rest)))
330 (apply simple-format (cons dest rest))))
333 ergonomic-simple-format)
336 (define-public (myd k v)
343 (define-public (print . args)
344 (apply format (cons (current-output-port) args)))
347 ;;; General settings.
349 ;;; Debugging evaluator is slower. This should have a more sensible
353 (if (or (ly:get-option 'verbose)
354 (ly:get-option 'trace-memory-frequency)
355 (ly:get-option 'trace-scheme-coverage))
357 (ly:set-option 'protected-scheme-parsing #f)
358 (debug-enable 'backtrace)
359 (read-enable 'positions)))
361 (if (ly:get-option 'trace-scheme-coverage)
364 (define-public parser #f)
366 (define music-string-to-path-backends
369 (if (memq (ly:get-option 'backend) music-string-to-path-backends)
370 (ly:set-option 'music-strings-to-paths #t))
372 (define-public (ly:load x)
373 (let* ((file-name (%search-load-path x)))
374 (ly:debug "[~A" file-name)
376 (ly:error (_ "cannot find: ~A") x))
377 (primitive-load-path file-name) ;; to support Guile V2 autocompile
378 ;; TODO: Any chance to use ly:debug here? Need to extend it to prevent
379 ;; a newline in this case
380 (if (ly:get-option 'verbose)
381 (ly:progress "]\n"))))
384 (let ((platform (string-tokenize
385 (vector-ref (uname) 0) char-set:letter+digit)))
386 (if (null? (cdr platform)) #f
387 (member (string-downcase (cadr platform)) '("95" "98" "me")))))
390 (if (string-index x #\\)
392 (string-regexp-substitute
394 (string-regexp-substitute "\\\\" "/" x))))
396 (define-public (ly-getcwd)
397 (if (eq? PLATFORM 'windows)
401 (define-public (is-absolute? file-name)
402 (let ((file-name-length (string-length file-name)))
403 (if (= file-name-length 0)
405 (or (eq? (string-ref file-name 0) #\/)
406 (and (eq? PLATFORM 'windows)
407 (> file-name-length 2)
408 (eq? (string-ref file-name 1) #\:)
409 (eq? (string-ref file-name 2) #\/))))))
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
412 ;;; If necessary, emulate Guile V2 module_export_all! for Guile V1.8.n
415 (define (module-export-all! mod)
416 (define (fresh-interface!)
417 (let ((iface (make-module)))
418 (set-module-name! iface (module-name mod))
419 ;; for guile 2: (set-module-version! iface (module-version mod))
420 (set-module-kind! iface 'interface)
421 (set-module-public-interface! mod iface)
423 (let ((iface (or (module-public-interface mod)
424 (fresh-interface!))))
425 (set-module-obarray! iface (module-obarray mod))))))
428 (define-safe-public (lilypond-version)
430 (map (lambda (x) (if (symbol? x)
436 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
439 (ly:set-default-scale (ly:make-scale #(0 1 2 5/2 7/2 9/2 11/2)))
441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
445 ;; List of Scheme files to be loaded into the (lily) module.
447 ;; - Library definitions, need to be at the head of the list
448 (define init-scheme-files-lib
451 ;; - Files containing definitions used later by other files later in load
452 (define init-scheme-files-used
453 '("markup-macros.scm"
454 "parser-ly-from-scheme.scm"))
455 ;; - Main body of files to be loaded
456 (define init-scheme-files-body
458 "define-event-classes.scm"
459 "define-music-callbacks.scm"
460 "define-music-types.scm"
461 "define-note-names.scm"
466 "define-markup-commands.scm"
468 "modal-transforms.scm"
469 "chord-generic-names.scm"
470 "chord-ignatzek-names.scm"
471 "music-functions.scm"
474 "define-music-properties.scm"
475 "time-signature-settings.scm"
479 "ly-syntax-constructors.scm"
481 "define-context-properties.scm"
482 "translation-functions.scm"
496 "define-woodwind-diagrams.scm"
497 "display-woodwind-diagrams.scm"
498 "predefined-fretboards.scm"
499 "define-grob-properties.scm"
501 "define-grob-interfaces.scm"
502 "define-stencil-commands.scm"
503 "scheme-engravers.scm"
508 "backend-library.scm"
510 ;; - Files to be loaded last
511 (define init-scheme-files-tail
512 ;; - must be after everything has been defined
515 ;; Now construct the load list
517 (define init-scheme-files
518 (append init-scheme-files-lib
519 init-scheme-files-used
520 init-scheme-files-body
521 init-scheme-files-tail))
523 (for-each ly:load init-scheme-files)
525 (define-public r5rs-primary-predicates
526 `((,boolean? . "boolean")
527 (,char? . "character")
528 (,number? . "number")
531 (,procedure? . "procedure")
532 (,string? . "string")
533 (,symbol? . "symbol")
534 (,vector? . "vector")))
536 (define-public r5rs-secondary-predicates
537 `((,char-alphabetic? . "alphabetic character")
538 (,char-lower-case? . "lower-case character")
539 (,char-numeric? . "numeric character")
540 (,char-upper-case? . "upper-case character")
541 (,char-whitespace? . "whitespace character")
543 (,complex? . "complex number")
544 (,even? . "even number")
545 (,exact? . "exact number")
546 (,inexact? . "inexact number")
547 (,integer? . "integer")
548 (,negative? . "negative number")
549 (,odd? . "odd number")
550 (,positive? . "positive number")
551 (,rational? . "rational number")
552 (,real? . "real number")
558 (,input-port? . "input port")
559 (,output-port? . "output port")
561 ;; would this ever be used?
562 (,eof-object? . "end-of-file object")
565 (define-public guile-predicates
566 `((,hash-table? . "hash table")
569 (define-public lilypond-scheme-predicates
570 `((,boolean-or-symbol? . "boolean or symbol")
572 (,cheap-list? . "list")
573 (,fraction? . "fraction, as pair")
574 (,grob-list? . "list of grobs")
575 (,index? . "non-negative integer")
576 (,markup? . "markup")
577 (,markup-command-list? . "markup command list")
578 (,markup-list? . "markup list")
579 (,moment-pair? . "pair of moment objects")
580 (,number-list? . "number list")
581 (,number-or-grob? . "number or grob")
582 (,number-or-markup? . "number or markup")
583 (,number-or-pair? . "number or pair")
584 (,number-or-string? . "number or string")
585 (,number-pair? . "pair of numbers")
586 (,rhythmic-location? . "rhythmic location")
587 (,scheme? . "any type")
588 (,string-or-pair? . "string or pair")
589 (,string-or-music? . "string or music")
590 (,string-or-symbol? . "string or symbol")
591 (,symbol-list? . "symbol list")
592 (,symbol-list-or-music? . "symbol list or music")
593 (,symbol-list-or-symbol? . "symbol list or symbol")
597 (define-public lilypond-exported-predicates
598 `((,ly:book? . "book")
600 (,ly:context? . "context")
601 (,ly:context-def? . "context definition")
602 (,ly:context-mod? . "context modification")
603 (,ly:dimension? . "dimension, in staff space")
604 (,ly:dir? . "direction")
605 (,ly:dispatcher? . "dispatcher")
606 (,ly:duration? . "duration")
607 (,ly:event? . "post event")
608 (,ly:font-metric? . "font metric")
609 (,ly:grob? . "graphical (layout) object")
610 (,ly:grob-array? . "array of grobs")
611 (,ly:input-location? . "input location")
613 (,ly:iterator? . "iterator")
614 (,ly:lily-lexer? . "lily-lexer")
615 (,ly:lily-parser? . "lily-parser")
616 (,ly:listener? . "listener")
617 (,ly:moment? . "moment")
618 (,ly:music? . "music")
619 (,ly:music-function? . "music function")
620 (,ly:music-list? . "list of music objects")
621 (,ly:music-output? . "music output")
622 (,ly:otf-font? . "OpenType font")
623 (,ly:output-def? . "output definition")
624 (,ly:page-marker? . "page marker")
625 (,ly:pango-font? . "pango font")
626 (,ly:paper-book? . "paper book")
627 (,ly:paper-system? . "paper-system Prob")
628 (,ly:pitch? . "pitch")
629 (,ly:prob? . "property object")
630 (,ly:score? . "score")
631 (,ly:simple-closure? . "simple closure")
632 (,ly:skyline? . "skyline")
633 (,ly:skyline-pair? . "pair of skylines")
634 (,ly:source-file? . "source file")
635 (,ly:spanner? . "spanner")
636 (,ly:spring? . "spring")
637 (,ly:stencil? . "stencil")
638 (,ly:stream-event? . "stream event")
639 (,ly:translator? . "translator")
640 (,ly:translator-group? . "translator group")
641 (,ly:unpure-pure-container? . "unpure/pure container")
645 (set! type-p-name-alist
646 (append r5rs-primary-predicates
647 r5rs-secondary-predicates
649 lilypond-scheme-predicates
650 lilypond-exported-predicates))
653 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
656 (define (profile-measurements)
659 (list (- (+ (tms:cutime t)
661 (assoc-get 'gc-time-taken stats))
662 (assoc-get 'total-cells-allocated stats 0))))
664 (define (dump-profile base last this)
665 (let* ((outname (format #f "~a.profile" (dir-basename base ".ly")))
666 (diff (map (lambda (y) (apply - y)) (zip this last))))
667 (ly:progress "\nWriting timing to ~a..." outname)
668 (format (open-file outname "w")
669 "time: ~a\ncells: ~a\n"
670 (if (ly:get-option 'dump-cpu-profile)
675 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
676 ;; debug memory leaks
681 (define gc-protect-stat-count
684 ;; Undead objects that should be ignored after the first time round
686 (make-weak-key-hash-table 0))
688 (define-public (dump-live-object-stats outfile)
689 (for-each (lambda (x)
690 (format outfile "~a: ~a\n" (car x) (cdr x)))
691 (sort (gc-live-object-stats)
693 (string<? (car x) (car y))))))
695 (define-public (dump-gc-protects)
696 (set! gc-protect-stat-count (1+ gc-protect-stat-count))
697 (let* ((protects (sort (hash-table->alist (ly:protects))
699 (< (object-address (car a))
700 (object-address (car b))))))
701 (out-file-name (string-append
702 "gcstat-" (number->string gc-protect-stat-count)
704 (outfile (open-file out-file-name "w")))
706 (ly:progress "Dumping GC statistics ~a...\n" out-file-name)
707 (for-each (lambda (y)
710 (format outfile "~a (~a) = ~a\n" (object-address x) c x)))
713 (not (symbol? (car x))))
715 (format outfile "\nprotected symbols: ~a\n"
716 (apply + (map (lambda (obj-count)
717 (if (symbol? (car obj-count))
722 ;; (display (ly:smob-protects))
724 (if (defined? 'gc-live-object-stats)
726 (ly:progress "Live object statistics: GC'ing\n")
730 (ly:progress "Asserting dead objects\n")
731 (ly:set-option 'debug-gc-assert-parsed-dead #t)
733 (ly:set-option 'debug-gc-assert-parsed-dead #f)
736 (if (not (hashq-ref gc-zombies x))
738 (ly:programming-error "Parsed object should be dead: ~a" x)
739 (hashq-set! gc-zombies x #t))))
740 (ly:parsed-undead-list!))
741 (set! stats (gc-live-object-stats))
742 (ly:progress "Dumping live object statistics.\n")
743 (dump-live-object-stats outfile)))
745 (let* ((stats (gc-stats)))
746 (for-each (lambda (sym)
747 (format outfile "~a ~a ~a\n"
748 gc-protect-stat-count
750 (assoc-get sym stats "?")))
751 '(protected-objects bytes-malloced cell-heap-size)))
753 (close-port outfile)))
755 (define (check-memory)
756 "Read `/proc/self' to check up on memory use."
757 (define (gulp-file name)
758 (let* ((file (open-input-file name))
759 (text (read-delimited "" file)))
763 (let* ((stat (gulp-file "/proc/self/status"))
764 (lines (string-split stat #\newline))
765 (interesting (filter identity
768 (string-match "^VmData:[ \t]*([0-9]*) kB" l))
770 (mem (string->number (match:substring (car interesting) 1))))
771 (format #t "VMDATA: ~a\n" mem)
775 (begin (dump-gc-protects)
778 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
780 (define (multi-fork count)
781 "Split this process into COUNT helpers. Returns either a list of
782 PIDs or the number of the process."
783 (define (helper count acc)
785 (let* ((pid (primitive-fork)))
788 (helper (1- count) (cons pid acc))))
793 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
795 (define* (ly:exit status #:optional (silently #f))
796 "Exit function for lilypond"
799 ((0) (ly:basic-progress (_ "Success: compilation successfully completed")))
800 ((1) (ly:warning (_ "Compilation completed with warnings or errors")))
801 (else (ly:message ""))))
804 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
806 (define-public (lilypond-main files)
807 "Entry point for LilyPond."
808 (eval-string (ly:command-line-code))
809 (if (ly:get-option 'help)
810 (begin (ly:option-usage)
812 (if (ly:get-option 'show-available-fonts)
813 (begin (ly:font-config-display-fonts)
815 (if (ly:get-option 'gui)
820 (if (ly:get-option 'read-file-list)
823 (> (string-length s) 0))
826 (string-split (string-delete (ly:gulp-file f) #\cr) #\nl))
828 (if (and (number? (ly:get-option 'job-count))
829 (>= (length files) (ly:get-option 'job-count)))
830 (let* ((count (ly:get-option 'job-count))
831 (split-todo (split-list files count))
832 (joblist (multi-fork count))
834 (if (not (string-or-symbol? (ly:get-option 'log-file)))
835 (ly:set-option 'log-file "lilypond-multi-run"))
836 (if (number? joblist)
837 (begin (ly:set-option
838 'log-file (format #f "~a-~a"
839 (ly:get-option 'log-file) joblist))
840 (set! files (vector-ref split-todo joblist)))
841 (begin (ly:progress "\nForking into jobs: ~a\n" joblist)
844 (let* ((stat (cdr (waitpid pid))))
847 (acons (list-element-index joblist pid)
854 (logfile (format #f "~a-~a.log"
855 (ly:get-option 'log-file) job))
856 (log (ly:gulp-file logfile))
857 (len (string-length log))
858 (tail (substring log (max 0 (- len 1024)))))
859 (if (status:term-sig state)
862 (format #f (_ "job ~a terminated with signal: ~a")
863 job (status:term-sig state)))
865 (_ "logfile ~a (exit ~a):\n~a")
866 logfile (status:exit-val state) tail))))
869 (ly:error "Children ~a exited with errors."
871 ;; must overwrite individual entries
872 (if (ly:get-option 'dump-profile)
873 (dump-profile "lily-run-total"
874 '(0 0) (profile-measurements)))
879 (if (string-or-symbol? (ly:get-option 'log-file))
880 (ly:stderr-redirect (format #f "~a.log" (ly:get-option 'log-file)) "w"))
881 (let ((failed (lilypond-all files)))
882 (if (ly:get-option 'trace-scheme-coverage)
884 (coverage:show-all (lambda (f)
885 (string-contains f "lilypond")))))
887 (begin (ly:error (_ "failed files: ~S") (string-join failed))
893 (define-public (lilypond-all files)
895 (separate-logs (ly:get-option 'separate-log-files))
898 (if (string-or-symbol? (ly:get-option 'log-file))
899 (open-file (format #f "~a.log" (ly:get-option 'log-file))
902 (do-measurements (ly:get-option 'dump-profile))
903 (handler (lambda (key failed-file)
904 (set! failed (append (list failed-file) failed)))))
908 (let* ((start-measurements (if do-measurements
909 (profile-measurements)
911 (base (dir-basename x ".ly"))
912 (all-settings (ly:all-options)))
914 (ly:stderr-redirect (format #f "~a.log" base) "w"))
916 (format ping-log "Processing ~a\n" base))
917 (if (ly:get-option 'trace-memory-frequency)
918 (mtrace:start-trace (ly:get-option 'trace-memory-frequency)))
919 (lilypond-file handler x)
920 (ly:check-expected-warnings)
922 (if start-measurements
923 (dump-profile x start-measurements (profile-measurements)))
924 (if (ly:get-option 'trace-memory-frequency)
925 (begin (mtrace:stop-trace)
926 (mtrace:dump-results base)))
927 (for-each (lambda (s)
928 (ly:set-option (car s) (cdr s)))
930 (ly:set-option 'debug-gc-assert-parsed-dead #t)
932 (ly:set-option 'debug-gc-assert-parsed-dead #f)
935 (if (not (hashq-ref gc-zombies x))
937 (ly:programming-error "Parsed object should be dead: ~a" x)
938 (hashq-set! gc-zombies x #t))))
939 (ly:parsed-undead-list!))
940 (if (ly:get-option 'debug-gc)
942 (ly:reset-all-fonts))
946 ;; Ensure a notice re failed files is written to aggregate logfile.
948 (format ping-log "Failed files: ~a\n" failed))
949 (if (ly:get-option 'dump-profile)
950 (dump-profile "lily-run-total" '(0 0) (profile-measurements)))
953 (define (lilypond-file handler file-name)
954 (catch 'ly-file-failed
955 (lambda () (ly:parse-file file-name))
956 (lambda (x . args) (handler x file-name))))
958 (use-modules (scm editor))
960 (define-public (gui-main files)
962 (gui-no-files-handler))
963 (if (not (string? (ly:get-option 'log-file)))
964 (let* ((base (dir-basename (car files) ".ly"))
965 (log-name (string-append base ".log")))
966 (if (not (ly:get-option 'gui))
967 (ly:message (_ "Redirecting output to ~a...") log-name))
968 (ly:stderr-redirect log-name "w")
969 (ly:message "# -*-compilation-*-"))
970 (let ((failed (lilypond-all files)))
974 (ly:stderr-redirect "foo" "r")
975 (system (get-editor-command log-name 0 0 0))
976 (ly:error (_ "failed files: ~S") (string-join failed))
981 (define (gui-no-files-handler)
982 (let* ((ly (string-append (ly:effective-prefix) "/ly/"))
983 ;; FIXME: soft-code, localize
984 (welcome-ly (string-append ly "Welcome_to_LilyPond.ly"))
985 (cmd (get-editor-command welcome-ly 0 0 0)))
986 (ly:message (_ "Invoking `~a'...\n") cmd)