forked from mantidproject/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_package.rb.in
executable file
·386 lines (343 loc) · 16 KB
/
make_package.rb.in
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#!/usr/bin/env ruby
#This loop changes the linking from /usr/local/lib to @rpath
require 'pathname'
def copyFile(file)
p "copying file #{file}"
output = system("cp #{file} Contents/MacOS/")
if output != true
exit 1
end
end
def copyOptionalFile(file)
if File.exist?(file)
p "copying optional file #{file}"
output = system("cp #{file} Contents/MacOS/")
end
end
def addPythonLibrary(input, output)
p "copying directory #{input} to #{output}"
output = system("rsync -a -L --exclude=.pyc #{input} #{output}")
if output != true
exit 1
end
end
def addPythonLibrariesInDirectory(input, output)
p "copying directory #{input} to #{output}"
output = system("rsync -a -L --exclude=.pyc #{input}/* #{output}")
if output != true
exit 1
end
end
lib_dir = Pathname.new("/usr/local/lib")
openssl_dir = Pathname.new("/usr/local/opt/openssl/lib")
ParaView_dir = Pathname.new("@ParaView_DIR@")
#filenames with path for all shared libraries used by MantidPlot and its dependencies.
library_filenames = ["libboost_regex-mt.dylib",
"libboost_date_time-mt.dylib",
"libboost_python-mt.dylib",
"libboost_serialization-mt.dylib",
"libboost_filesystem-mt.dylib",
"libboost_system-mt.dylib",
"libgsl.dylib",
"libgslcblas.dylib",
"libjsoncpp.dylib",
"libmuparser.dylib",
"libNeXus.dylib",
"libNeXusCPP.dylib",
"libPocoFoundation.dylib",
"libPocoUtil.dylib",
"libPocoXML.dylib",
"libPocoNet.dylib",
"libPocoCrypto.dylib",
"libPocoNetSSL.dylib",
"libTKernel.dylib",
"libTKBO.dylib",
"libTKernel.dylib",
"libTKShHealing.dylib",
"libTKPrim.dylib",
"libTKMesh.dylib",
"libTKBRep.dylib",
"libTKGeomAlgo.dylib",
"libTKTopAlgo.dylib",
"libTKMath.dylib",
"libTKG2d.dylib",
"libTKG3d.dylib",
"libTKGeomBase.dylib",
"libqwt.dylib",
"libqwtplot3d.dylib",
"libqscintilla2.dylib",
"libmxml.dylib",
"libhdf5.dylib",
"libhdf5_hl.dylib",
"libhdf5_cpp.dylib",
"libhdf5_hl_cpp.dylib",
"libmfhdf.dylib",
"libdf.dylib",
"libsz.dylib",
"libjpeg.dylib",
"libssl.dylib",
"libcrypto.dylib",
"libtbb.dylib",
"libtbbmalloc.dylib",
"libtbbmalloc_proxy.dylib",
"librdkafka.dylib",
"librdkafka++.dylib"]
poco_version = "@POCO_VERSION@".split(".").map(&:to_i)
if(poco_version[0] > 1 || (poco_version[0] == 1 && poco_version[1] >= 6))
library_filenames << "libPocoJSON.dylib"
end
if("@OPENMP_FOUND@" == "TRUE")
library_filenames << "libomp.dylib"
end
#This copies the libraries over, then changes permissions and the id from /usr/local/lib to @rpath
library_filenames.each do |filename|
if filename.include? "libssl.dylib"
copyFile(openssl_dir+filename)
elsif filename.include? "libcrypto.dylib"
copyFile(openssl_dir+filename)
else
copyFile(lib_dir+filename)
end
`chmod +w Contents/MacOS/#{filename}`
`install_name_tool -id @rpath/#{filename} Contents/MacOS/#{filename}`
end
if( "@MAKE_VATES@" == "ON" )
def add_ParaView_Libraries(file)
dependencies = `otool -L #{file}`
dependencies.split("\n").each do |dependency|
currentname = dependency.strip.split(" ")
filename = currentname[0]
if filename.include? "#{ParaView_dir}"
`cp #{filename} Contents/Libraries`
name_split_on_slash = filename.strip.split("/")
filename_no_dir = name_split_on_slash[-1]
`chmod +w Contents/Libraries/#{filename_no_dir}`
`install_name_tool -id @rpath/#{filename_no_dir} Contents/Libraries/#{filename_no_dir}`
`install_name_tool -change #{filename} @rpath/#{filename_no_dir} #{file}`
end
end
end
`mkdir Contents/Libraries`
`cp #{ParaView_dir}/lib/*Python.so Contents/Libraries`
vatesfiles = ["Contents/MacOS/MantidPlot",
"Contents/MacOS/libMantidQtWidgetsCommon.dylib",
"Contents/MacOS/libMantidParaViewQtWidgets.dylib",
"Contents/MacOS/libMantidVatesAPI.dylib",
"plugins/libMantidVatesAlgorithms.dylib",
"pvplugins/libMantidVatesSimpleGuiViewWidgets.dylib"]
vatesfiles += Dir["Contents/Libraries/*Python.so"] + Dir["pvplugins/pvplugins/*.dylib"]
vatesfiles.each do |file|
add_ParaView_Libraries(file)
end
loop do
issues_found = 0
Dir["Contents/Libraries/*.dylib"].each do |library|
dependencies = `otool -L #{library}`
dependencies.split("\n").each do |dependency|
currentname = dependency.strip.split(" ")
filename = currentname[0]
if filename.include? "#{ParaView_dir}"
#p "fixing #{library} #{filename}"
issues_found = issues_found + 1
name_split_on_slash = filename.strip.split("/")
filename_no_dir = name_split_on_slash[-1]
if !FileTest.exist?("Contents/Libraries/#{filename_no_dir}")
`cp #{filename} Contents/Libraries`
`chmod +w Contents/Libraries/#{filename_no_dir}`
`install_name_tool -id @rpath/#{filename_no_dir} Contents/Libraries/#{filename_no_dir}`
end
`install_name_tool -add_rpath @loader_path/../Libraries #{library} > /dev/null 2>&1`
`install_name_tool -add_rpath @loader_path/../MacOS #{library} > /dev/null 2>&1`
`install_name_tool -change #{filename} @rpath/#{filename_no_dir} #{library}`
end
end
end
p "fixed #{issues_found} issues this iteration!"
break if issues_found == 0
end
#fix libNonOrthogonalSource.dylib
`install_name_tool -id @rpath/libNonOrthogonalSource.dylib pvplugins/pvplugins/libNonOrthogonalSource.dylib`
end
#use install_name_tool to change dependencies from /usr/local to libraries in the package.
search_patterns = ["**/*.dylib","**/*.so","**/MantidPlot"]
search_patterns.each do |pattern|
Dir[pattern].each do |library|
dependencies = `otool -L #{library}`
dependencies.split("\n").each do |dependency|
currentname = dependency.strip.split(" ")
name_split_on_slash = currentname[0].strip.split("/")
name_split_on_period = name_split_on_slash[-1].split(".")
prefix = name_split_on_period[0]+"."
library_filenames.each do |filename|
basename = File.basename(filename,"dylib")
if prefix == basename
`install_name_tool -change #{currentname[0]} @rpath/#{basename+"dylib"} #{library}`
end
end
end
end
end
#We'll use macdeployqt to fix qt dependencies.
Qt_Executables = "-executable=Contents/MacOS/mantidqtpython.so -executable=Contents/MacOS/libqwtplot3d.dylib -executable=Contents/MacOS/libqwt.dylib -executable=Contents/MacOS/libqscintilla2.dylib"
if( "@MAKE_VATES@" == "ON" )
list = ["Contents/Libraries/vtkParaViewWebCorePython.so",
"Contents/Libraries/vtkPVAnimationPython.so",
"Contents/Libraries/vtkPVCatalystPython.so",
"Contents/Libraries/vtkPVCinemaReaderPython.so",
"Contents/Libraries/vtkPVClientServerCoreDefaultPython.so",
"Contents/Libraries/vtkPVClientServerCoreRenderingPython.so",
"Contents/Libraries/vtkPVPythonCatalystPython.so",
"Contents/Libraries/vtkPVServerImplementationRenderingPython.so",
"Contents/Libraries/vtkPVServerManagerApplicationPython.so",
"Contents/Libraries/vtkPVServerManagerDefaultPython.so",
"Contents/Libraries/vtkPVServerManagerRenderingPython.so",
"Contents/Libraries/vtkPVVTKExtensionsDefaultPython.so",
"Contents/Libraries/vtkPVVTKExtensionsRenderingPython.so"]
list.each do |filename|
Qt_Executables << " -executable=#{filename}"
end
end
`macdeployqt ../MantidPlot.app #{Qt_Executables}`
if Dir.exist?("Contents/PlugIns")
#Fix remaining QT-related linking issues.
Dir["Contents/PlugIns/**/*.dylib"].each do |library|
basename = File.basename(library)
`chmod +w #{library}`
`install_name_tool -id @rpath/#{basename} #{library}`
end
else
p "Contents/PlugIns not created by macdeployqt."
exit 1
end
# We only need one copy of openssl
`install_name_tool -change @loader_path/../../../libssl.1.0.0.dylib @loader_path/../../../../MacOS/libssl.dylib Contents/Frameworks/QtNetwork.framework/Versions/4/QtNetwork`
`install_name_tool -change @loader_path/../../../libcrypto.1.0.0.dylib @loader_path/../../../../MacOS/libcrypto.dylib Contents/Frameworks/QtNetwork.framework/Versions/4/QtNetwork`
`rm Contents/Frameworks/libssl.1.0.0.dylib`
`rm Contents/Frameworks/libcrypto.1.0.0.dylib`
#change id of all libraries that match patterns
def change_id(patterns, lib_path)
patterns.each do |pattern|
Dir[pattern].each do |library|
basename = File.basename(library)
`chmod +w #{lib_path}/#{basename}`
`install_name_tool -id @rpath/#{basename} #{lib_path}/#{basename}`
end
end
end
#Homebrew recently switched the linking from /usr/local/lib/* to /usr/local/opt/qt/lib/*
#This attempts to determine the correct path to pass to install_name_tool.
def find_linking_directories(patterns, lib_name, lib_path)
linking_dir = []
Dir[patterns[0]].each do |library|
dependencies = `otool -L #{library}`
dependencies.split("\n").each do |dependency|
if dependency.match(lib_name)
if dependency.match(lib_path)
linking_dir << lib_path
else
linking_dir << '/usr/local/lib'
end
end
end
end
return linking_dir
end
#change id of all PyQt4 libraries
pyqt4_patterns = ["**/PyQt4/*.so"]
change_id(pyqt4_patterns, "Contents/MacOS/PyQt4/")
QtLinkingDir = find_linking_directories(pyqt4_patterns, 'Qt.*.framework/Versions/\d/Qt.*', '/usr/local/opt/qt/lib')
if QtLinkingDir.uniq != [QtLinkingDir[0]]
p "Error updating PyQt4 dynamic linking!"
exit 1
end
#fix PyQt4 and Qt4 linking issues
`install_name_tool -change #{QtLinkingDir[0]}/QtCore.framework/Versions/4/QtCore @loader_path/../../Frameworks/QtCore.framework/Versions/4/QtCore Contents/MacOS/PyQt4/QtCore.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtGui.framework/Versions/4/QtGui @loader_path/../../Frameworks/QtGui.framework/Versions/4/QtGui Contents/MacOS/PyQt4/QtGui.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtCore.framework/Versions/4/QtCore @loader_path/../../Frameworks/QtCore.framework/Versions/4/QtCore Contents/MacOS/PyQt4/QtGui.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtOpenGL.framework/Versions/4/QtOpenGL @loader_path/../../Frameworks/QtOpenGL.framework/Versions/4/QtOpenGL Contents/MacOS/PyQt4/QtOpenGL.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtGui.framework/Versions/4/QtGui @loader_path/../../Frameworks/QtGui.framework/Versions/4/QtGui Contents/MacOS/PyQt4/QtOpenGL.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtCore.framework/Versions/4/QtCore @loader_path/../../Frameworks/QtCore.framework/Versions/4/QtCore Contents/MacOS/PyQt4/QtOpenGL.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtSql.framework/Versions/4/QtSql @loader_path/../../Frameworks/QtSql.framework/Versions/4/QtSql Contents/MacOS/PyQt4/QtSql.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtGui.framework/Versions/4/QtGui @loader_path/../../Frameworks/QtGui.framework/Versions/4/QtGui Contents/MacOS/PyQt4/QtSql.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtCore.framework/Versions/4/QtCore @loader_path/../../Frameworks/QtCore.framework/Versions/4/QtCore Contents/MacOS/PyQt4/QtSql.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtSvg.framework/Versions/4/QtSvg @loader_path/../../Frameworks/QtSvg.framework/Versions/4/QtSvg Contents/MacOS/PyQt4/QtSvg.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtGui.framework/Versions/4/QtGui @loader_path/../../Frameworks/QtGui.framework/Versions/4/QtGui Contents/MacOS/PyQt4/QtSvg.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtCore.framework/Versions/4/QtCore @loader_path/../../Frameworks/QtCore.framework/Versions/4/QtCore Contents/MacOS/PyQt4/QtSvg.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtXml.framework/Versions/4/QtXml @loader_path/../../Frameworks/QtXml.framework/Versions/4/QtXml Contents/MacOS/PyQt4/QtXml.so`
`install_name_tool -change #{QtLinkingDir[0]}/QtCore.framework/Versions/4/QtCore @loader_path/../../Frameworks/QtCore.framework/Versions/4/QtCore Contents/MacOS/PyQt4/QtXml.so`
#Copy over python libraries not included with OSX.
#currently missing epics
path = "/Library/Python/2.7/site-packages"
directories = ["sphinx","sphinx_bootstrap_theme","IPython","zmq","pygments","backports","certifi","tornado","markupsafe","jinja2","psutil","jsonschema","functools32","ptyprocess","CifFile","yaml"]
directories.each do |directory|
addPythonLibrary("#{path}/#{directory}","Contents/MacOS/")
end
if( "@MAKE_VATES@" == "ON" )
addPythonLibrariesInDirectory("#{ParaView_dir}/lib/site-packages","Contents/Python/")
end
# ---------------------------------------------
# H5Py section
# ---------------------------------------------
h5py_path = "/usr/local/lib/python2.7/site-packages"
h5py_directories = ["h5py"]
h5py_directories.each do |directory|
addPythonLibrary("#{h5py_path}/#{directory}","Contents/MacOS/")
end
h5py_patterns = ["**/h5py/*.so"]
change_id(h5py_patterns, "Contents/MacOS/h5py/")
h5py_linking_dir = find_linking_directories(h5py_patterns, 'lib/libhdf5', '/usr/local/opt/hdf5/lib')
h5py_patterns.each do |pattern|
Dir[pattern].each do |library|
basename = File.basename(library)
dependencies = `otool -L #{library}`
dependencies.split("\n").each do |dependency|
currentname = dependency.strip.split(" ")
filename = currentname[0]
if filename.include? "libhdf5"
name_split_on_slash = filename.strip.split("/")
filename_no_dir = name_split_on_slash[-1]
parts = filename_no_dir.strip.split(".")
loader_filename = parts[0] + "." + parts[2]
`install_name_tool -add_rpath @loader_path/../ Contents/MacOS/h5py/#{basename} > /dev/null 2>&1`
`install_name_tool -change #{h5py_linking_dir[0]}/#{filename_no_dir} @rpath/#{loader_filename} Contents/MacOS/h5py/#{basename}`
end
end
end
end
files = ["gnureadline.so","readline.py","pyparsing.py","mistune.py"]
files.each do |file|
copyFile("#{path}/#{file}")
end
#mistune.so isn't present in v0.7
copyOptionalFile("#{path}/mistune.so")
`mkdir Contents/MacOS/bin`
`cp /usr/local/bin/ipython@PYTHON_VERSION_MAJOR@ Contents/MacOS/bin/`
#Lastly check for any libraries in the package linking against homebrew libraries.
search_patterns.each do |pattern|
Dir[pattern].each do |library|
dependencies = `otool -L #{library}`
dependencies.split("\n").each do |dependency|
if dependency.include? "/usr/local/"
p "issue with library: #{library} linked against: #{dependency}"
exit 1
end
if dependency.include? "@loader_path/libTK"
p "issue with library: #{library} linked against: #{dependency}"
p "Is an OpenCascade library missing?"
exit 1
end
if( "@MAKE_VATES@" == "ON" )
if dependency.include? "@loader_path"
if dependency.include? "libvtk"
p "ParaView libraries found Contents/Libraries. Is the vatesfiles list is complete?"
exit 1
end
end
if dependency.include? "#{ParaView_dir}"
p "issue with library: #{library} linking against: #{dependency}"
exit 1
end
end
end
end
end