Bug #76350 C Extension fails to compile if mysql_config return more than one include dir
Submitted: 17 Mar 2015 13:03 Modified: 24 Mar 2017 15:42
Reporter: Guillaume Poulin Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:2.1.1 OS:Linux
Assigned to: Assigned Account CPU Architecture:Any

[17 Mar 2015 13:03] Guillaume Poulin
Description:
On my system, `mysql_config  --include` return `-I/usr/include/mysql -I/usr/include/mysql/..` which is correct. However, `lib/cpy_distutils.py` assumes that `mysql_config` will return only one folder. The attached patch solves the issue.

How to repeat:
`python setup.py --with-mysql-capi=/usr/bin/mysql_config` on a system where mysql_config return more than one include dirs.

Suggested fix:
diff -rupN mysql-connector-python-2.1.1/lib/cpy_distutils.py mysql-connector-python-2.1.1_patched/lib/cpy_distutils.py
--- mysql-connector-python-2.1.1/lib/cpy_distutils.py	2015-02-06 06:03:00.000000000 +0800
+++ mysql-connector-python-2.1.1_patched/lib/cpy_distutils.py	2015-03-17 20:35:46.501442835 +0800
@@ -159,7 +159,7 @@ def get_mysql_config_info(mysql_config):
     info['lib_r_dir'] = libs[0].replace('-L', '')
     info['libs_r'] = [ lib.replace('-l', '') for lib in libs[1:] ]
 
-    info['include'] = info['include'].replace('-I', '')
+    info['include'] = [x.strip() for x in info['include'].split('-I')[1:]]
 
     # Try to figure out the architecture
     info['arch'] = None
@@ -284,7 +284,7 @@ class BuildExtDynamic(build_ext):
                 else:
                     raise OSError("Unsupported platform: %s" % os.name)
 
-                include_dir = os.path.join(connc_loc, 'include')
+                include_dirs = [os.path.join(connc_loc, 'include')]
                 if os.name == 'nt':
                     libraries = ['libmysql']
                 else:
@@ -307,19 +307,20 @@ class BuildExtDynamic(build_ext):
                 log.error(err_version)
                 sys.exit(1)
 
-            include_dir = myc_info['include']
+            include_dirs = myc_info['include']
             libraries = myc_info['libs']
             library_dirs = myc_info['lib_dir']
             self._mysql_config_info = myc_info
             self.arch = self._mysql_config_info['arch']
             connc_64bit = self.arch == 'x86_64'
 
-        if not os.path.exists(include_dir):
-            log.error(err_invalid_loc, connc_loc)
-            sys.exit(1)
+        for include_dir in include_dirs:
+            if not os.path.exists(include_dir):
+                log.error(err_invalid_loc, connc_loc)
+                sys.exit(1)
 
         # Set up the build_ext class
-        self.include_dirs.append(include_dir)
+        self.include_dirs.extend(include_dirs)
         self.libraries.extend(libraries)
         self.library_dirs.append(library_dirs)
[19 Mar 2015 13:38] Geert Vanderkelen
Thanks for reporting this issue. Verified.

Which specific Linux distribution was used? Which MySQL package?
[25 Mar 2015 3:23] Guillaume Poulin
I'm using Gentoo with dev-db/mariadb-10.0.17. I looked at the code of mysql_config.sh and only mariadb version could produce more than one include folder. I understand that the support of mariadb is probably not a requirement of this project, however is the only issue that I faced when testing the C extension.
[24 Mar 2017 15:42] Paul Dubois
Posted by developer:
 
Noted in 2.1.6 changelog.

If the output from the mysql_config --include command included more
than one directory, the C Extension failed to compile.