MAP calls SB-SEQUENCE:MAP for extended sequences
[sbcl.git] / tools-for-build / wxs.lisp
blobd015b731280e7269da8029638e92021fb5d75374
1 ;;;; Generate WiX XML Source, from which we eventually generate the .MSI
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 ;;;; XML generation
14 (defvar *indent-level* 0)
16 (defvar *sbcl-source-root*
17 (truename
18 (merge-pathnames (make-pathname :directory (list :relative :up))
19 (make-pathname :name nil :type nil :defaults *load-truename*))))
21 (defun print-xml (sexp &optional (stream *standard-output*))
22 (destructuring-bind (tag &optional attributes &body children) sexp
23 (when attributes (assert (evenp (length attributes))))
24 (format stream "~VT<~A~{ ~A='~A'~}~@[/~]>~%"
25 *indent-level* tag attributes (not children))
26 (let ((*indent-level* (+ *indent-level* 3)))
27 (dolist (child children)
28 (unless (listp child)
29 (error "Malformed child: ~S in ~S" child children))
30 (print-xml child stream)))
31 (when children
32 (format stream "~VT</~A>~%" *indent-level* tag))))
34 (defun xml-1.0 (pathname sexp)
35 (with-open-file (xml pathname :direction :output :if-exists :supersede
36 :external-format :ascii)
37 (format xml "<?xml version='1.0'?>")
38 (print-xml sexp xml)))
40 (defun application-name ()
41 (format nil "Steel Bank Common Lisp ~A (~A)" (lisp-implementation-version) (machine-type)))
43 (defun version-digits (&optional (horrible-thing (lisp-implementation-version)))
44 "Turns something like 0.pre7.14.flaky4.13 (see version.lisp-expr)
45 into an acceptable form for WIX (up to four dot-separated numbers)."
46 (with-output-to-string (output)
47 (loop repeat 4
48 with position = 0
49 for separator = "" then "."
50 for next-digit = (position-if #'digit-char-p horrible-thing
51 :start position)
52 while next-digit
53 do (multiple-value-bind (number end)
54 (parse-integer horrible-thing :start next-digit :junk-allowed t)
55 (format output "~A~D" separator number)
56 (setf position end)))))
58 ;;;; GUID generation
59 ;;;;
60 ;;;; Apparently this willy-nilly regeneration of GUIDs is a bad thing, and
61 ;;;; we should probably have a single GUID per release / Component, so
62 ;;;; that no matter by whom the .MSI is built the GUIDs are the same.
63 ;;;;
64 ;;;; Something to twiddle on a rainy day, I think.
66 (load-shared-object "OLE32.DLL")
68 (define-alien-type uuid
69 (struct uuid
70 (data1 unsigned-int)
71 (data2 unsigned-short)
72 (data3 unsigned-short)
73 (data4 (array unsigned-char 8))))
75 (define-alien-routine ("CoCreateGuid" co-create-guid) int (guid (* uuid)))
77 (defun uuid-string (uuid)
78 (declare (type (alien (* uuid)) uuid))
79 (let ((data4 (slot uuid 'data4)))
80 (format nil "~8,'0X-~4,'0X-~4,'0X-~2,'0X~2,'0X-~{~2,'0X~}"
81 (slot uuid 'data1)
82 (slot uuid 'data2)
83 (slot uuid 'data3)
84 (deref data4 0)
85 (deref data4 1)
86 (loop for i from 2 upto 7 collect (deref data4 i)))))
88 (defun make-guid ()
89 (let (guid)
90 (unwind-protect
91 (progn
92 (setf guid (make-alien (struct uuid)))
93 (co-create-guid guid)
94 (uuid-string guid))
95 (free-alien guid))))
97 (defvar *id-char-substitutions* '((#\\ . #\_)
98 (#\/ . #\_)
99 (#\: . #\.)
100 (#\- . #\.)))
102 (defun id (string)
103 ;; Mangle a string till it can be used as an Id. A-Z, a-z, 0-9, and
104 ;; _ are ok, nothing else is.
105 (map 'string (lambda (c)
106 (or (cdr (assoc c *id-char-substitutions*))
108 string))
110 (defun directory-id (name)
111 (id (format nil "Directory_~A" (enough-namestring name *sbcl-source-root*))))
113 (defun file-id (pathname)
114 (id (format nil "File_~A" (enough-namestring pathname *sbcl-source-root*))))
116 (defparameter *ignored-directories* '("CVS" ".svn" "test-output"))
118 (defparameter *pathname-type-abbrevs*
119 '(("lisp" . "lsp")
120 ("fasl" . "fas")
121 ("SBCL" . "txt") ; README.SBCL -> README.txt
122 ("texinfo" . "tfo")
123 ("lisp-temp" . "lmp")
124 ("html" . "htm")))
126 (defparameter *components* nil)
128 (defun component-id (pathname)
129 (let ((id (id (format nil "Contrib_~A" (enough-namestring pathname *sbcl-source-root*)))))
130 (push id *components*)
131 id))
133 (defun ref-all-components ()
134 (prog1
135 (mapcar (lambda (id)
136 `("ComponentRef" ("Id" ,id)))
137 *components*)
138 (setf *components* nil)))
140 (defun collect-1-component (root)
141 `("Directory" ("Name" ,(car (last (pathname-directory root)))
142 "Id" ,(directory-id root))
143 ("Component" ("Id" ,(component-id root)
144 "Guid" ,(make-guid)
145 "DiskId" 1)
146 ,@(loop for file in (directory
147 (make-pathname :name :wild :type :wild :defaults root))
148 when (or (pathname-name file) (pathname-type file))
149 collect `("File" ("Name" ,(file-namestring file)
150 "Id" ,(file-id file)
151 "Source" ,(enough-namestring file)))))))
153 (defun directory-empty-p (dir)
154 (null (directory (make-pathname :name :wild :type :wild :defaults dir))))
156 (defun collect-components (root)
157 (append (unless (directory-empty-p root) (list (collect-1-component root)))
158 (loop for directory in
159 (directory
160 (merge-pathnames (make-pathname
161 :directory '(:relative :wild)
162 :name nil :type nil)
163 root))
164 unless (member (car (last (pathname-directory directory)))
165 *ignored-directories* :test #'equal)
166 append (collect-components directory))))
168 (defun collect-contrib-components ()
169 (collect-components "../obj/sbcl-home/contrib/"))
171 (defun make-extension (type mime)
172 `("Extension" ("Id" ,type "ContentType" ,mime)
173 ("Verb" ("Id" ,(format nil "load_~A" type)
174 "Argument" "--core \"[#sbcl.core]\" --load \"%1\""
175 "Command" "Load with SBCL"
176 "Target" "[#sbcl.exe]"))))
178 (defun write-wxs (pathname)
179 ;; both :INVERT and :PRESERVE could be used here, but this seemed
180 ;; better at the time
181 (xml-1.0
182 pathname
183 `("Wix" ("xmlns" "http://schemas.microsoft.com/wix/2006/wi")
184 ("Product" ("Id" "*"
185 "Name" ,(application-name)
186 "Version" ,(version-digits)
187 "Manufacturer" "http://www.sbcl.org"
188 "UpgradeCode" "BFF1D4CA-0153-4AAC-BB21-06DC4B8EAD7D"
189 "Language" 1033)
190 ("Package" ("Id" "*"
191 "Manufacturer" "http://www.sbcl.org"
192 "InstallerVersion" 200
193 "Compressed" "yes"
194 #+x86-64 "Platform" #+x86-64 "x64"
195 "InstallScope" "perMachine"))
196 ("Media" ("Id" 1
197 "Cabinet" "sbcl.cab"
198 "EmbedCab" "yes"))
199 ("Property" ("Id" "PREVIOUSVERSIONSINSTALLED"
200 "Secure" "yes"))
201 ("Upgrade" ("Id" "BFF1D4CA-0153-4AAC-BB21-06DC4B8EAD7D")
202 ("UpgradeVersion" ("Minimum" "1.0.0"
203 "Maximum" "99.0.0"
204 "Property" "PREVIOUSVERSIONSINSTALLED"
205 "IncludeMinimum" "yes"
206 "IncludeMaximum" "no")))
207 ("InstallExecuteSequence" ()
208 ("RemoveExistingProducts" ("After" "InstallInitialize")))
209 ("Directory" ("Id" "TARGETDIR"
210 "Name" "SourceDir")
211 ("Directory" ("Id" "ProgramMenuFolder")
212 ("Component" ("Id" "SBCL_Shortcut"
213 "Guid" ,(make-guid))
214 ("Shortcut" ("Id" "sbcl.lnk"
215 "Name" ,(application-name)
216 "Target" "[INSTALLDIR]sbcl.exe"
217 "Arguments" "--core \"[#sbcl.core]\""))
218 ("RegistryValue" ("Root" "HKCU"
219 "Key" ,(application-name)
220 "Name" "installed"
221 "Type" "integer"
222 "Value" "1"
223 "KeyPath" "yes"))))
224 ("Directory" ("Id" #-x86-64 "ProgramFilesFolder" #+x86-64 "ProgramFiles64Folder"
225 "Name" "PFiles")
226 ("Directory" ("Id" "BaseFolder"
227 "Name" "Steel Bank Common Lisp")
228 ("Directory" ("Id" "VersionFolder"
229 "Name" ,(lisp-implementation-version))
230 ("Directory" ("Id" "INSTALLDIR")
231 ("Component" ("Id" "SBCL_SetHOME"
232 "Guid" ,(make-guid)
233 "DiskId" 1)
234 ("Environment" ("Id" "Env_SBCL_HOME"
235 "System" "yes"
236 "Action" "set"
237 "Name" "SBCL_HOME"
238 "Part" "all"
239 "Value" "[INSTALLDIR]")))
241 ("Component" ("Id" "SBCL_SetPATH"
242 "Guid" ,(make-guid)
243 "DiskId" 1)
244 ("Environment" ("Id" "Env_PATH"
245 "System" "yes"
246 "Action" "set"
247 "Name" "PATH"
248 "Part" "last"
249 "Value" "[INSTALLDIR]")))
250 ("Component" ("Id" "SBCL_Base"
251 "Guid" ,(make-guid)
252 "DiskId" 1)
253 ;; If we want to associate files with SBCL, this
254 ;; is how it's done -- but doing this by default
255 ;; and without asking the user for permission Is
256 ;; Bad. Before this is enabled we need to figure out
257 ;; how to make WiX ask for permission for this...
258 ;; ,(make-extension "fasl" "application/x-lisp-fasl")
259 ;; ,(make-extension "lisp" "text/x-lisp-source")
260 ("File" ("Name" "sbcl.exe"
261 "Source" "../src/runtime/sbcl.exe"))
262 ("File" ("Name" "sbcl.core"
263 "Source" "sbcl.core")))
264 ,@(collect-contrib-components))))))
265 ("Feature" ("Id" "Minimal"
266 "Title" "SBCL Executable"
267 "ConfigurableDirectory" "INSTALLDIR"
268 "Level" 1)
269 ("ComponentRef" ("Id" "SBCL_Base"))
270 ("Feature" ("Id" "Contrib" "Level" 1 "Title" "Contributed Modules")
271 ,@(ref-all-components))
272 ("Feature" ("Id" "Shortcut" "Level" 1 "Title" "Add Start Menu Shortcut")
273 ("ComponentRef" ("Id" "SBCL_Shortcut")))
274 ("Feature" ("Id" "SetPath" "Level" 1 "Title" "Set Environment Variable: PATH")
275 ("ComponentRef" ("Id" "SBCL_SetPATH")))
276 ;; SetHome is still enabled by default (level 1), because SBCL
277 ;; does not yet support running without SBCL_HOME:
278 ("Feature" ("Id" "SetHome" "Level" 1 "Title" "Set Environment Variable: SBCL_HOME")
279 ("ComponentRef" ("Id" "SBCL_SetHOME"))))
280 ("WixVariable" ("Id" "WixUILicenseRtf"
281 "Value" "License.rtf"))
282 ("Property" ("Id" "WIXUI_INSTALLDIR" "Value" "INSTALLDIR"))
283 ("UIRef" ("Id" "WixUI_FeatureTree"))))))