changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > demo / tools/prepare-image.lisp

changeset 26: 2015d7277629
child: aa37feddcfb2
author: ellis <ellis@rwest.io>
date: Mon, 05 Jun 2023 19:59:26 -0400
permissions: -rw-r--r--
description: refactor 01
1 (in-package :cl-user)
2 
3 ;; For SBCL, if you don't have SBCL_HOME set, then we won't be able to require this later.
4 #+sbcl
5 (require 'sb-introspect)
6 
7 (when (probe-file "scripts/asdf.lisp")
8  (format t "Compiling asdf..~%")
9  (let ((output (compile-file "scripts/asdf.lisp" :verbose nil :print nil)))
10  (load output))
11  (provide "asdf"))
12 
13 (require "asdf")
14 
15 #+sbcl
16 (require "sb-sprof")
17 
18 #+nil
19 (push (pathname (format nil "~a/local-projects/poiu/" (namestring (uiop:getcwd))))
20  asdf:*central-registry*)
21 
22 (defvar *asdf-root-guesser* nil)
23 
24 (defparameter *cwd* (merge-pathnames
25  *default-pathname-defaults*
26  (uiop:getcwd)))
27 
28 (defun update-output-translations (root)
29  "This function is called dynamically from deliver-utils/common.lisp!"
30  (asdf:initialize-output-translations
31  `(:output-translations
32  :inherit-configuration
33  (,(namestring root)
34  ,(format nil "~abuild/asdf-cache/~a/" root
35  (uiop:implementation-identifier))))))
36 
37 (update-output-translations *cwd*)
38 
39 #+sbcl
40 (progn
41  (require :sb-rotate-byte)
42  (require :sb-cltl2)
43  (asdf:register-preloaded-system :sb-rotate-byte)
44  (asdf:register-preloaded-system :sb-cltl2))
45 
46 (defun %read-version (file)
47  (let ((key "version: "))
48  (loop for line in (uiop:read-file-lines file)
49  if (string= key line :end2 (length key))
50  return (subseq line (length key)))))
51 
52 (defun init-quicklisp ()
53  (let ((version (%read-version "quicklisp/dists/quicklisp/distinfo.txt")))
54  (let ((quicklisp-loc (ensure-directories-exist
55  (merge-pathnames
56  (format nil "build/quicklisp/~a/" version)
57  *cwd*)))
58  (src (merge-pathnames
59  "quicklisp/"
60  *cwd*)))
61  (flet ((safe-copy-file (path &optional (dest path))
62  (let ((src (merge-pathnames
63  path
64  "quicklisp/"))
65  (dest (merge-pathnames
66  dest
67  quicklisp-loc)))
68  (format t "Copying: ~a to ~a~%" src dest)
69 
70  (when (equal src dest)
71  (error "Trying to overwrite the same file"))
72  (unless (uiop:file-exists-p dest)
73  (uiop:copy-file
74  src
75  (ensure-directories-exist
76  dest))))))
77  (loop for name in
78  (append (directory
79  (merge-pathnames
80  "quicklisp/quicklisp/*.lisp"
81  *cwd*))
82  (directory
83  (merge-pathnames
84  "quicklisp/quicklisp/*.asd"
85  *cwd*)))
86  do (safe-copy-file name
87  (format nil "quicklisp/~a.~a"
88  (pathname-name name)
89  (pathname-type name))))
90  (loop for name in (directory
91  (merge-pathnames
92  "quicklisp/*.lisp"
93  *cwd*))
94  do (safe-copy-file name
95  (format nil "~a.lisp"
96  (pathname-name name))))
97  (safe-copy-file "setup.lisp")
98  (safe-copy-file "quicklisp/version.txt")
99  (safe-copy-file "dists/quicklisp/distinfo.txt")
100  (safe-copy-file "dists/quicklisp/enabled.txt")
101  (safe-copy-file "dists/quicklisp/preference.txt"))
102  (load (merge-pathnames
103  "setup.lisp"
104  quicklisp-loc)))))
105 
106 (init-quicklisp)
107 
108 #+nil
109 (ql:update-all-dists :prompt nil)
110 
111 (pushnew :demo *features*)
112 
113 (defun update-project-directories (cwd)
114  (flet ((push-src-dir (name)
115  (let ((dir (pathname (format nil "~a~a/" cwd name))))
116  (when (probe-file dir)
117  (push dir ql:*local-project-directories*)))))
118  #-demo
119  (push-src-dir "local-projects")
120  (push-src-dir "src")
121  (push-src-dir "third-party")
122  (push-src-dir "lisp")))
123 
124 
125 (defun update-root (cwd)
126  (update-output-translations cwd)
127  (update-project-directories cwd))
128 
129 (update-project-directories *cwd*)
130 
131 (defun maybe-asdf-prepare ()
132  (when *asdf-root-guesser*
133  (update-root (funcall *asdf-root-guesser*))))
134 
135 (compile 'maybe-asdf-prepare)
136 
137 (defun unprepare-asdf (root-guesser)
138  "This function is called dynamically from deliver-utils/common.lisp!"
139  (setf *asdf-root-guesser* root-guesser))
140 
141 (defun maybe-configure-proxy ()
142  (let ((proxy (uiop:getenv "HTTP_PROXY")))
143  (when (and proxy (> (length proxy) 0))
144  (setf ql:*proxy-url* proxy))))
145 
146 (maybe-configure-proxy)
147 
148 
149 (ql:quickload "log4cl")
150 (ql:quickload "prove-asdf")
151 
152 (log:info "*local-project-directories: ~S" ql:*local-project-directories*)
153 
154 ;; (ql:quickload :cl-ppcre)
155 ;; make sure we have build asd
156 #+nil
157 (push (pathname (format nil "~a/build-utils/" *cwd*))
158  asdf:*central-registry*)
159 (ql:register-local-projects)