/
prepare-wix-input.rb
242 lines (198 loc) · 5.9 KB
/
prepare-wix-input.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# Copyright 2013 by Vincent Fourmond
# Usable, modifiable and redistributable under the same terms as QSoas itself
#
# This small script is run by qmake on windows to prepare the XML
# input file for WiX.
require 'rbconfig'
# For the generation of the UUID
require 'securerandom'
# Persistence of UUID across runs of this script.
require 'yaml'
# Here is a rather cumbersome way to detect WIN64:
puts "Building using the given PATH: #{ENV['PATH']}"
if ENV['PATH'] =~ /mingw64/
$win64 = true
puts " -> building a win64 installer"
else
$win64 = false
puts " -> building a win32 installer"
end
# Takes two arguments: full version, and win-nice version
full_version = ARGV[0] || "full"
win_version = ARGV[1] || "0.0"
uuids = {}
# uuids.yaml contains the persistent UUIDs
if File.exist?("uuids.yaml")
File.open("uuids.yaml", "r") { |f| uuids = YAML::load(f) }
end
files = []
debug_files = []
# A hash 'dir' -> 'release|debug' -> file list
subdirs = {}
######################################################################
# Finding the libraries
# Qt libraries
for f in %w[Qt5Core Qt5Gui Qt5OpenGL Qt5PrintSupport Qt5Widgets Qt5Svg Qt5Help Qt5Sql Qt5CLucene Qt5Network]
lib_file = "#{ENV['QTDIR']}\\bin\\#{f}.dll"
files << lib_file
debug_files << lib_file.gsub(/.dll/, "d.dll")
end
# Handling platforms
pltforms = {}
subdirs['platforms'] = pltforms
for ptf in %w[qwindows qminimal qoffscreen]
pltforms['release'] ||= []
pltforms['release'] << "#{ENV['QTDIR']}\\plugins\\platforms\\#{ptf}.dll"
pltforms['debug'] ||= []
pltforms['debug'] << "#{ENV['QTDIR']}\\plugins\\platforms\\#{ptf}d.dll"
end
# Handling the sqlite driver plugin
subdirs["sqldrivers"] = {}
drivers = subdirs["sqldrivers"]
for ptf in %w[qsqlite]
drivers['release'] ||= []
drivers['release'] << "#{ENV['QTDIR']}\\plugins\\sqldrivers\\#{ptf}.dll"
drivers['debug'] ||= []
drivers['debug'] << "#{ENV['QTDIR']}\\plugins\\sqldrivers\\#{ptf}d.dll"
end
# Handling image formats
imgs = {}
subdirs['imageformats'] = imgs
for ptf in %w[qjpeg qsvg]
imgs['release'] ||= []
imgs['release'] << "#{ENV['QTDIR']}\\plugins\\imageformats\\#{ptf}.dll"
imgs['debug'] ||= []
imgs['debug'] << "#{ENV['QTDIR']}\\plugins\\imageformats\\#{ptf}d.dll"
end
# Ruby library
rb = File::join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['LIBRUBY_SO'])
rb.gsub!(/\//, '\\')
files << rb
debug_files << rb
# And now, we look for g++ libraries:
path = ENV['PATH'].split(/\s*;\s*/)
for f in %w[libgcc_s_dw2-1.dll libgcc_s_sjlj-1.dll libstdc++-6.dll mingwm10.dll libwinpthread-1.dll libgcc_s_seh-1.dll]
for d in path
t = File::join(d,f)
if File.exists?(t)
t.gsub!(/\//, '\\')
files << t
debug_files << t
break
end
end
end
# We first get the MD5sum for all the files
file_ids = {}
all_files = files + debug_files
for k in subdirs.keys
all_files += subdirs[k].values.flatten
end
for f in all_files
sz = begin
File.size f
rescue
0
end
fid = "#{f}+#{sz}"
file_ids[f] = fid
end
# We add a few keys
keys = file_ids.values
keys += ["UpgradeID", "ProductID", "QSoasID", "QSoasProgID", "StartMenuID", "DocID"]
# Now, we generate all the missing UUIDs
for k in keys
if ! uuids.key?(k)
uuids[k] = SecureRandom.uuid
end
end
# This is not very clear, but it seems that, for upgrades to replace
# the previous things, the upgradeID should be identical.
#
# According to https://docs.microsoft.com/en-us/windows/win32/msi/upgradecode, the UpgradeID represents a related set of products...
uuids['UpgradeID'] = "BF4BE0DE-BC7C-438A-AC28-DC4310B28EEA"
store = uuids.dup
# These are UUIDS that should change at every run
store.delete("QSoasID")
store.delete("DocID")
File.open("uuids.yaml", "w") do |f|
YAML::dump(store, f)
end
# p uuids
# Generation of the two components
what = {
'release' => files,
'debug' => debug_files
}
dlls = {}
pltf = {}
dll_refs = {}
w64p = ""
if $win64
w64p = " Win64='yes'"
end
for k,v in what
idx = 0
dlls[k] = ""
pltf[k] = ""
dll_refs[k] = ""
for f in v
next unless File::exists?(f) # Only for testing !
guid = uuids[file_ids[f]]
bf = File::basename(f)
dlls[k] << "<Component Id='Dll#{idx}' Guid='#{guid}'#{w64p}>\n"
dlls[k] << " <File Id='Dll_file#{idx}' Name='#{bf}' DiskId='1' Source='#{f}' KeyPath='yes' />\n"
dlls[k] << "</Component>\n"
dll_refs[k] << "<ComponentRef Id='Dll#{idx}' />\n"
idx += 1
end
for dir in subdirs.keys
if subdirs[dir][k]
dlls[k] << "<Directory Id='#{dir}dir' Name='#{dir}'>\n"
for f in subdirs[dir][k]
guid = uuids[file_ids[f]]
bf = File::basename(f)
dlls[k] << " <Component Id='Dll#{idx}' Guid='#{guid}'>\n"
dlls[k] << " <File Id='Dll_file#{idx}' Name='#{bf}' DiskId='1' Source='#{f}' KeyPath='yes' />\n"
dlls[k] << " </Component>\n"
dll_refs[k] << "<ComponentRef Id='Dll#{idx}' />\n"
idx += 1
end
dlls[k] << "</Directory>\n"
end
end
end
substs = uuids.dup
substs['DLLS'] = dlls['release']
substs['DEBUG_DLLS'] = dlls['debug']
substs['DLL_REFS'] = dll_refs['release']
substs['DEBUG_DLL_REFS'] = dll_refs['debug']
substs['VERSION'] = full_version
substs['WIN_VERSION'] = win_version
# Here preparing the win64 substitutions
if $win64
substs['PFF'] = "ProgramFiles64Folder"
substs['ARCH'] = "Platform='x64'"
substs['W64'] = "Win64='yes'"
else
substs['PFF'] = "ProgramFilesFolder"
substs['ARCH'] = ""
substs['W64'] = ""
end
# Dumping some informations...
puts "Preparing the wix input files. Using the following substititions:"
puts YAML::dump(substs)
# OK, now the generation of the XML source file, in the current directory ?
for src in ["pkg/QSoas.wxs", "pkg/QSoas-nint.wxs", "pkg/QSoas-debug.wxs"]
tgt = File::basename(src)
File.open(src, "r") do |f|
File.open(tgt, "w") do |o|
for line in f
line.gsub!(/#([^#]+)#/) do |s|
substs[$1]
end
o.print line
end
end
end
end