build-wxs.lisp 7.82 KB
Newer Older
Eric Timmons's avatar
Eric Timmons committed
1
2
3
4
5
6
7
8
9
10
11
12
;;;; Builds a WiX XML file for building an MSI installer
;;;;
;;;; This software is part of CLPM. See README.org for more information. See
;;;; LICENSE for license information.

(in-package #:cl-user)

(load (merge-pathnames "common.lisp"
                       *load-truename*))

(in-package #:clpm-scripts)

Eric Timmons's avatar
Eric Timmons committed
13
14
(load (merge-pathnames "../logical-pathname.lisp" *load-truename*))

Eric Timmons's avatar
Eric Timmons committed
15
16
17
(setup-asdf "default")

(asdf:load-system :s-xml)
18
(asdf:load-system :uuid)
Eric Timmons's avatar
Eric Timmons committed
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(defun gen-uuid ()
  (format nil "~A" (uuid:make-v4-uuid)))

(defun sanitize-id (id)
  (substitute #\_ #\- id))

(defun directory-tree (pn component-base-id file-base-id dir-base-id)
  (let* ((files (directory (merge-pathnames "*.*" pn)))
         (dirs (directory (merge-pathnames "*/" pn)))
         (dir-name (car (last (pathname-directory pn))))
         (dir-id (uiop:strcat dir-base-id "." dir-name))
         (out `(("Directory" "Name" ,dir-name "Id" ,(sanitize-id dir-id))))
         (component-name (sanitize-id (uiop:strcat component-base-id "_" dir-name)))
         (component-names (list component-name))
         (component (list (list (list "CreateFolder"))
                          (list "Component"
                                "Id" component-name
                                "Guid" (gen-uuid)
                                "DiskId" "1"
                                "Win64" "yes"))))
40
41
42
43
44
    (dolist (file files)
      (unless (or (uiop:directory-pathname-p file)
                  (equal "fasl" (pathname-type file)))
        (let ((enough (enough-namestring file pn)))
          (push `(("File" "Name" ,enough
45
                          "Id" ,(sanitize-id (uiop:strcat file-base-id "." dir-name "." enough))
46
                          "Source" ,(enough-namestring file *build-root-pathname*)))
47
48
                component))))
    (push (nreverse component) out)
49
    (dolist (dir dirs)
50
51
52
53
54
      (multiple-value-bind (subdir-tree sub-component-names)
          (directory-tree dir component-name (uiop:strcat file-base-id "." dir-name) dir-id)
        (setf component-names (append sub-component-names component-names))
        (push subdir-tree out)))
    (values (nreverse out) component-names)))
55

56
57
58
59
60
61
62
63
64
65
66
(defun directory-files (pn)
  (let ((files (directory (merge-pathnames "*.*" pn)))
        (out))
    (dolist (file files)
      (unless (or (uiop:directory-pathname-p file)
                  (equal "fasl" (pathname-type file)))
        (push `(("File" "Name" ,(enough-namestring file pn)
                        "Source" ,(enough-namestring file *build-root-pathname*)))
              out)))
    out))

Eric Timmons's avatar
Eric Timmons committed
67
(defun build-wxs ()
68
69
70
71
72
73
  (multiple-value-bind (src-dir-tree src-dir-component-names)
      (directory-tree (merge-pathnames "lib/clpm/src/clpm/" *build-root-pathname*)
                      "CLPM_Src" "CLPM_SrcFile" "CLPM_SrcDir")
    `(("Wix" "xmlns" "http://schemas.microsoft.com/wix/2006/wi")
      (("Product" "Id" "*"
                  "Name" "Common Lisp Package Manager (CLPM)"
Eric Timmons's avatar
Eric Timmons committed
74
                  "Version" "0.3.0-alpha.4"
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
                  "Manufacturer" "https://www.clpm.dev"
                  "UpgradeCode" "D499FD17-A05C-41F8-837E-8B1BF4C4403B"
                  "Language" "1033")
       (("Package" "Id" "*"
                   "Manufacturer" "https://www.clpm.dev"
                   "InstallerVersion" "200"
                   "Compressed" "yes"
                   "Platform" "x64"
                   "InstallScope" "perMachine"))
       (("Media" "Id" "1"
                 "Cabinet" "clpm.cab"
                 "EmbedCab" "yes"))
       (("Property" "Id" "PREVIOUSVERSIONSINSTALLED"
                    "Secure" "yes"))
       (("Upgrade" "Id" "D499FD17-A05C-41F8-837E-8B1BF4C4403B")
        (("UpgradeVersion" "Minimum" "0.1.0"
                           "Maximum" "99.0.0"
                           "Property" "PREVIOUSVERSIONSINSTALLED"
                           "IncludeMinimum" "yes"
                           "IncludeMaximum" "no")))
       (("InstallExecuteSequence")
        (("RemoveExistingProducts" "After" "InstallInitialize")))

       (("Directory" "Id" "TARGETDIR"
                     "Name" "SourceDir")
        (("Directory" "Id" "ProgramFiles64Folder"
                      "Name" "PFiles")
         (("Directory" "Id" "BaseFolder"
                       "Name" "CLPM")
          (("Directory" "Id" "VersionFolder"
Eric Timmons's avatar
Eric Timmons committed
105
                        "Name" "v0.3.0-alpha.4")
106
107
108
109
110
           (("Directory" "Id" "INSTALLDIR")
            (("Directory" "Id" "BINDIR"
                          "Name" "bin")
             (("Component" "Id" "CLPM_SetPATH"
                           "Guid" "5514D118-8FAD-497C-ACFB-BAC6C0161E69"
Eric Timmons's avatar
Eric Timmons committed
111
112
                           "DiskId" "1"
                           "Win64" "yes")
113
114
115
116
117
118
119
120
121
              (("CreateFolder"))
              (("Environment" "Id" "Env_PATH"
                              "System" "yes"
                              "Action" "set"
                              "Name" "PATH"
                              "Part" "last"
                              "Value" "[BINDIR]")))
             (("Component" "Id" "CLPM_Bin"
                           "Guid" "E7F4D949-DEBC-4FF9-9D60-D455BC11F606"
Eric Timmons's avatar
Eric Timmons committed
122
123
                           "DiskId" "1"
                           "Win64" "yes")
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
              (("File" "Name" "clpm.exe"
                       "Source" "bin/clpm.exe"))))

            (("Directory" "Id" "LIBDIR"
                          "Name" "lib")
             (("Component" "Id" "CLPM_Libs"
                           "Guid" "35C91C7A-ED22-40B5-A761-730C57CCF803"
                           "DiskId" "1"
                           "Win64" "yes")
              (("CreateFolder"))
              ,@(directory-files (merge-pathnames "lib/clpm/" *build-root-pathname*)))
             (("Component" "Id" "CLPM_SetHOME"
                           "Guid" "E75E9C41-C6B9-44FE-90B3-8055B22341D0"
                           "DiskId" "1"
                           "Win64" "yes")
              (("CreateFolder"))
              (("Environment" "Id" "Env_CLPM_HOME"
                              "System" "yes"
                              "Action" "set"
                              "Name" "CLPM_HOME"
                              "Part" "all"
                              "Value" "[LIBDIR]")))
             (("Directory" "Id" "SrcDir"
                           "Name" "src")
              (("Directory" "Id" "ClientDir"
                            "Name" "clpm-client")
               (("Component" "Id" "CLPM_Client"
                             "Guid" "6B847710-C813-4E8E-861B-7C0B767F4C36"
                             "DiskId" "1"
                             "Win64" "yes")
                ,@(directory-files (merge-pathnames "lib/clpm/src/clpm-client/" *build-root-pathname*))))
              ,src-dir-tree)))))))

       (("Feature" "Id" "Minimal"
                   "Title" "CLPM Executable"
                   "ConfigurableDirectory" "INSTALLDIR"
                   "Level" "1")
        (("ComponentRef" "Id" "CLPM_Bin"))
        (("ComponentRef" "Id" "CLPM_Libs"))
        (("ComponentRef" "Id" "CLPM_Client"))
        ,@(mapcar (lambda (id) `(("ComponentRef" "Id" ,id))) src-dir-component-names)
        (("Feature" "Id" "SetPath"
                    "Level" "1"
                    "Title" "Set Environment Variable: PATH")
         (("ComponentRef" "Id" "CLPM_SetPATH")))
        (("Feature" "Id" "SetHome"
                    "Level" "1"
                    "Title" "Set Environment Variable: CLPM_HOME")
         (("ComponentRef" "Id" "CLPM_SetHOME"))))
       (("WixVariable" "Id" "WixUILicenseRtf"
                       "Value" "License.rtf"))
       (("Property" "Id" "WIXUI_INSTALLDIR"
                    "Value" "INSTALLDIR"))
       (("UIRef" "Id" "WixUI_FeatureTree"))))))
Eric Timmons's avatar
Eric Timmons committed
178
179

(defun write-wxs ()
180
  (with-open-file (s (merge-pathnames "clpm.wxs" *build-root-pathname*)
Eric Timmons's avatar
Eric Timmons committed
181
182
183
184
                   :if-exists :supersede :direction :output)
    (format s "<?xml version='1.0'?>~%")
    (s-xml:print-xml (build-wxs) :stream s :pretty t)))

185
(print (build-wxs))
Eric Timmons's avatar
Eric Timmons committed
186
(write-wxs)