30
30
from distutils .errors import DistutilsExecError
31
31
from distutils .util import get_platform
32
32
from distutils .version import LooseVersion
33
- from distutils .dir_util import copy_tree
33
+ from distutils .dir_util import copy_tree , mkpath
34
+ from distutils .sysconfig import get_python_lib
34
35
from distutils import log
35
36
from glob import glob
36
37
import os
@@ -167,6 +168,8 @@ def parse_mysql_config_info(options, stdout):
167
168
168
169
info ['version' ] = tuple ([int (v ) for v in ver .split ('.' )[0 :3 ]])
169
170
libs = shlex .split (info ['libs' ])
171
+ if ',' in libs [1 ]:
172
+ libs .pop (1 )
170
173
info ['lib_dir' ] = libs [0 ].replace ('-L' , '' )
171
174
info ['libs' ] = [ lib .replace ('-l' , '' ) for lib in libs [1 :] ]
172
175
if platform .uname ()[0 ] == 'SunOS' :
@@ -176,9 +179,10 @@ def parse_mysql_config_info(options, stdout):
176
179
for lib in info ['libs' ]:
177
180
log .debug ("# {0}" .format (lib ))
178
181
libs = shlex .split (info ['libs_r' ])
182
+ if ',' in libs [1 ]:
183
+ libs .pop (1 )
179
184
info ['lib_r_dir' ] = libs [0 ].replace ('-L' , '' )
180
185
info ['libs_r' ] = [ lib .replace ('-l' , '' ) for lib in libs [1 :] ]
181
-
182
186
info ['include' ] = [x .strip () for x in info ['include' ].split ('-I' )[1 :]]
183
187
184
188
return info
@@ -301,6 +305,28 @@ def initialize_options(self):
301
305
self .with_protobuf_lib_dir = None
302
306
self .with_protoc = None
303
307
308
+ def _copy_vendor_libraries (self ):
309
+ if self .with_mysql_capi and platform .system () == "Darwin" :
310
+ data_files = []
311
+ openssl_libs = ["libssl.1.0.0.dylib" , "libcrypto.1.0.0.dylib" ]
312
+ vendor_folder = "vendor"
313
+ mkpath (os .path .join (os .getcwd (), vendor_folder ))
314
+
315
+ # Copy OpenSSL libraries to 'vendor' folder
316
+ log .info ("Copying OpenSSL libraries" )
317
+ for filename in openssl_libs :
318
+ data_files .append (os .path .join (vendor_folder , filename ))
319
+ src = os .path .join (self .with_mysql_capi , "lib" , filename )
320
+ dst = os .path .join (os .getcwd (), vendor_folder )
321
+ log .info ("Copying {0} -> {1}" .format (src , dst ))
322
+ shutil .copy (src , dst )
323
+
324
+ # Add data_files to distribution
325
+ self .distribution .data_files = [(
326
+ os .path .join (get_python_lib (), vendor_folder ),
327
+ data_files
328
+ )]
329
+
304
330
def _finalize_connector_c (self , connc_loc ):
305
331
"""Finalize the --with-connector-c command line argument
306
332
"""
@@ -427,6 +453,8 @@ def finalize_options(self):
427
453
('with_protobuf_lib_dir' , 'with_protobuf_lib_dir' ),
428
454
('with_protoc' , 'with_protoc' ))
429
455
456
+ self ._copy_vendor_libraries ()
457
+
430
458
build_ext .finalize_options (self )
431
459
432
460
print ("# Python architecture: {0}" .format (py_arch ))
@@ -534,7 +562,7 @@ def fix_compiler(self):
534
562
if self .extra_compile_args :
535
563
ext .extra_compile_args .extend (self .extra_compile_args .split ())
536
564
# Add extra link args
537
- if self .extra_link_args :
565
+ if self .extra_link_args and ext . name != "_mysqlxpb" :
538
566
ext .extra_link_args .extend (self .extra_link_args .split ())
539
567
# Add system headers
540
568
for sysheader in sysheaders :
@@ -562,7 +590,7 @@ def run(self):
562
590
if self .extra_compile_args :
563
591
ext .extra_compile_args .extend (self .extra_compile_args .split ())
564
592
# Add extra link args
565
- if self .extra_link_args :
593
+ if self .extra_link_args and ext . name != "_mysqlxpb" :
566
594
ext .extra_link_args .extend (self .extra_link_args .split ())
567
595
if self .with_mysqlxpb_cext :
568
596
self .run_protoc ()
@@ -576,6 +604,25 @@ def run(self):
576
604
self .run_protoc ()
577
605
self .real_build_extensions ()
578
606
607
+ if platform .system () == "Darwin" :
608
+ cmd_libssl = [
609
+ "install_name_tool" , "-change" , "libssl.1.0.0.dylib" ,
610
+ "@loader_path/vendor/libssl.1.0.0.dylib" ,
611
+ build_ext .get_ext_fullpath (self , "_mysql_connector" )
612
+ ]
613
+ log .info ("Executing: {0}" .format (" " .join (cmd_libssl )))
614
+ proc = Popen (cmd_libssl , stdout = PIPE , universal_newlines = True )
615
+ stdout , _ = proc .communicate ()
616
+
617
+ cmd_libcrypto = [
618
+ "install_name_tool" , "-change" , "libcrypto.1.0.0.dylib" ,
619
+ "@loader_path/vendor/libcrypto.1.0.0.dylib" ,
620
+ build_ext .get_ext_fullpath (self , "_mysql_connector" )
621
+ ]
622
+ log .info ("Executing: {0}" .format (" " .join (cmd_libcrypto )))
623
+ proc = Popen (cmd_libcrypto , stdout = PIPE , universal_newlines = True )
624
+ stdout , _ = proc .communicate ()
625
+
579
626
580
627
class BuildExtStatic (BuildExtDynamic ):
581
628
@@ -584,6 +631,8 @@ class BuildExtStatic(BuildExtDynamic):
584
631
user_options = build_ext .user_options + CEXT_OPTIONS
585
632
586
633
def finalize_options (self ):
634
+ self ._copy_vendor_libraries ()
635
+
587
636
install_obj = self .distribution .get_command_obj ('install' )
588
637
install_obj .with_mysql_capi = self .with_mysql_capi
589
638
install_obj .with_protobuf_include_dir = self .with_protobuf_include_dir
@@ -746,7 +795,7 @@ def fix_compiler(self):
746
795
if self .extra_compile_args :
747
796
ext .extra_compile_args .extend (self .extra_compile_args .split ())
748
797
# Add extra link args
749
- if self .extra_link_args :
798
+ if self .extra_link_args and ext . name != "_mysqlxpb" :
750
799
ext .extra_link_args .extend (self .extra_link_args .split ())
751
800
752
801
0 commit comments