Skip to content

Commit fc49fd5

Browse files
committed
setupinfo.py
- Backed out previos change to add "librt" lib/cpy_distutils.py - Use more specialized variables 'include_dirs', 'library_dirs' and 'libraries' when adding information to the compiler and linker objects. - Add "librt" after adding "libmysqlclient". GCC 4.6 ignore "-lrt" if given before "-lmysqlclient", and how distutils and the old code worked the order was always "-lrt" before "-lmysqlclient"
1 parent 27683d5 commit fc49fd5

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

lib/cpy_distutils.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import struct
3838
from subprocess import Popen, PIPE, STDOUT
3939
import sys
40+
import platform
4041

4142
ARCH_64BIT = sys.maxsize > 2**32 # Works with Python 2.6 and greater
4243

@@ -429,35 +430,33 @@ def _finalize_connector_c(self, connc_loc):
429430
copy_tree(os.path.join(connc_loc, 'lib'), self.connc_lib)
430431
copy_tree(os.path.join(connc_loc, 'include'), self.connc_include)
431432

433+
# Remove all but static libraries to force static linking
432434
for lib_file in os.listdir(self.connc_lib):
433435
if os.name == 'posix' and not lib_file.endswith('.a'):
434436
os.unlink(os.path.join(self.connc_lib, lib_file))
435437

436438
def fix_compiler(self):
437439
BuildExtDynamic.fix_compiler(self)
438440

439-
extra_compile_args = []
440-
extra_link_args = []
441+
include_dirs = []
442+
library_dirs = []
443+
libraries = []
441444

442445
if os.name == 'posix':
443-
extra_compile_args = [
444-
'-I%s' % self.connc_include
445-
]
446-
extra_link_args = [
447-
#'-lstdc++',
448-
'-L%s' % self.connc_lib,
449-
'-lmysqlclient',
450-
]
451-
452-
if not extra_compile_args and not extra_link_args:
453-
return
446+
include_dirs.append(self.connc_include)
447+
library_dirs.append(self.connc_lib)
448+
libraries.append("mysqlclient")
454449

455-
for ext in self.extensions:
456-
if extra_compile_args:
457-
ext.extra_compile_args.extend(extra_compile_args)
458-
if extra_link_args:
459-
ext.extra_link_args.extend(extra_link_args)
450+
# As we statically link and the "libmysqlclient.a" library
451+
# carry no information what it depends on, we need to
452+
# manually add library dependencies here.
453+
if platform.system() not in ["Darwin", "Windows"]:
454+
libraries.append("rt")
460455

456+
for ext in self.extensions:
457+
ext.include_dirs.extend(include_dirs)
458+
ext.library_dirs.extend(library_dirs)
459+
ext.libraries.extend(libraries)
461460

462461

463462
class InstallLib(install_lib):

setupinfo.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from distutils.core import Extension
2525
import os
2626
import sys
27-
import platform
2827

2928
from lib.cpy_distutils import (
3029
Install, InstallLib, BuildExtDynamic, BuildExtStatic
@@ -61,10 +60,6 @@
6160
name = 'mysql-connector-python'
6261
version = '{0}.{1}.{2}'.format(*VERSION[0:3])
6362

64-
extra_libraries = ['rt']
65-
if platform.system() in ["Darwin", "Windows"]:
66-
extra_libraries = []
67-
6863
extensions = [
6964
Extension("_mysql_connector",
7065
sources=[
@@ -75,7 +70,6 @@
7570
"src/force_cpp_linkage.cc",
7671
],
7772
include_dirs=['src/include'],
78-
libraries=extra_libraries,
7973
)
8074
]
8175

0 commit comments

Comments
 (0)