|
2 | 2 | ;;; Commentary: Prepare to setup Qob environment for sandboxing
|
3 | 3 | ;;; Code:
|
4 | 4 |
|
5 |
| - |
6 | 5 | ;;
|
7 | 6 | ;;; Includes
|
8 | 7 |
|
9 | 8 | (require "asdf")
|
10 | 9 |
|
| 10 | +;; |
| 11 | +;;; Verbose |
| 12 | + |
| 13 | +(defun qob-princ (stream fmt &rest args) |
| 14 | + "Root print function with STREAM. |
| 15 | +
|
| 16 | +The argument STREAM is used to decide weather the stream should be standard |
| 17 | +output or standard error. |
| 18 | +
|
| 19 | +The arguments FMT and ARGS are used to form the output message." |
| 20 | + (let ((object (apply #'format nil fmt args)) |
| 21 | + (stream (case stream |
| 22 | + (stdout *standard-output*) |
| 23 | + (stderr *error-output*) |
| 24 | + (t t)))) |
| 25 | + (princ object stream) |
| 26 | + (force-output stream) |
| 27 | + )) |
| 28 | + |
| 29 | +(defun qob-print (msg &rest args) |
| 30 | + "Standard output print MSG and ARGS." |
| 31 | + (apply #'qob-princ 'stdout msg args)) |
| 32 | + |
| 33 | +(defun qob-println (msg &rest args) |
| 34 | + "Like function `qob-print' but with newline at the end." |
| 35 | + (apply #'qob-print msg args) |
| 36 | + (qob-print "~%")) |
| 37 | + |
| 38 | +(defun qob-msg (msg &rest args) |
| 39 | + "Standard error print MSG and ARGS." |
| 40 | + (apply #'qob-princ 'stderr msg args) |
| 41 | + (qob-princ 'stderr "~%")) |
| 42 | + |
| 43 | +(defun qob-trace (msg &rest args) |
| 44 | + "" |
| 45 | + ;; TODO: .. |
| 46 | + (apply #'qob-msg msg args)) |
| 47 | + |
| 48 | +(defun qob-debug (msg &rest args) |
| 49 | + "" |
| 50 | + ;; TODO: .. |
| 51 | + (apply #'qob-msg msg args) |
| 52 | + ) |
| 53 | + |
| 54 | +(defun qob-info (msg &rest args) |
| 55 | + "" |
| 56 | + ;; TODO: .. |
| 57 | + (apply #'qob-msg msg args) |
| 58 | + ) |
| 59 | + |
| 60 | +(defun qob-warn (msg &rest args) |
| 61 | + "" |
| 62 | + ;; TODO: .. |
| 63 | + (apply #'qob-msg msg args) |
| 64 | + ) |
| 65 | + |
| 66 | +(defun qob-error (msg &rest args) |
| 67 | + "" |
| 68 | + ;; TODO: .. |
| 69 | + (apply #'qob-msg msg args) |
| 70 | + ) |
| 71 | + |
11 | 72 | ;;
|
12 | 73 | ;;; Environment
|
13 | 74 |
|
14 |
| -(defvar qob-dot-global (uiop:getenv "QOB_DOT_GLOBAL") |
15 |
| - "Return the global .qob directory.") |
| 75 | +(defvar qob-lisp (uiop:getenv "QOB_LISP") |
| 76 | + "Return the current lisp implementation.") |
16 | 77 |
|
17 |
| -(defvar qob-dot-local (uiop:getenv "QOB_DOT_LOCAL") |
18 |
| - "Return the local .qob directory.") |
| 78 | +(defvar qob-dot (uiop:getenv "QOB_DOT") |
| 79 | + "Return the current .qob directory.") |
19 | 80 |
|
20 |
| -(defvar qob-temp-filename (uiop:merge-pathnames* qob-dot-global "TMP") |
| 81 | +(defvar qob-temp-filename (uiop:getenv "QOB_TEMP_FILE") |
21 | 82 | "Return the temp buffer filename.")
|
22 | 83 |
|
23 |
| -(defun qob-dot () |
24 |
| - "Return the current .qob directory." |
25 |
| - (if (qob-global-p) qob-dot-global qob-dot-local)) |
| 84 | +(defvar qob-lisp-root (uiop:getenv "QOB_LISP_ROOT") |
| 85 | + "Source `lisp' directory; should always end with slash.") |
| 86 | + |
| 87 | +(defvar qob-user-init (uiop:getenv "QOB_USER_INIT") |
| 88 | + "Return the user init file.") |
| 89 | + |
| 90 | +(defvar qob-quicklisp-installed-p (uiop:getenv "QOB_QUICKLISP_INSTALLED") |
| 91 | + "Return non-nil if Quicklisp is already installed.") |
26 | 92 |
|
27 | 93 | ;;
|
28 | 94 | ;;; Flags
|
|
37 | 103 | ;; TODO: ..
|
38 | 104 | t)
|
39 | 105 |
|
| 106 | +;; |
| 107 | +;;; Elisp Layer |
| 108 | + |
| 109 | +(defun el-memq (elt list) |
| 110 | + "Mimic `memq' function." |
| 111 | + (member elt list :test #'eq)) |
| 112 | + |
40 | 113 | ;;
|
41 | 114 | ;;; Utils
|
42 | 115 |
|
|
45 | 118 | (let ((len (if (numberp len-or-list) len-or-list (length len-or-list))))
|
46 | 119 | (if (<= len 1) form-1 form-2)))
|
47 | 120 |
|
48 |
| -(defun qob-import (url) |
49 |
| - "Load and eval the script from a URL." |
50 |
| - (let ((bytes (dex:get url))) |
51 |
| - (with-open-file (out qob-temp-filename |
52 |
| - :direction :output |
53 |
| - :if-exists :supersede |
54 |
| - :if-does-not-exist :create |
55 |
| - :element-type 'unsigned-byte) |
56 |
| - (write-sequence bytes out)))) |
| 121 | +(defvar qob-loading-file-p nil |
| 122 | + "This became t; if we are loading script from another file and not expecting |
| 123 | +the `qob-start' execution.") |
| 124 | + |
| 125 | +(defun qob-script (script) |
| 126 | + "Return full SCRIPT filename." |
| 127 | + (concatenate 'string qob-lisp-root script ".lisp")) |
| 128 | + |
| 129 | +(defun qob-call (script) |
| 130 | + "Call another qob SCRIPT." |
| 131 | + (let ((script-file (qob-script script))) |
| 132 | + (when (uiop:file-exists-p script-file) |
| 133 | + (load script-file) |
| 134 | + (qob-error "Script missing %s" script-file)))) |
| 135 | + |
| 136 | +(defun qob-load (script) |
| 137 | + "Load another eask SCRIPT; so we can reuse functions across all scripts." |
| 138 | + (let ((qob-loading-file-p t)) (qob-call script))) |
57 | 139 |
|
58 | 140 | ;;
|
59 | 141 | ;;; Package
|
60 | 142 |
|
61 |
| -(defun qob-quicklisp-installed-p () |
62 |
| - "Return non-nil if Quicklisp is already installed." |
63 |
| - (uiop:file-exists-p (concatenate 'string (qob-dot) "quicklisp.lisp"))) |
64 |
| - |
65 | 143 | (defun qob-install-quicklisp ()
|
66 | 144 | "Install Quicklisp if not installed."
|
67 |
| - (alexandria:when-let ((ql (qob-quicklisp-installed-p))) |
68 |
| - (load ql) |
69 |
| - (quicklisp-quickstart:install) |
70 |
| - (ql:add-to-init-file))) |
| 145 | + (let* ((quicklisp-dir (uiop:merge-pathnames* "quicklisp/" qob-dot)) |
| 146 | + (quicklisp-init (uiop:merge-pathnames* "setup.lisp" quicklisp-dir))) |
| 147 | + (unless qob-quicklisp-installed-p |
| 148 | + (qob-quicklisp-install quicklisp-dir)) |
| 149 | + (when (probe-file quicklisp-init) |
| 150 | + (load quicklisp-init)))) |
71 | 151 |
|
72 | 152 | ;;
|
73 |
| -;;; Verbose |
74 |
| - |
75 |
| -(defun qob-princ (stream fmt &rest args) |
76 |
| - "Root print function with STREAM. |
77 |
| -
|
78 |
| -The argument STREAM is used to decide weather the stream should be standard |
79 |
| -output or standard error. |
80 |
| -
|
81 |
| -The arguments FMT and ARGS are used to form the output message." |
82 |
| - (apply #'format (case stream |
83 |
| - (`stdout *standard-output*) |
84 |
| - (`stderr *error-output*) |
85 |
| - (t t)) |
86 |
| - fmt args)) |
87 |
| - |
88 |
| -(defun qob-print (msg &rest args) |
89 |
| - "Standard output print MSG and ARGS." |
90 |
| - (apply #'qob-princ 'stdout msg args)) |
91 |
| - |
92 |
| -(defun qob-println (msg &rest args) |
93 |
| - "Like function `qob-print' but with newline at the end." |
94 |
| - (apply #'qob-print msg args) |
95 |
| - (terpri)) |
96 |
| - |
97 |
| -(defun qob-msg (msg &rest args) |
98 |
| - "Standard error print MSG and ARGS." |
99 |
| - (apply #'qob-princ 'stderr msg args) |
100 |
| - (terpri)) |
| 153 | +;;; Core |
101 | 154 |
|
102 |
| -(defun qob-info (msg &rest args) |
103 |
| - "" |
104 |
| - (qob-princ ) |
| 155 | +(defun qob-asd-test-files () |
| 156 | + "Return a list of ASD test files." |
| 157 | + (directory "*-test*.asd")) |
| 158 | + |
| 159 | +(defun qob-asd-files (&optional with-test) |
| 160 | + "Return a list of ASD files. |
| 161 | +
|
| 162 | +If optional argument WITH-TEST is non-nil; include test ASD files as well." |
| 163 | + (uiop:if-let ((files (directory "*.asd")) |
| 164 | + (_ (not with-test)) |
| 165 | + (tests (qob-asd-test-files))) |
| 166 | + (remove-if (lambda (filename) (el-memq filename tests)) files) |
| 167 | + files)) |
| 168 | + |
| 169 | +(defun qob-load-system (filename) |
| 170 | + "Load the system from ASD's FILENAME; and return the registered name." |
| 171 | + (let ((dir (uiop:pathname-parent-directory-pathname filename)) |
| 172 | + (file (pathname-name filename))) |
| 173 | + (push dir asdf:*central-registry*) |
| 174 | + (asdf:load-system file) |
| 175 | + file)) ; registered name |
| 176 | + |
| 177 | +(defun qob-find-system (name) |
| 178 | + "Return a system of given NAME." |
| 179 | + (asdf/system-registry:registered-system name)) |
| 180 | + |
| 181 | +(defun qob-setup () |
| 182 | + "Setup the system." |
| 183 | + (qob-install-quicklisp) |
| 184 | + ;; (let ((files (qob-asd-files t))) |
| 185 | + ;; (mapc (lambda (file) |
| 186 | + ;; (qob-load-system file) |
| 187 | + ;; (qob-info "Load ASD file ~A" file)) |
| 188 | + ;; files)) |
105 | 189 | )
|
106 | 190 |
|
107 | 191 | ;;
|
108 |
| -;;; Core |
| 192 | +;;; Externals |
109 | 193 |
|
110 |
| -(defmacro qob-start (&rest body) |
111 |
| - "Execute BODY with workspace setup." |
112 |
| - `(progn |
113 |
| - (push (uiop:getcwd) asdf:*central-registry*) |
114 |
| - ,@body)) |
115 |
| - |
116 |
| -;; (defun qob-setup () |
117 |
| -;; "Setup the system." |
118 |
| -;; (let ((files (asd-files t))) |
119 |
| -;; (mapc (lambda (file) |
120 |
| -;; (load-system file) |
121 |
| -;; (-info "Load ASD file ~A" file)) |
122 |
| -;; files))) |
123 |
| -;; |
124 |
| -;; (defun qob-load-system (filename) |
125 |
| -;; "Load the system from ASD's FILENAME; and return the registered name." |
126 |
| -;; (let ((dir (uiop:pathname-parent-directory-pathname filename)) |
127 |
| -;; (file (pathname-name filename))) |
128 |
| -;; (push dir asdf:*central-registry*) |
129 |
| -;; (asdf:load-system file) |
130 |
| -;; file)) ; registered name |
131 |
| -;; |
132 |
| -;; (defun qob-find-system (name) |
133 |
| -;; "Return a system of given NAME." |
134 |
| -;; (asdf/system-registry:registered-system name)) |
135 |
| -;; |
136 |
| -;; (defun qob-asd-files (&optional with-test) |
137 |
| -;; "Return a list of ASD files. |
138 |
| -;; |
139 |
| -;; If optional argument WITH-TEST is non-nil; include test ASD files as well." |
140 |
| -;; (uiop:if-let ((files (directory "*.asd")) |
141 |
| -;; (_ (not with-test)) |
142 |
| -;; (tests (asd-test-files))) |
143 |
| -;; (remove-if (lambda (filename) (el-lib:el-memq filename tests)) files) |
144 |
| -;; files)) |
145 |
| -;; |
146 |
| -;; (defun qob-asd-test-files () |
147 |
| -;; "Return a list of ASD test files." |
148 |
| -;; (directory "*-test*.asd")) |
| 194 | +;;(qob-load "extern/alexandria") |
| 195 | + |
| 196 | +;;; End of _prepare.lisp |
0 commit comments