Skip to content

Commit 8399904

Browse files
committed
BUG21782246: Fix Install check of bitness of libmysql c client fails.
The check for libmysqlclient.so it was being done in the worng file, this patch corrects the problem avoding 'libmysqlclient.a.*' files. v 1.7
1 parent a865ae2 commit 8399904

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Full release notes:
1111
v2.1.3
1212
======
1313

14+
- BUG#21782246: Fix Install check of bitness of libmysql c client fails
1415
- BUG#21505096: MySQL Connector python 2.1.2 does not ship with required __init.py__ files
1516
- BUG#21499127: Fix copyright year in README.txt
1617
- BUG#21420633: Fix CExtension crashing while fetching large number of NULL value

lib/cpy_distutils.py

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
22
# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
33

4+
45
# MySQL Connector/Python is licensed under the terms of the GPLv2
56
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
67
# MySQL Connectors. There are special exceptions to the terms and
@@ -40,6 +41,7 @@
4041
import platform
4142

4243
ARCH_64BIT = sys.maxsize > 2**32 # Works with Python 2.6 and greater
44+
py_arch = '64-bit' if ARCH_64BIT else '32-bit'
4345

4446
CEXT_OPTIONS = [
4547
('with-mysql-capi=', None,
@@ -108,25 +110,28 @@ def unix_lib_is64bit(lib_file):
108110
raise OSError("unix_lib_is64bit only useful on UNIX-like systems")
109111

110112
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):
113115
for filename in files:
114116
filepath = os.path.join(root, filename)
115117
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:
121123
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]
123127

128+
log.debug("# Using file command to test lib_file {0}".format(lib_file))
124129
prc = Popen(['file', '-L', lib_file], stdin=PIPE, stderr=STDOUT,
125130
stdout=PIPE)
126131
stdout = prc.communicate()[0]
127132
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:
130135
return True
131136

132137
return False
@@ -147,9 +152,11 @@ def get_mysql_config_info(mysql_config):
147152
except OSError as exc:
148153
raise DistutilsExecError("Failed executing mysql_config: {0}".format(
149154
str(exc)))
150-
155+
log.debug("# stdout: {0}".format(stdout))
151156
info = {}
152157
for option, line in zip(options, stdout.split('\n')):
158+
log.debug("# option: {0}".format(option))
159+
log.debug("# line: {0}".format(line))
153160
info[option] = line.strip()
154161

155162
ver = info['version']
@@ -160,7 +167,10 @@ def get_mysql_config_info(mysql_config):
160167
libs = shlex.split(info['libs'])
161168
info['lib_dir'] = libs[0].replace('-L', '')
162169
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']))
164174
libs = shlex.split(info['libs_r'])
165175
info['lib_r_dir'] = libs[0].replace('-L', '')
166176
info['libs_r'] = [ lib.replace('-l', '') for lib in libs[1:] ]
@@ -171,11 +181,29 @@ def get_mysql_config_info(mysql_config):
171181
info['arch'] = None
172182
if os.name == 'posix':
173183
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()
175198

176199
stdout = None
177200
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,
179207
universal_newlines=True)
180208
stdout, _ = proc.communicate()
181209
stdout = stdout.split(':')[1]
@@ -254,6 +282,7 @@ def _finalize_connector_c(self, connc_loc):
254282
if os.path.isfile(mysql_config) and \
255283
os.access(mysql_config, os.X_OK):
256284
connc_loc = mysql_config
285+
log.debug("# connc_loc: {0}".format(connc_loc))
257286
else:
258287
# Probably using MS Windows
259288
myconfigh = os.path.join(connc_loc, 'include', 'my_config.h')
@@ -299,6 +328,7 @@ def _finalize_connector_c(self, connc_loc):
299328
libraries = ['-lmysqlclient']
300329
library_dirs = os.path.join(connc_loc, 'lib')
301330

331+
log.debug("# connc_64bit: {0}".format(connc_64bit))
302332
if connc_64bit:
303333
self.arch = 'x86_64'
304334
else:
@@ -310,6 +340,7 @@ def _finalize_connector_c(self, connc_loc):
310340
mysql_config = connc_loc
311341
# Check mysql_config
312342
myc_info = get_mysql_config_info(mysql_config)
343+
log.debug("# myc_info: {0}".format(myc_info))
313344

314345
if myc_info['version'] < min_version:
315346
log.error(err_version)
@@ -334,10 +365,16 @@ def _finalize_connector_c(self, connc_loc):
334365
# We try to offer a nice message when the architecture of Python
335366
# is not the same as MySQL Connector/C binaries.
336367
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))
337371
if ARCH_64BIT != connc_64bit:
338372
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))
341378
sys.exit(1)
342379

343380
def finalize_options(self):

0 commit comments

Comments
 (0)