Adapt to the new version of WiX.
[sbcl.git] / tools-for-build / wxs.lisp
blob45a23a036729f83a0157ec7613214a56dc8b9a38
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 #+x86-64 "Win64" #+x86-64 "yes")
147 ,@(loop for file in (directory
148 (make-pathname :name :wild :type :wild :defaults root))
149 when (or (pathname-name file) (pathname-type file))
150 collect `("File" ("Name" ,(file-namestring file)
151 "Id" ,(file-id file)
152 "Source" ,(enough-namestring file)))))))
154 (defun directory-empty-p (dir)
155 (null (directory (make-pathname :name :wild :type :wild :defaults dir))))
157 (defun collect-components (root)
158 (append (unless (directory-empty-p root) (list (collect-1-component root)))
159 (loop for directory in
160 (directory
161 (merge-pathnames (make-pathname
162 :directory '(:relative :wild)
163 :name nil :type nil)
164 root))
165 unless (member (car (last (pathname-directory directory)))
166 *ignored-directories* :test #'equal)
167 append (collect-components directory))))
169 (defun collect-contrib-components ()
170 (collect-components "../obj/sbcl-home/contrib/"))
172 (defun make-extension (type mime)
173 `("Extension" ("Id" ,type "ContentType" ,mime)
174 ("Verb" ("Id" ,(format nil "load_~A" type)
175 "Argument" "--core \"[#sbcl.core]\" --load \"%1\""
176 "Command" "Load with SBCL"
177 "Target" "[#sbcl.exe]"))))
179 (defun write-wxs (pathname)
180 ;; both :INVERT and :PRESERVE could be used here, but this seemed
181 ;; better at the time
182 (xml-1.0
183 pathname
184 `("Wix" ("xmlns" "http://schemas.microsoft.com/wix/2006/wi")
185 ("Product" ("Id" "*"
186 "Name" ,(application-name)
187 "Version" ,(version-digits)
188 "Manufacturer" "http://www.sbcl.org"
189 "UpgradeCode" "BFF1D4CA-0153-4AAC-BB21-06DC4B8EAD7D"
190 "Language" 1033)
191 ("Package" ("Id" "*"
192 "Manufacturer" "http://www.sbcl.org"
193 "InstallerVersion" 200
194 "Compressed" "yes"
195 #+x86-64 "Platform" #+x86-64 "x64"
196 "InstallScope" "perMachine"))
197 ("Media" ("Id" 1
198 "Cabinet" "sbcl.cab"
199 "EmbedCab" "yes"))
200 ("Property" ("Id" "PREVIOUSVERSIONSINSTALLED"
201 "Secure" "yes"))
202 ("Upgrade" ("Id" "BFF1D4CA-0153-4AAC-BB21-06DC4B8EAD7D")
203 ("UpgradeVersion" ("Minimum" "1.0.0"
204 "Maximum" "99.0.0"
205 "Property" "PREVIOUSVERSIONSINSTALLED"
206 "IncludeMinimum" "yes"
207 "IncludeMaximum" "no")))
208 ("InstallExecuteSequence" ()
209 ("RemoveExistingProducts" ("After" "InstallInitialize")))
210 ("Directory" ("Id" "TARGETDIR"
211 "Name" "SourceDir")
212 ("Directory" ("Id" "ProgramMenuFolder")
213 ("Directory" ("Id" "ProgramMenuDir"
214 "Name" ,(application-name))
215 ("Component" ("Id" "ProgramMenuDir"
216 "Guid" ,(make-guid))
217 ("RemoveFolder" ("Id" "ProgramMenuDir"
218 "On" "uninstall"))
219 ("RegistryValue" ("Root" "HKCU"
220 "Key" "Software\[Manufacturer]\[ProductName]"
221 "Type" "string"
222 "Value" ""
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 #+x86-64 "Win64" #+x86-64 "yes")
235 ("CreateFolder")
236 ("Environment" ("Id" "Env_SBCL_HOME"
237 "System" "yes"
238 "Action" "set"
239 "Name" "SBCL_HOME"
240 "Part" "all"
241 "Value" "[INSTALLDIR]")))
243 ("Component" ("Id" "SBCL_SetPATH"
244 "Guid" ,(make-guid)
245 "DiskId" 1
246 #+x86-64 "Win64" #+x86-64 "yes")
247 ("CreateFolder")
248 ("Environment" ("Id" "Env_PATH"
249 "System" "yes"
250 "Action" "set"
251 "Name" "PATH"
252 "Part" "last"
253 "Value" "[INSTALLDIR]")))
254 ("Component" ("Id" "SBCL_Base"
255 "Guid" ,(make-guid)
256 "DiskId" 1
257 #+x86-64 "Win64" #+x86-64 "yes")
258 ;; If we want to associate files with SBCL, this
259 ;; is how it's done -- but doing this by default
260 ;; and without asking the user for permission Is
261 ;; Bad. Before this is enabled we need to figure out
262 ;; how to make WiX ask for permission for this...
263 ;; ,(make-extension "fasl" "application/x-lisp-fasl")
264 ;; ,(make-extension "lisp" "text/x-lisp-source")
265 ("File" ("Name" "sbcl.core"
266 "Source" "sbcl.core"))
267 ("File" ("Name" "sbcl.exe"
268 "Source" "../src/runtime/sbcl.exe"
269 "KeyPath" "yes")
270 ("Shortcut" ("Id" "sbcl.lnk"
271 "Advertise" "yes"
272 "Name" ,(application-name)
273 "Directory" "ProgramMenuDir"
274 "Arguments" "--core \"[#sbcl.core]\""))))
275 ,@(collect-contrib-components))))))
276 ("Feature" ("Id" "Minimal"
277 "Title" "SBCL Executable"
278 "ConfigurableDirectory" "INSTALLDIR"
279 "Level" 1)
280 ("ComponentRef" ("Id" "SBCL_Base"))
281 ("ComponentRef" ("Id" "ProgramMenuDir"))
282 ("Feature" ("Id" "Contrib" "Level" 1 "Title" "Contributed Modules")
283 ,@(ref-all-components))
284 ("Feature" ("Id" "SetPath" "Level" 1 "Title" "Set Environment Variable: PATH")
285 ("ComponentRef" ("Id" "SBCL_SetPATH")))
286 ;; SetHome is still enabled by default (level 1), because SBCL
287 ;; does not yet support running without SBCL_HOME:
288 ("Feature" ("Id" "SetHome" "Level" 1 "Title" "Set Environment Variable: SBCL_HOME")
289 ("ComponentRef" ("Id" "SBCL_SetHOME"))))
290 ("WixVariable" ("Id" "WixUILicenseRtf"
291 "Value" "License.rtf"))
292 ("Property" ("Id" "WIXUI_INSTALLDIR" "Value" "INSTALLDIR"))
293 ("UIRef" ("Id" "WixUI_FeatureTree"))))))