Skip to content

Commit eef8671

Browse files
author
Aurelien Rainone
authored
Merge pull request arl#4 from iltommi/master
Add brew relinking
2 parents b5a2c8b + a32daa2 commit eef8671

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

macdeployqtfix.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111

1212
QTLIB_NAME_REGEX = r'^(?:@executable_path)?/.*/(Qt[a-zA-Z]*).framework/(?:Versions/\d/)?\1$'
1313
QTPLUGIN_NAME_REGEX = r'^(?:@executable_path)?/.*/[pP]lug[iI]ns/(.*)/(.*).dylib$'
14+
15+
BREWLIB_REGEX = r'^/usr/local/.*/(.*)'
16+
1417
QTLIB_NORMALIZED = r'$prefix/Frameworks/$qtlib.framework/Versions/$qtversion/$qtlib'
1518
QTPLUGIN_NORMALIZED = r'$prefix/PlugIns/$plugintype/$pluginname.dylib'
1619

20+
BREWLIB_NORMALIZED = r'$prefix/Frameworks/$brewlib'
21+
1722

1823
class GlobalConfig:
1924

@@ -77,6 +82,15 @@ def is_qt_lib(filename):
7782
rgxret = qtlib_name_rgx.match(filename)
7883
return rgxret is not None
7984

85+
def is_brew_lib(filename):
86+
"""
87+
check if a given file is a brew library
88+
accept absolute path as well as path containing @executable_path
89+
"""
90+
qtlib_name_rgx = re.compile(BREWLIB_REGEX)
91+
rgxret = qtlib_name_rgx.match(filename)
92+
return rgxret is not None
93+
8094
def normalize_qtplugin_name(filename):
8195
"""
8296
input: a path to a qt plugin, as returned by otool, that can have this form :
@@ -158,14 +172,57 @@ def normalize_qtlib_name(filename):
158172
GlobalConfig.logger.debug('\treturns({0})'.format((qtlib, abspath, rpath)))
159173
return qtlib, abspath, rpath
160174

175+
176+
def normalize_brew_name(filename):
177+
"""
178+
input: a path to a brew library, as returned by otool, that can have this form :
179+
- an absolute path /usr/local/lib/yyy
180+
output:
181+
a tuple (brewlib, abspath, rpath) where:
182+
- brewlib is the name of the brew lib
183+
- abspath is the absolute path of the qt lib inside the app bundle of exepath
184+
- relpath is the correct rpath to a qt lib inside the app bundle
185+
"""
186+
GlobalConfig.logger.debug('normalize_brew_name({0})'.format(filename))
187+
188+
brewlib_name_rgx = re.compile(BREWLIB_REGEX)
189+
rgxret = brewlib_name_rgx.match(filename)
190+
if not rgxret:
191+
msg = 'couldn\'t normalize a brew lib filename: {0}'.format(filename)
192+
GlobalConfig.logger.critical(msg)
193+
raise Exception(msg)
194+
195+
# brewlib normalization settings
196+
brewlib = rgxret.groups()[0]
197+
templ = Template(BREWLIB_NORMALIZED)
198+
# from brewlib, forge 2 path :
199+
# - absolute path of qt lib in bundle,
200+
abspath = os.path.normpath(templ.safe_substitute(
201+
prefix=os.path.dirname(GlobalConfig.exepath) + '/..',
202+
brewlib=brewlib))
203+
204+
# - and rpath containing @executable_path, relative to exepath
205+
rpath = templ.safe_substitute(
206+
prefix='@executable_path/..',
207+
brewlib=brewlib)
208+
209+
GlobalConfig.logger.debug('\treturns({0})'.format((brewlib, abspath, rpath)))
210+
print filename, "->",brewlib, abspath, rpath
211+
return brewlib, abspath, rpath
212+
213+
161214
def fix_dependency(binary, dep):
162215
"""
163216
fix 'dep' dependency of 'binary'. 'dep' is a qt library
164217
"""
218+
219+
165220
if is_qt_lib(dep):
166221
qtname, dep_abspath, dep_rpath = normalize_qtlib_name(dep)
167222
elif is_qt_plugin(dep):
168223
qtname, dep_abspath, dep_rpath = normalize_qtplugin_name(dep)
224+
elif is_brew_lib(dep):
225+
qtname, dep_abspath, dep_rpath = normalize_brew_name(dep)
169226
else:
170227
return True
171228

0 commit comments

Comments
 (0)