From 584ab6d29bcd6af244177906d7f99a3088f63a78 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 31 Dec 2020 23:30:59 +0900 Subject: [PATCH 1/4] Support MYSQLCLIDNT_CFLAGS and MYSQLCLIENT_LDFLAGS --- setup_posix.py | 52 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/setup_posix.py b/setup_posix.py index 5602be84..91028cd1 100644 --- a/setup_posix.py +++ b/setup_posix.py @@ -19,9 +19,9 @@ def dequote(s): def mysql_config(what): - from os import popen - - f = popen("{} --{}".format(_mysql_config_path, what)) + cmd = "{} --{}".format(_mysql_config_path, what) + print(cmd) + f = os.popen(cmd) data = f.read().strip().split() ret = f.close() if ret: @@ -29,6 +29,7 @@ def mysql_config(what): data = [] if ret / 256 > 1: raise OSError("{} not found".format(_mysql_config_path)) + print(data) return data @@ -62,27 +63,38 @@ def get_config(): static = True sys.argv.remove("--static") - libs = mysql_config("libs") + libs = os.environ.get("MYSQLCLIENT_LDFLAGS") + if libs: + libs = libs.strip().split() + else: + libs = mysql_config("libs") library_dirs = [dequote(i[2:]) for i in libs if i.startswith("-L")] libraries = [dequote(i[2:]) for i in libs if i.startswith("-l")] extra_link_args = [x for x in libs if not x.startswith(("-l", "-L"))] - removable_compile_args = ("-I", "-L", "-l") - extra_compile_args = [ - i.replace("%", "%%") - for i in mysql_config("cflags") - if i[:2] not in removable_compile_args - ] + cflags = os.environ.get("MYSQLCLIENT_CFLAGS") + if cflags: + use_mysqlconfig_cflags = False + cflags = cflags.strip().split() + else: + use_mysqlconfig_cflags = True + cflags = mysql_config("cflags") + + include_dirs = [] + extra_compile_args = [] + + for a in cflags: + if a.startswith("-I"): + include_dirs.append(dequote(a[2:])) + elif a.startswith(("-L", "-l")): # This should be LIBS. + continue + extra_compile_args = [a.replace("%", "%%")] # Copy the arch flags for linking as well for i in range(len(extra_compile_args)): if extra_compile_args[i] == "-arch": extra_link_args += ["-arch", extra_compile_args[i + 1]] - include_dirs = [ - dequote(i[2:]) for i in mysql_config("include") if i.startswith("-I") - ] - if static: # properly handle mysql client libraries that are not called libmysqlclient client = None @@ -109,11 +121,12 @@ def get_config(): if client in libraries: libraries.remove(client) else: - # mysql_config may have "-lmysqlclient -lz -lssl -lcrypto", but zlib and - # ssl is not used by _mysql. They are needed only for static build. - for L in ("crypto", "ssl", "z"): - if L in libraries: - libraries.remove(L) + if use_mysqlconfig_cflags: + # mysql_config may have "-lmysqlclient -lz -lssl -lcrypto", but zlib and + # ssl is not used by _mysql. They are needed only for static build. + for L in ("crypto", "ssl", "z"): + if L in libraries: + libraries.remove(L) name = "mysqlclient" metadata["name"] = name @@ -138,6 +151,7 @@ def get_config(): if static: ext_options["language"] = "c++" + print("options: ", ext_options) return metadata, ext_options From eabd3b8fb52fb0f1fab4aa11a4e2a9489aa9fcd4 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 31 Dec 2020 23:44:33 +0900 Subject: [PATCH 2/4] fixup --- setup_posix.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/setup_posix.py b/setup_posix.py index 91028cd1..e76082ca 100644 --- a/setup_posix.py +++ b/setup_posix.py @@ -87,8 +87,9 @@ def get_config(): if a.startswith("-I"): include_dirs.append(dequote(a[2:])) elif a.startswith(("-L", "-l")): # This should be LIBS. - continue - extra_compile_args = [a.replace("%", "%%")] + pass + else: + extra_compile_args = [a.replace("%", "%%")] # Copy the arch flags for linking as well for i in range(len(extra_compile_args)): @@ -151,7 +152,10 @@ def get_config(): if static: ext_options["language"] = "c++" - print("options: ", ext_options) + print("ext_options:") + for k, v in ext_options.items(): + print(" {}: {}".format(k, v)) + return metadata, ext_options From dbd6df5ab7e08eb0c35a0ae9fdc921ffe0afa4f9 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 31 Dec 2020 23:45:38 +0900 Subject: [PATCH 3/4] black --- setup_posix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup_posix.py b/setup_posix.py index e76082ca..481610c1 100644 --- a/setup_posix.py +++ b/setup_posix.py @@ -86,7 +86,7 @@ def get_config(): for a in cflags: if a.startswith("-I"): include_dirs.append(dequote(a[2:])) - elif a.startswith(("-L", "-l")): # This should be LIBS. + elif a.startswith(("-L", "-l")): # This should be LIBS. pass else: extra_compile_args = [a.replace("%", "%%")] From 9e96c2f1559cfdad6be226c8e57d6187d6f8f5b1 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 31 Dec 2020 23:51:01 +0900 Subject: [PATCH 4/4] Add "-std=c99" by default --- setup_posix.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/setup_posix.py b/setup_posix.py index 481610c1..e556f5c5 100644 --- a/setup_posix.py +++ b/setup_posix.py @@ -81,7 +81,7 @@ def get_config(): cflags = mysql_config("cflags") include_dirs = [] - extra_compile_args = [] + extra_compile_args = ["-std=c99"] for a in cflags: if a.startswith("-I"): @@ -89,12 +89,15 @@ def get_config(): elif a.startswith(("-L", "-l")): # This should be LIBS. pass else: - extra_compile_args = [a.replace("%", "%%")] + extra_compile_args.append(a.replace("%", "%%")) # Copy the arch flags for linking as well - for i in range(len(extra_compile_args)): - if extra_compile_args[i] == "-arch": + try: + i = extra_compile_args.index("-arch") + if "-arch" not in extra_link_args: extra_link_args += ["-arch", extra_compile_args[i + 1]] + except ValueError: + pass if static: # properly handle mysql client libraries that are not called libmysqlclient