in mysql-connector-python/cpydist/__init__.py [0:0]
def run(self):
"""Run the command."""
# Generate docs/INFO_SRC
write_info_src(VERSION_TEXT)
disabled = [] # Extensions to be disabled
for ext in self.extensions:
if ext.name == "_mysql_connector":
if not self.with_mysql_capi:
self.log.warning(
"The '_mysql_connector' C extension will not be built"
)
disabled.append(ext)
continue
# Add extra compile args
if self.extra_compile_args:
ext.extra_compile_args.extend(self.extra_compile_args.split())
# Add extra link args
if self.extra_link_args:
ext.extra_link_args.extend(self.extra_link_args.split())
# Add -rpath if the platform is Linux
if platform.system() == "Linux" and not self.skip_vendor:
ext.extra_link_args.extend(["-Wl,-rpath,$ORIGIN/mysql/vendor"])
# Add include dirs
if self.with_openssl_include_dir:
ext.include_dirs.append(self.with_openssl_include_dir)
if "include_dirs" in self._mysql_info:
ext.include_dirs.extend(self._mysql_info["include_dirs"])
# Add library dirs
ext.library_dirs.append(self._build_mysql_lib_dir)
if "library_dirs" in self._mysql_info:
ext.library_dirs.extend(self._mysql_info["library_dirs"])
if self.with_openssl_lib_dir:
ext.library_dirs.append(self.with_openssl_lib_dir)
# Add libraries
if "libraries" in self._mysql_info:
ext.libraries.extend(self._mysql_info["libraries"])
# Suppress unknown pragmas
if os.name == "posix":
ext.extra_compile_args.append("-Wno-unknown-pragmas")
if os.name != "nt":
is_macos = platform.system() == "Darwin"
cc = os.environ.get("CC", "clang" if is_macos else "gcc")
cxx = os.environ.get("CXX", "clang++" if is_macos else "g++")
cmd_cc_ver = [cc, "-v"]
self.log.info("Executing: %s", " ".join(cmd_cc_ver))
proc = Popen(cmd_cc_ver, stdout=PIPE, universal_newlines=True)
self.log.info(proc.communicate())
cmd_cxx_ver = [cxx, "-v"]
self.log.info("Executing: %s", " ".join(cmd_cxx_ver))
proc = Popen(cmd_cxx_ver, stdout=PIPE, universal_newlines=True)
self.log.info(proc.communicate())
# Remove disabled extensions
for ext in disabled:
self.extensions.remove(ext)
build_ext.run(self)
# Change @loader_path if the platform is MacOS
if platform.system() == "Darwin" and self.with_openssl_lib_dir:
for ext in self.extensions:
if ext.name == "_mysql_connector":
libssl, libcrypto = self._get_openssl_libs()
cmd_libssl = [
"install_name_tool",
"-change",
libssl,
f"@loader_path/mysql/vendor/{libssl}",
build_ext.get_ext_fullpath(self, "_mysql_connector"),
]
self.log.info("Executing: %s", " ".join(cmd_libssl))
proc = Popen(cmd_libssl, stdout=PIPE, universal_newlines=True)
proc.communicate()
cmd_libcrypto = [
"install_name_tool",
"-change",
libcrypto,
f"@loader_path/mysql/vendor/{libcrypto}",
build_ext.get_ext_fullpath(self, "_mysql_connector"),
]
self.log.info("Executing: %s", " ".join(cmd_libcrypto))
proc = Popen(cmd_libcrypto, stdout=PIPE, universal_newlines=True)
proc.communicate()
# Generate docs/INFO_BIN
if self.with_mysql_capi:
mysql_version = self._get_mysql_version()
compiler = (
self.compiler.compiler_so[0]
if hasattr(self.compiler, "compiler_so")
else None
)
write_info_bin(mysql_version, compiler)