-
Notifications
You must be signed in to change notification settings - Fork 37
/
mariadb_windows.py
executable file
·84 lines (73 loc) · 3.18 KB
/
mariadb_windows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#
# Windows configuration
#
import os
import platform
import sys
from packaging import version
from winreg import ConnectRegistry, OpenKey, QueryValueEx,\
HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_64KEY
class MariaDBConfiguration():
lib_dirs = []
libs = []
version = []
includes = []
extra_objects = []
extra_compile_args = []
extra_link_args = []
def get_config(options):
static = options["link_static"]
mariadb_dir = options["install_dir"]
required_version = "3.2.4"
if not os.path.exists(mariadb_dir):
try:
mariadb_dir = os.environ["MARIADB_CC_INSTALL_DIR"]
cc_version = ["", ""]
print("using environment configuration " + mariadb_dir)
except KeyError:
try:
local_reg = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
if platform.architecture()[0] == '32bit':
connector_key = OpenKey(local_reg,
'SOFTWARE\\MariaDB Corporation\\'
'MariaDB Connector C')
else:
connector_key = OpenKey(local_reg,
'SOFTWARE\\MariaDB Corporation\\'
'MariaDB Connector C 64-bit',
access=KEY_READ | KEY_WOW64_64KEY)
cc_version = QueryValueEx(connector_key, "Version")
if (version.Version(cc_version[0]) <
version.Version(required_version)):
print("MariaDB Connector/Python requires "
"MariaDB Connector/C "
">= %s (found version: %s") \
% (required_version, cc_version[0])
sys.exit(2)
mariadb_dir = QueryValueEx(connector_key, "InstallDir")[0]
except Exception:
print("Could not find InstallationDir of MariaDB Connector/C. "
"Please make sure MariaDB Connector/C is installed or "
"specify the InstallationDir of MariaDB Connector/C by "
"setting the environment variable "
"MARIADB_CC_INSTALL_DIR.")
sys.exit(3)
print("Found MariaDB Connector/C in '%s'" % mariadb_dir)
cfg = MariaDBConfiguration()
cfg.includes = [".\\include", mariadb_dir + "\\include", mariadb_dir +
"\\include\\mysql", mariadb_dir + "\\include\\mariadb",
mariadb_dir + "\\include\\mariadb\\mysql"]
cfg.lib_dirs = [mariadb_dir + "\\lib", mariadb_dir + "\\lib\\mariadb"]
cfg.libs = ["ws2_32", "advapi32", "kernel32", "shlwapi", "crypt32",
"secur32", "bcrypt"]
if static.lower() == "on" or static.lower() == "default":
cfg.libs.append("mariadbclient")
else:
print("dynamic")
cfg.extra_link_args = ["/NODEFAULTLIB:LIBCMT"]
cfg.extra_compile_args = ["/MD"]
f = open("./include/config_win.h", "w")
f.write("#define DEFAULT_PLUGINS_SUBDIR \"%s\\\\lib\\\\mariadb\\\\plugin\"" %
mariadb_dir.replace(""'\\', '\\\\'))
f.close()
return cfg