21
21
import (" lib.detect.find_tool" )
22
22
import (" private.action.require.impl.packagenv" )
23
23
import (" private.action.require.impl.install_packages" )
24
-
25
24
import (" .batchcmds" )
26
25
27
26
-- get the wixtoolset
@@ -65,7 +64,7 @@ function _to_rtf_string(str)
65
64
escape_text = escape_text :gsub (" }" , " \\ }" )
66
65
67
66
local rtf = " {\\ rtf1\\ ansi{\\ fonttbl\\ f0\\ fswiss Helvetica;}\\ f0\\ pard " ;
68
- rtf = rtf .. escape_text :gsub (" \r\n " , " \\ par " ) .. " }"
67
+ rtf = rtf .. escape_text :gsub (" \r\n " , " \\ par " ) .. " }"
69
68
return rtf
70
69
end
71
70
@@ -78,7 +77,7 @@ function _get_cp_kind_table(package, cmds, opt)
78
77
if cmd .kind ~= " cp" then
79
78
goto continue
80
79
end
81
-
80
+
82
81
local option = table .join (cmd .opt or {}, opt )
83
82
local srcfiles = os .files (cmd .srcpath )
84
83
for _ , srcfile in ipairs (srcfiles ) do
@@ -111,19 +110,16 @@ function _get_other_commands(package, cmd, opt)
111
110
opt = table .join (cmd .opt or {}, opt )
112
111
local result = " "
113
112
local kind = cmd .kind
114
-
115
113
if kind == " rm" then
116
114
local subdirectory = _translate_filepath (package , path .directory (cmd .filepath ))
117
115
subdirectory = subdirectory ~= " ." and string.format ([[ Subdirectory="%s"]] , subdirectory ) or " "
118
116
local on = opt .install and [[ On="install"]] or [[ On="uninstall"]]
119
117
local filename = path .filename (cmd .filepath )
120
-
121
118
result = string.format ([[ <RemoveFile Directory="INSTALLFOLDER" Name="%s" %s %s/>]] , filename , subdirectory , on )
122
119
elseif kind == " rmdir" then
123
120
local dir = _translate_filepath (package , cmd .dir )
124
121
local subdirectory = dir ~= " ." and string.format ([[ Subdirectory="%s"]] , dir ) or " "
125
122
local on = opt .install and [[ On="install"]] or [[ On="uninstall"]]
126
-
127
123
result = string.format ([[ <RemoveFolder Directory="INSTALLFOLDER" %s %s/>]] , subdirectory , on )
128
124
elseif kind == " mkdir" then
129
125
local dir = _translate_filepath (package , cmd .dir )
@@ -148,9 +144,9 @@ function _get_feature_string(name, title, opt)
148
144
end
149
145
150
146
function _get_component_string (id , subdirectory )
151
- local subdirectory = (subdirectory ~= " ." and subdirectory ~= nil ) and string.format ([[ Subdirectory="%s"]] , subdirectory ) or " "
147
+ local subdirectory = (subdirectory ~= " ." and subdirectory ~= nil ) and string.format ([[ Subdirectory="%s"]] , subdirectory ) or " "
152
148
return string.format ([[ <Component Id="%s" Guid="%s" Directory="INSTALLFOLDER" %s>]] , id :gsub (" " , " " ), hash .uuid (id ), subdirectory )
153
- end
149
+ end
154
150
155
151
-- for each id/guid in the file wix want them to be unique
156
152
-- so compute a hash for each directory based on the file that are inside
@@ -178,12 +174,11 @@ function _build_feature(package, opt)
178
174
179
175
local installcmds = batchcmds .get_installcmds (package ):cmds ()
180
176
local uninstallcmds = batchcmds .get_uninstallcmds (package ):cmds ()
181
-
177
+
182
178
local cp_table = _get_cp_kind_table (package , installcmds , opt )
183
179
table .remove_if (installcmds , function (_ , cmd ) return cmd .kind == " cp" end )
184
180
185
181
local dir_id = _get_dir_id (cp_table )
186
-
187
182
for dir , files in pairs (cp_table ) do
188
183
table.insert (result , _get_component_string (dir_id [dir ], dir ))
189
184
for _ , file in ipairs (files ) do
@@ -192,7 +187,7 @@ function _build_feature(package, opt)
192
187
table.insert (result , string.format ([[ <File Source="%s" Name="%s"/>]] , srcfile , dstname ))
193
188
end
194
189
table.insert (result , " </Component>" )
195
- end
190
+ end
196
191
197
192
table.insert (result , _get_component_string (name .. " Cmds" ))
198
193
for _ , cmd in ipairs (installcmds ) do
@@ -201,7 +196,7 @@ function _build_feature(package, opt)
201
196
for _ , cmd in ipairs (uninstallcmds ) do
202
197
table.insert (result , _get_other_commands (package , cmd , {install = false }))
203
198
end
204
-
199
+
205
200
table.insert (result , " </Component>" )
206
201
table.insert (result , " </Feature>" )
207
202
return result
@@ -220,14 +215,12 @@ end
220
215
221
216
-- get specvars
222
217
function _get_specvars (package )
223
-
224
218
local installcmds = batchcmds .get_installcmds (package ):cmds ()
225
219
local specvars = table .clone (package :specvars ())
226
220
227
221
local features = {}
228
222
table .join2 (features , _build_feature (package , {default = true , force = true , config_dir = true }))
229
223
table .join2 (features , _add_to_path (package ))
230
-
231
224
for name , component in table .orderpairs (package :components ()) do
232
225
table .join2 (features , _build_feature (component , {name = " Install " .. name }))
233
226
end
@@ -296,12 +289,14 @@ function _pack_wix(wix, package)
296
289
end
297
290
298
291
function main (package )
292
+
299
293
-- only for windows
300
294
if not is_host (" windows" ) then
301
295
return
302
296
end
303
297
304
298
cprint (" packing %s" , package :outputfile ())
299
+
305
300
-- get wix
306
301
local wix , oldenvs = _get_wix ()
307
302
@@ -310,4 +305,4 @@ function main(package)
310
305
311
306
-- done
312
307
os .setenvs (oldenvs )
313
- end
308
+ end
0 commit comments