@@@ more wip
[runlisp] / runlisp-base.conf
CommitLineData
8996f767
MW
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.
48ignore-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.
59clear-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.
71set-script-feature =
72 (pushnew :runlisp-script *features*)
73
74;; Load the system's ASDF.
75require-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.
82inhibit-asdf-upgrade =
83 (funcall (intern "REGISTER-IMMUTABLE-SYSTEM"
84 (find-package "ASDF"))
85 "asdf")
86
87;; Upgrade ASDF from the source registry.
88upgrade-asdf =
89 (funcall (intern "UPGRADE-ASDF" (find-package "ASDF")))
90
91;; Common actions when resuming a custom image.
92image-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.
97run-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.
106dump-image-prelude =
107 (progn
108 ${require-asdf}
109 ${upgrade-asdf}
110 ${inhibit-asdf-upgrade}
111 ${ignore-shebang}
112 ${set-script-feature})
113
114image-path = ${@image-dir}/${image-file}
115
116;;;--------------------------------------------------------------------------
117[sbcl]
118
119command = ${@ENV:SBCL?sbcl}
120image-file = ${@name}+asdf.core
121
122run-script =
123 ${command} --noinform
124 $?@image{--core "${image-path}" --eval "${image-restore}" |
125 --eval "${run-script-prelude}"}
126 --script "${@script}"
127
128dump-image =
129 ${command} --noinform --no-userinit --no-sysinit --disable-debugger
130 --eval "${dump-image-prelude}"
131 --eval "(sb-ext:save-lisp-and-die \"${@image-new|q}\")"
132
133;;;--------------------------------------------------------------------------
134[ccl]
135
136command = ${@ENV:CCL?ccl}
137image-file = ${@name}+asdf.image
138
139run-script =
140 ${command} -b -n -Q
141 $?@image{-I "${image-path}" -e "${image-restore}" |
142 -e "${run-script-prelude}"}
143 -l "${@script}" -e "(ccl:quit)" --
144
145;; A snaglet occurs here. CCL wants to use the image name as a clue to where
146;; the rest of its installation is; but in fact the image is nowhere near its
147;; installation. So we must hack...
148dump-image =
149 ${command} -b -n -Q
150 -e "${dump-image-prelude}"
151 -e "(ccl::in-development-mode
152 (let ((#1=#:real-ccl-dir (ccl::ccl-directory)))
153 (defun ccl::ccl-directory ()
154 (let* ((#2=#:dirpath
155 (ccl:getenv \"CCL_DEFAULT_DIRECTORY\")))
156 (if (and #2# (plusp (length (namestring #2#))))
157 (ccl::native-to-directory-pathname #2#)
158 #1#))))
159 (compile 'ccl::ccl-directory))"
160 -e "(ccl:save-application \"${@image-new|q}\"
161 :init-file nil
162 :error-handler :quit)"
163
164;;;--------------------------------------------------------------------------
165[clisp]
166
167;; CLisp causes much sadness. Superficially, it's the most sensible of all
168;; of the systems supported here: you just run `clisp SCRIPT -- ARGS ...' and
169;; it works.
170;;
171;; The problems come when you want to do some preparatory work (e.g., load
172;; `asdf') and then run the script. There's a `-x' option to evaluate some
173;; Lisp code, but it has three major deficiencies.
174;;
175;; * It insists on printing the values of the forms it evaluates. It
176;; prints a blank line even if the form goes out of its way to produce no
177;; values at all. So the whole thing has to be a single top-level form
178;; which quits the Lisp rather than returning.
179;;
180;; * For some idiotic reason, you can have /either/ `-x' forms /or/ a
181;; script, but not both. So we have to include the `load' here
182;; explicitly. I suppose that was inevitable because we have to inhibit
183;; printing of the result forms, but it's still a separate source of
184;; annoyance.
185;;
186;; * The icing on the cake: the `-x' forms are collectively concatenated --
187;; without spaces! -- and used to build a string stream, which is then
188;; assigned over the top of `*standard-input*', making the original stdin
189;; somewhat fiddly to track down.
190;;
191;; There's a `-i' option which will load a file without any of this
192;; stupidity, but nothing analogous for immediate expressions.
193
194clisp-common-startup =
195 (setf *standard-input* (ext:make-stream :input))
196 (load "${@script|q}" :verbose nil :print nil)
197 (ext:quit)
198
199command = ${@ENV:CLISP?clisp}
200image-file = ${@name}+asdf.mem
201
202run-script =
203 ${command}
204 $?@image{-M "${image-path}" -q
205 -x "(progn
206 ${image-restore}
207 ${clisp-common-startup})" |
208 -norc -q
209 -x "(progn
210 ${run-script-prelude}
211 ${clisp-common-startup})"}
212 --
213
214dump-image =
215 ${command} -norc -q -q
216 -x "${dump-image-prelude}"
217 -x "(ext:saveinitmem \"${@image-new|q}\" :norc t :script t)"
218
219;;;--------------------------------------------------------------------------
220[ecl]
221
222command = ${@ENV:ECL?ecl}
223image-file = ${@name}+asdf
224
225run-script =
226 $?@image{"${image-path}" -s "${@script}" |
227 ${@ENV:ECL?ecl} "${@ecl-opt}norc"
228 "${@ecl-opt}eval" "(progn
229 ${run-script-prelude}
230 ${clear-cl-user})"
231 "${@ecl-opt}shell" "${@script}"}
232 --
233
234dump-image =
235 "${@data-dir}/dump-ecl"
236 "${@image-new}" "${command}" "${@ecl-opt}" "${@tmp-dir}"
237
238;;;--------------------------------------------------------------------------
239[cmucl]
240
241command = ${@ENV:CMUCL?cmucl}
242image-file = ${@name}+asdf.core
243
244run-script =
245 ${command}
246 $?@image{-core "${image-path}" -eval "${image-restore}" |
247 -batch -noinit -nositeinit -quiet
248 -eval "(progn
249 (setf ext:*require-verbose* nil)
250 ${run-script-prelude})"}
251 -load "${@script}" -eval "(ext:quit)" --
252
253dump-image =
254 ${command} -batch -noinit -nositeinit -quiet
255 -eval "${dump-image-prelude}"
256 -eval "(ext:save-lisp \"${@image-new|q}\"
257 :batch-mode t :print-herald nil
258 :site-init nil :load-init-file nil)"
259
260;;;--------------------------------------------------------------------------
261[abcl]
262
263;; CLisp made a worthy effort, but ABCL still manages to take the prize.
264;;
265;; * ABCL manages to avoid touching the `stderr' stream at all, ever. Its
266;; startup machinery finds `stdout' (as `java.lang.System.out'), wraps it
267;; up in a Lisp stream, and uses the result as `*standard-output*' and
268;; `*error-output*' (and a goodly number of other things too). So we
269;; must manufacture a working `stderr' the hard way.
270;;
271;; * There doesn't appear to be any easy way to prevent toplevel errors
272;; from invoking the interactive debugger. For extra fun, the debugger
273;; reads from `stdin' by default, so an input file which somehow manages
274;; to break the script can then take over its brain by providing Lisp
275;; forms for the debugger to evaluate.
276;;
277;; * And, just to really top everything off, ABCL's `adjoin.lisp' is
278;; missing an `(in-package ...)' form at the top, so it leaks symbols
279;; into the `COMMON-LISP-USER' package.
280
281command = ${@ENV:ABCL?abcl}
282
283abcl-startup =
284 (let ((#9=#:script "${@script|q}"))
285 ${run-script-prelude}
286 ${clear-cl-user}
287 (setf *error-output*
288 (java:jnew "org.armedbear.lisp.Stream"
289 \'sys::system-stream
290 (java:jfield "java.lang.System" "err")
291 \'character
292 java:+true+))
293 (handler-case (load #9# :verbose nil :print nil)
294 (error (error)
295 (format *error-output* "~A (unhandled error): ~A~%" #9# error)
296 (ext:quit :status 255))))
297
298run-script =
299 ${command} --batch --noinform --noinit --nosystem
300 --eval "${abcl-startup}"
301 --
302
303;;;----- That's all, folks --------------------------------------------------