|
6 | 6 | (:local-nicknames (:bt :bordeaux-threads))
|
7 | 7 | (:shadowing-import-from :closer-mop :ensure-finalized)
|
8 | 8 | (:import-from :cffi)
|
9 |
| - (:import-from :kiln/dispatch) |
| 9 | + (:import-from :kiln/dispatch :*entry-point*) |
| 10 | + (:import-from |
| 11 | + :kiln/flags |
| 12 | + :dbg |
| 13 | + :+kiln-target-package+ |
| 14 | + :+kiln-target-system+) |
10 | 15 | (:import-from :kiln/script-cache :populate-script-cache)
|
11 | 16 | (:import-from :kiln/script-cache :populate-script-cache)
|
12 | 17 | (:import-from :kiln/utils :setpgrp)
|
13 | 18 | (:export
|
14 |
| - :load-all-script-systems)) |
| 19 | + :load-all-script-systems)) |
15 | 20 | (in-package :kiln/image)
|
16 | 21 |
|
17 | 22 | (let (lib-names)
|
|
33 | 38 | script-systems
|
34 | 39 | :test #'equal)))
|
35 | 40 |
|
| 41 | +(defun mark-all-systems-immutable () |
| 42 | + (map nil 'asdf:register-immutable-system |
| 43 | + (asdf:already-loaded-systems))) |
| 44 | + |
36 | 45 | (defun record-builtins ()
|
37 | 46 | (setf *builtins-by-system*
|
38 | 47 | (list-all-scripts-by-system)
|
|
54 | 63 | (unless (typep cls 'built-in-class)
|
55 | 64 | (ensure-finalized cls)))))
|
56 | 65 |
|
| 66 | +(defparameter *target-system* |
| 67 | + (uiop:getenvp +kiln-target-system+)) |
| 68 | + |
| 69 | +(defparameter *target-package* |
| 70 | + (or (uiop:getenvp +kiln-target-package+) |
| 71 | + (and *target-system* |
| 72 | + (string-invert-case *target-system*)))) |
| 73 | + |
57 | 74 | (defun kiln-before-dump-image ()
|
58 | 75 | (setf uiop/image::*lisp-interaction* nil)
|
59 | 76 | #+sbcl (setf sb-ext:*derive-function-types* t)
|
|
65 | 82 | (record-builtins)
|
66 | 83 | ;; NB Quicklisp doesn't work if it's called inside of the ASDF
|
67 | 84 | ;; build-op. So we run it in a separate thread. (Is this still true?)
|
68 |
| - (let* ((subsystems (list-builtin-script-subsystems))) |
69 |
| - (load-all-script-systems :script-systems subsystems) |
70 |
| - ;; Mark systems immutable twice: first anything loaded by the |
71 |
| - ;; package scripts (so the shebang scripts load faster), then |
72 |
| - ;; again for anything loaded after the shebang scripts. |
73 |
| - (mark-other-systems-immutable :script-systems subsystems) |
74 |
| - (populate-script-cache) |
75 |
| - (mark-other-systems-immutable :script-systems subsystems)) |
| 85 | + (if *target-system* |
| 86 | + (let ((package-name |
| 87 | + (or *target-package* |
| 88 | + (error "No target package name in environment")))) |
| 89 | + (load-system *target-system*) |
| 90 | + (mark-all-systems-immutable) |
| 91 | + (let ((package |
| 92 | + (or (find-package package-name) |
| 93 | + (error "No such package as ~a" package-name)))) |
| 94 | + (setf *entry-point* |
| 95 | + (or (find-symbol (string 'main) package) |
| 96 | + (error "No main function for package ~a" |
| 97 | + package-name))))) |
| 98 | + (let* ((subsystems (list-builtin-script-subsystems))) |
| 99 | + (load-all-script-systems :script-systems subsystems) |
| 100 | + ;; Mark systems immutable twice: first anything loaded by the |
| 101 | + ;; package scripts (so the shebang scripts load faster), then |
| 102 | + ;; again for anything loaded after the shebang scripts. |
| 103 | + (mark-other-systems-immutable :script-systems subsystems) |
| 104 | + (populate-script-cache) |
| 105 | + (mark-other-systems-immutable :script-systems subsystems))) |
76 | 106 | (finalize-all-classes)
|
77 | 107 | (asdf:clear-configuration)
|
78 | 108 | (unload-all-foreign-libraries))))
|
|
83 | 113 | #+sbcl
|
84 | 114 | (defvar *sbcl-home* (sb-int:sbcl-homedir-pathname))
|
85 | 115 |
|
86 |
| - |
87 | 116 | (defun kiln-after-restore-image ()
|
88 | 117 | #+sbcl (sb-ext:disable-debugger)
|
89 | 118 | ;; TODO Would it be better to preload them all?
|
90 |
| - #+sbcl (setf sb-sys::*sbcl-homedir-pathname* *sbcl-home*) |
91 |
| - #+sbcl (setf sb-ext:*derive-function-types* nil) |
| 119 | + (unless *target-system* |
| 120 | + #+sbcl (setf sb-sys::*sbcl-homedir-pathname* *sbcl-home*) |
| 121 | + #+sbcl (setf sb-ext:*derive-function-types* nil)) |
92 | 122 | (setf uiop/image::*lisp-interaction* nil)
|
93 | 123 | (setpgrp)
|
94 | 124 | (reload-all-foreign-libraries))
|
|
0 commit comments