in mysqlx-connector-python/cpydist/__init__.py [0:0]
def _finalize_protobuf(self):
if not self.with_protobuf_include_dir:
self.with_protobuf_include_dir = os.environ.get(
"MYSQLXPB_PROTOBUF_INCLUDE_DIR"
)
if not self.with_protobuf_lib_dir:
self.with_protobuf_lib_dir = os.environ.get("MYSQLXPB_PROTOBUF_LIB_DIR")
if not self.with_protoc:
self.with_protoc = os.environ.get("MYSQLXPB_PROTOC")
if self.with_protobuf_include_dir:
self.log.info(
"Protobuf include directory: %s",
self.with_protobuf_include_dir,
)
if not os.path.isdir(self.with_protobuf_include_dir):
self.log.error("Protobuf include dir should be a directory")
sys.exit(1)
else:
self.log.error("Unable to find Protobuf include directory")
sys.exit(1)
if self.with_protobuf_lib_dir:
self.log.info("Protobuf library directory: %s", self.with_protobuf_lib_dir)
if not os.path.isdir(self.with_protobuf_lib_dir):
self.log.error("Protobuf library dir should be a directory")
sys.exit(1)
else:
self.log.error("Unable to find Protobuf library directory")
sys.exit(1)
if self.with_protoc:
self.log.info("Protobuf protoc binary: %s", self.with_protoc)
if not os.path.isfile(self.with_protoc):
self.log.error("Protobuf protoc binary is not valid")
sys.exit(1)
else:
self.log.error("Unable to find Protobuf protoc binary")
sys.exit(1)
if not os.path.exists(self._build_protobuf_lib_dir):
os.makedirs(self._build_protobuf_lib_dir)
self.log.info("Copying Protobuf libraries")
# load protobuf-related static libraries
libs = glob(os.path.join(self.with_protobuf_lib_dir, "libprotobuf*"))
# load absl-related static libraries
libs += glob(
os.path.join(self.with_protobuf_lib_dir, f"*absl_*.{ABSL_LIBS_EXT}")
)
libs += glob(
os.path.join(self.with_protobuf_lib_dir, f"*utf8_*.{ABSL_LIBS_EXT}")
)
for lib in libs:
if os.path.isfile(lib):
self.log.info("copying %s -> %s", lib, self._build_protobuf_lib_dir)
shutil.copy2(lib, self._build_protobuf_lib_dir)
# Remove all but static libraries to force static linking
if os.name == "posix":
self.log.info(
"Removing non-static Protobuf libraries from %s",
self._build_protobuf_lib_dir,
)
for lib in os.listdir(self._build_protobuf_lib_dir):
lib_path = os.path.join(self._build_protobuf_lib_dir, lib)
if os.path.isfile(lib_path) and not lib.endswith((".a", ".dylib")):
os.unlink(os.path.join(self._build_protobuf_lib_dir, lib))