1
1
# MySQL Connector/Python - MySQL driver written in Python.
2
2
# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3
3
4
+
4
5
# MySQL Connector/Python is licensed under the terms of the GPLv2
5
6
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
6
7
# MySQL Connectors. There are special exceptions to the terms and
40
41
import platform
41
42
42
43
ARCH_64BIT = sys .maxsize > 2 ** 32 # Works with Python 2.6 and greater
44
+ py_arch = '64-bit' if ARCH_64BIT else '32-bit'
43
45
44
46
CEXT_OPTIONS = [
45
47
('with-mysql-capi=' , None ,
@@ -108,25 +110,28 @@ def unix_lib_is64bit(lib_file):
108
110
raise OSError ("unix_lib_is64bit only useful on UNIX-like systems" )
109
111
110
112
if os .isdir (lib_file ):
111
- mysqlclient_lib = None
112
- for root , dirs , files in os .walk (lib_file ):
113
+ mysqlclient_libs = []
114
+ for root , _ , files in os .walk (lib_file ):
113
115
for filename in files :
114
116
filepath = os .path .join (root , filename )
115
117
if filename .startswith ('libmysqlclient' ) and \
116
- not os .path .islink (filepath ) and \
117
- '_r' not in filename :
118
- mysqlclient_lib = filepath
119
- break
120
- if mysqlclient_lib :
118
+ not os .path .islink (filepath ) and \
119
+ '_r' not in filename and \
120
+ '.a' not in filename :
121
+ mysqlclient_libs . append ( filepath )
122
+ if mysqlclient_libs :
121
123
break
122
- lib_file = mysqlclient_lib
124
+ # give priority to .so files instead of .a
125
+ mysqlclient_libs .sort ()
126
+ lib_file = mysqlclient_libs [- 1 ]
123
127
128
+ log .debug ("# Using file command to test lib_file {0}" .format (lib_file ))
124
129
prc = Popen (['file' , '-L' , lib_file ], stdin = PIPE , stderr = STDOUT ,
125
130
stdout = PIPE )
126
131
stdout = prc .communicate ()[0 ]
127
132
stdout = stdout .split (':' )[1 ]
128
-
129
- if 'x86_64' in stdout or 'x86-64' in stdout :
133
+ log . debug ( "# lib_file {0} stdout: {1}" . format ( lib_file , stdout ))
134
+ if 'x86_64' in stdout or 'x86-64' in stdout or '32-bit' not in stdout :
130
135
return True
131
136
132
137
return False
@@ -147,9 +152,11 @@ def get_mysql_config_info(mysql_config):
147
152
except OSError as exc :
148
153
raise DistutilsExecError ("Failed executing mysql_config: {0}" .format (
149
154
str (exc )))
150
-
155
+ log . debug ( "# stdout: {0}" . format ( stdout ))
151
156
info = {}
152
157
for option , line in zip (options , stdout .split ('\n ' )):
158
+ log .debug ("# option: {0}" .format (option ))
159
+ log .debug ("# line: {0}" .format (line ))
153
160
info [option ] = line .strip ()
154
161
155
162
ver = info ['version' ]
@@ -160,7 +167,10 @@ def get_mysql_config_info(mysql_config):
160
167
libs = shlex .split (info ['libs' ])
161
168
info ['lib_dir' ] = libs [0 ].replace ('-L' , '' )
162
169
info ['libs' ] = [ lib .replace ('-l' , '' ) for lib in libs [1 :] ]
163
-
170
+ log .debug ("# info['libs']: " )
171
+ for lib in info ['libs' ]:
172
+ log .debug ("# {0}" .format (lib ))
173
+ log .error ("# info['libs']: {0}" .format (info ['libs' ]))
164
174
libs = shlex .split (info ['libs_r' ])
165
175
info ['lib_r_dir' ] = libs [0 ].replace ('-L' , '' )
166
176
info ['libs_r' ] = [ lib .replace ('-l' , '' ) for lib in libs [1 :] ]
@@ -171,11 +181,29 @@ def get_mysql_config_info(mysql_config):
171
181
info ['arch' ] = None
172
182
if os .name == 'posix' :
173
183
pathname = os .path .join (info ['lib_dir' ], 'lib' + info ['libs' ][0 ]) + '*'
174
- lib = glob (pathname )[0 ]
184
+ libs = glob (pathname )
185
+ log .debug ("# libs: {0}" .format (libs ))
186
+ for lib in libs :
187
+ log .debug ("#- {0}" .format (lib ))
188
+ mysqlclient_libs = []
189
+ for filepath in libs :
190
+ _ , filename = os .path .split (filepath )
191
+ log .debug ("# filename {0}" .format (filename ))
192
+ if filename .startswith ('libmysqlclient' ) and \
193
+ not os .path .islink (filepath ) and \
194
+ '_r' not in filename and \
195
+ '.a' not in filename :
196
+ mysqlclient_libs .append (filepath )
197
+ mysqlclient_libs .sort ()
175
198
176
199
stdout = None
177
200
try :
178
- proc = Popen (['file' , '-L' , lib ], stdout = PIPE ,
201
+ log .debug ("# mysqlclient_lib: {0}" .format (mysqlclient_libs [- 1 ]))
202
+ for mysqlclient_lib in mysqlclient_libs :
203
+ log .debug ("#+ {0}" .format (mysqlclient_lib ))
204
+ log .debug ("# tested mysqlclient_lib[-1]: "
205
+ "{0}" .format (mysqlclient_libs [- 1 ]))
206
+ proc = Popen (['file' , '-L' , mysqlclient_libs [- 1 ]], stdout = PIPE ,
179
207
universal_newlines = True )
180
208
stdout , _ = proc .communicate ()
181
209
stdout = stdout .split (':' )[1 ]
@@ -254,6 +282,7 @@ def _finalize_connector_c(self, connc_loc):
254
282
if os .path .isfile (mysql_config ) and \
255
283
os .access (mysql_config , os .X_OK ):
256
284
connc_loc = mysql_config
285
+ log .debug ("# connc_loc: {0}" .format (connc_loc ))
257
286
else :
258
287
# Probably using MS Windows
259
288
myconfigh = os .path .join (connc_loc , 'include' , 'my_config.h' )
@@ -299,6 +328,7 @@ def _finalize_connector_c(self, connc_loc):
299
328
libraries = ['-lmysqlclient' ]
300
329
library_dirs = os .path .join (connc_loc , 'lib' )
301
330
331
+ log .debug ("# connc_64bit: {0}" .format (connc_64bit ))
302
332
if connc_64bit :
303
333
self .arch = 'x86_64'
304
334
else :
@@ -310,6 +340,7 @@ def _finalize_connector_c(self, connc_loc):
310
340
mysql_config = connc_loc
311
341
# Check mysql_config
312
342
myc_info = get_mysql_config_info (mysql_config )
343
+ log .debug ("# myc_info: {0}" .format (myc_info ))
313
344
314
345
if myc_info ['version' ] < min_version :
315
346
log .error (err_version )
@@ -334,10 +365,16 @@ def _finalize_connector_c(self, connc_loc):
334
365
# We try to offer a nice message when the architecture of Python
335
366
# is not the same as MySQL Connector/C binaries.
336
367
py_arch = '64-bit' if ARCH_64BIT else '32-bit'
368
+ log .debug ("# Python architecture: {0}" .format (py_arch ))
369
+ log .debug ("# Python ARCH_64BIT: {0}" .format (ARCH_64BIT ))
370
+ log .debug ("# self.arch: {0}" .format (self .arch ))
337
371
if ARCH_64BIT != connc_64bit :
338
372
log .error ("Python is {0}, but does not "
339
- "match MySQL C API {1} architecture" .format (
340
- py_arch , '64-bit' if connc_64bit else '32-bit' ))
373
+ "match MySQL C API {1} architecture, "
374
+ "type: {2}"
375
+ "" .format (py_arch ,
376
+ '64-bit' if connc_64bit else '32-bit' ,
377
+ self .arch ))
341
378
sys .exit (1 )
342
379
343
380
def finalize_options (self ):
0 commit comments