dump-runlisp-image.c: Add more logging about image commit.
[runlisp] / runlisp-base.conf
1 ;;; -*-conf-windows-*-
2
3 ;; This file contains essential definitions for `runlisp'. You are
4 ;; encouraged to put your local changes in the main `runlisp.conf', or in
5 ;; other files alongside this one in `runlisp.d/', rather then editing this
6 ;; file.
7
8 ;; Summary of syntax.
9 ;;
10 ;; Sections are started with a line `[NAME]', starting in the leftmost
11 ;; column. Empty lines and lines starting with `;' -- /without/ preceding
12 ;; whitespace -- are ignored. Assignments have the form `VAR = VALUE'; the
13 ;; VALUE may be continued across multiple lines, if they begin with
14 ;; whitespace. All of the lines are stripped of initial and final whitespace
15 ;; and concatenated with spaces.
16 ;;
17 ;; Values may contain substitutions:
18 ;;
19 ;; * ${[SECTION:]VAR[?ALT]} -- replace with the value of VAR in SECTION; if
20 ;; not found, use ALT instead. (If ALT isn't provided, it's an error.)
21 ;;
22 ;; * $?[SECTION:]VAR{YES[|NO]} -- look up VAR in SECTION (or in the
23 ;; (original) current section, and `@COMMON'); if found, use YES,
24 ;; otherwise use NO.
25 ;;
26 ;; Variables are looked up starting in the home (or explicitly specified)
27 ;; section, then proceeding to the parents assigned to `@PARENTS'.
28 ;; (`@PARENTS' usually defaults to `@COMMON'; the parent of `@COMMON' is
29 ;; `@BUILTIN'; `@BUILTIN' and `@CONFIG' have no parents.)
30 ;;
31 ;; At top-level, the text is split into words at whitespace, unless prevented
32 ;; by double- and single-quote, or escaped by `\'. Within single quotes, all
33 ;; characters are treated literally. Within double quotes, `\' and `$' still
34 ;; works. A variable reference within quotes, or within a word, suppresses
35 ;; word-splitting and quoting, within the variable value -- but `$'
36 ;; expansions still work.
37
38 ;;;--------------------------------------------------------------------------
39 [@COMMON]
40
41 ;; Turn `#!' into a comment-to-end-of-line. This is used in all Lisp
42 ;; invocations, even though some of them don't apparently need it. For
43 ;; example, SBCL ignores an initial line beginning `#!' as a special feature
44 ;; of its `--script' option. Other Lisps won't do this, so a countermeasure
45 ;; like the following is necessary in their case. For the sake of a
46 ;; consistent environment, we ignore `#!' lines everywhere, even in Lisps
47 ;; which have their own, more specific, solution to this problem.
48 ignore-shebang =
49 (set-dispatch-macro-character
50 #\\# #\\!
51 (lambda (#1=#:stream #2=#:char #3=#:arg)
52 (declare (ignore #2# #3#))
53 (values (read-line #1#))))
54
55 ;; Clear all present symbols from the `COMMON-LISP-USER' package. Some Lisps
56 ;; leave débris in `COMMON-LISP-USER' -- for example, ECL leaves some
57 ;; allegedly useful symbols lying around, while ABCL has a straight-up bug in
58 ;; its `adjoin.lisp' file.
59 clear-cl-user =
60 (let ((#4=#:pkg (find-package "COMMON-LISP-USER")))
61 (with-package-iterator (#5=#:next #4# :internal)
62 (loop (multiple-value-bind (#6=#:anyp #7=#:sym #8=#:how)
63 (#5#)
64 (declare (ignore #8#))
65 (unless #6# (return))
66 (unintern #7# #4#)))))
67
68 ;; Add `:runlisp-script' to `*features*' so that scripts can tell whether
69 ;; they're supposed to sit quietly and be debugged in a Lisp session or run
70 ;; as a script.
71 set-script-feature =
72 (pushnew :runlisp-script *features*)
73
74 ;; Load the system's ASDF.
75 require-asdf =
76 (require "asdf")
77
78 ;; Prevent ASDF from upgrading itself. Otherwise it will do this
79 ;; automatically if a script invokes `asdf:load-system', but that will have a
80 ;; bad effect on startup time, and risks spamming the output streams with
81 ;; drivel.
82 inhibit-asdf-upgrade =
83 (funcall (intern "REGISTER-IMMUTABLE-SYSTEM"
84 (find-package "ASDF"))
85 "asdf")
86
87 ;; Upgrade ASDF from the source registry.
88 upgrade-asdf =
89 (funcall (intern "UPGRADE-ASDF" (find-package "ASDF")))
90
91 ;; Common actions when resuming a custom image.
92 image-restore =
93 (uiop:call-image-restore-hook)
94
95 ;; Common prelude for script startup in vanilla images. Most of this is
96 ;; already done in custom images.
97 run-script-prelude =
98 (progn
99 (setf *load-verbose* nil *compile-verbose* nil)
100 ${require-asdf}
101 ${inhibit-asdf-upgrade}
102 ${ignore-shebang}
103 ${set-script-feature})
104
105 ;; Common prelude for dumping images.
106 dump-image-prelude =
107 (progn
108 ${require-asdf}
109 ${upgrade-asdf}
110 ${inhibit-asdf-upgrade}
111 ${ignore-shebang}
112 ${set-script-feature})
113
114 ;; Full pathname to custom image.
115 image-path = ${@image-dir}/${image-file}
116
117 ;;;--------------------------------------------------------------------------
118 [sbcl]
119
120 command = ${@ENV:SBCL?sbcl}
121 image-file = ${@name}+asdf.core
122
123 run-script =
124 ${command} --noinform
125 $?@image{--core "${image-path}" --eval "${image-restore}" |
126 --eval "${run-script-prelude}"}
127 --script "${@script}"
128
129 dump-image =
130 ${command} --noinform --no-userinit --no-sysinit --disable-debugger
131 --eval "${dump-image-prelude}"
132 --eval "(sb-ext:save-lisp-and-die \"${@image-new|q}\")"
133
134 ;;;--------------------------------------------------------------------------
135 [ccl]
136
137 command = ${@ENV:CCL?ccl}
138 image-file = ${@name}+asdf.image
139
140 run-script =
141 ${command} -b -n -Q
142 $?@image{-I "${image-path}" -e "${image-restore}" |
143 -e "${run-script-prelude}"}
144 -l "${@script}" -e "(ccl:quit)" --
145
146 ;; A snaglet occurs here. CCL wants to use the image name as a clue to where
147 ;; the rest of its installation is; but in fact the image is nowhere near its
148 ;; installation. So we must hack...
149 dump-image =
150 ${command} -b -n -Q
151 -e "${dump-image-prelude}"
152 -e "(ccl::in-development-mode
153 (let ((#1=#:real-ccl-dir (ccl::ccl-directory)))
154 (defun ccl::ccl-directory ()
155 (let* ((#2=#:dirpath
156 (ccl:getenv \"CCL_DEFAULT_DIRECTORY\")))
157 (if (and #2# (plusp (length (namestring #2#))))
158 (ccl::native-to-directory-pathname #2#)
159 #1#))))
160 (compile 'ccl::ccl-directory))"
161 -e "(ccl:save-application \"${@image-new|q}\"
162 :init-file nil
163 :error-handler :quit)"
164
165 ;;;--------------------------------------------------------------------------
166 [clisp]
167
168 ;; CLisp causes much sadness. Superficially, it's the most sensible of all
169 ;; of the systems supported here: you just run `clisp SCRIPT -- ARGS ...' and
170 ;; it works.
171 ;;
172 ;; The problems come when you want to do some preparatory work (e.g., load
173 ;; `asdf') and then run the script. There's a `-x' option to evaluate some
174 ;; Lisp code, but it has three major deficiencies.
175 ;;
176 ;; * It insists on printing the values of the forms it evaluates. It
177 ;; prints a blank line even if the form goes out of its way to produce no
178 ;; values at all. So the whole thing has to be a single top-level form
179 ;; which quits the Lisp rather than returning.
180 ;;
181 ;; * For some idiotic reason, you can have /either/ `-x' forms /or/ a
182 ;; script, but not both. So we have to include the `load' here
183 ;; explicitly. I suppose that was inevitable because we have to inhibit
184 ;; printing of the result forms, but it's still a separate source of
185 ;; annoyance.
186 ;;
187 ;; * The icing on the cake: the `-x' forms are collectively concatenated --
188 ;; without spaces! -- and used to build a string stream, which is then
189 ;; assigned over the top of `*standard-input*', making the original stdin
190 ;; somewhat fiddly to track down.
191 ;;
192 ;; There's a `-i' option which will load a file without any of this
193 ;; stupidity, but nothing analogous for immediate expressions.
194
195 clisp-common-startup =
196 (setf *standard-input* (ext:make-stream :input))
197 (load "${@script|q}" :verbose nil :print nil)
198 (ext:quit)
199
200 command = ${@ENV:CLISP?clisp}
201 image-file = ${@name}+asdf.mem
202
203 run-script =
204 ${command}
205 $?@image{-M "${image-path}" -q
206 -x "(progn
207 ${image-restore}
208 ${clisp-common-startup})" |
209 -norc -q
210 -x "(progn
211 ${run-script-prelude}
212 ${clisp-common-startup})"}
213 --
214
215 dump-image =
216 ${command} -norc -q -q
217 -x "${dump-image-prelude}"
218 -x "(ext:saveinitmem \"${@image-new|q}\" :norc t :script t)"
219
220 ;;;--------------------------------------------------------------------------
221 [ecl]
222
223 command = ${@ENV:ECL?ecl}
224 image-file = ${@name}+asdf
225
226 run-script =
227 $?@image{"${image-path}" -s "${@script}" |
228 ${@ENV:ECL?ecl} "${@ecl-opt}norc"
229 "${@ecl-opt}eval" "(progn
230 ${run-script-prelude}
231 ${clear-cl-user})"
232 "${@ecl-opt}shell" "${@script}"}
233 --
234
235 dump-image =
236 "${@data-dir}/dump-ecl"
237 "${@image-new}" "${command}" "${@ecl-opt}" "${@tmp-dir}"
238
239 ;;;--------------------------------------------------------------------------
240 [cmucl]
241
242 command = ${@ENV:CMUCL?cmucl}
243 image-file = ${@name}+asdf.core
244
245 run-script =
246 ${command}
247 $?@image{-core "${image-path}" -eval "${image-restore}" |
248 -batch -noinit -nositeinit -quiet
249 -eval "(progn
250 (setf ext:*require-verbose* nil)
251 ${run-script-prelude})"}
252 -load "${@script}" -eval "(ext:quit)" --
253
254 dump-image =
255 ${command} -batch -noinit -nositeinit -quiet
256 -eval "${dump-image-prelude}"
257 -eval "(ext:save-lisp \"${@image-new|q}\"
258 :batch-mode t :print-herald nil
259 :site-init nil :load-init-file nil)"
260
261 ;;;--------------------------------------------------------------------------
262 [abcl]
263
264 ;; CLisp made a worthy effort, but ABCL still manages to take the prize.
265 ;;
266 ;; * ABCL manages to avoid touching the `stderr' stream at all, ever. Its
267 ;; startup machinery finds `stdout' (as `java.lang.System.out'), wraps it
268 ;; up in a Lisp stream, and uses the result as `*standard-output*' and
269 ;; `*error-output*' (and a goodly number of other things too). So we
270 ;; must manufacture a working `stderr' the hard way.
271 ;;
272 ;; * There doesn't appear to be any easy way to prevent toplevel errors
273 ;; from invoking the interactive debugger. For extra fun, the debugger
274 ;; reads from `stdin' by default, so an input file which somehow manages
275 ;; to break the script can then take over its brain by providing Lisp
276 ;; forms for the debugger to evaluate.
277 ;;
278 ;; * And, just to really top everything off, ABCL's `adjoin.lisp' is
279 ;; missing an `(in-package ...)' form at the top, so it leaks symbols
280 ;; into the `COMMON-LISP-USER' package.
281
282 command = ${@ENV:ABCL?abcl}
283
284 abcl-startup =
285 (let ((#9=#:script "${@script|q}"))
286 ${run-script-prelude}
287 ${clear-cl-user}
288 (setf *error-output*
289 (java:jnew "org.armedbear.lisp.Stream"
290 \'sys::system-stream
291 (java:jfield "java.lang.System" "err")
292 \'character
293 java:+true+))
294 (handler-case (load #9# :verbose nil :print nil)
295 (error (error)
296 (format *error-output* "~A (unhandled error): ~A~%" #9# error)
297 (ext:quit :status 255))))
298
299 run-script =
300 ${command} --batch --noinform --noinit --nosystem
301 --eval "${abcl-startup}"
302 --
303
304 ;;;----- That's all, folks --------------------------------------------------