|
11 | 11 |
|
12 | 12 | QTLIB_NAME_REGEX = r'^(?:@executable_path)?/.*/(Qt[a-zA-Z]*).framework/(?:Versions/\d/)?\1$' |
13 | 13 | QTPLUGIN_NAME_REGEX = r'^(?:@executable_path)?/.*/[pP]lug[iI]ns/(.*)/(.*).dylib$' |
| 14 | + |
| 15 | +BREWLIB_REGEX = r'^/usr/local/.*/(.*)' |
| 16 | + |
14 | 17 | QTLIB_NORMALIZED = r'$prefix/Frameworks/$qtlib.framework/Versions/$qtversion/$qtlib' |
15 | 18 | QTPLUGIN_NORMALIZED = r'$prefix/PlugIns/$plugintype/$pluginname.dylib' |
16 | 19 |
|
| 20 | +BREWLIB_NORMALIZED = r'$prefix/Frameworks/$brewlib' |
| 21 | + |
17 | 22 |
|
18 | 23 | class GlobalConfig: |
19 | 24 |
|
@@ -77,6 +82,15 @@ def is_qt_lib(filename): |
77 | 82 | rgxret = qtlib_name_rgx.match(filename) |
78 | 83 | return rgxret is not None |
79 | 84 |
|
| 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 | + |
80 | 94 | def normalize_qtplugin_name(filename): |
81 | 95 | """ |
82 | 96 | 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): |
158 | 172 | GlobalConfig.logger.debug('\treturns({0})'.format((qtlib, abspath, rpath))) |
159 | 173 | return qtlib, abspath, rpath |
160 | 174 |
|
| 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 | + |
161 | 214 | def fix_dependency(binary, dep): |
162 | 215 | """ |
163 | 216 | fix 'dep' dependency of 'binary'. 'dep' is a qt library |
164 | 217 | """ |
| 218 | + |
| 219 | + |
165 | 220 | if is_qt_lib(dep): |
166 | 221 | qtname, dep_abspath, dep_rpath = normalize_qtlib_name(dep) |
167 | 222 | elif is_qt_plugin(dep): |
168 | 223 | 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) |
169 | 226 | else: |
170 | 227 | return True |
171 | 228 |
|
|
0 commit comments