|
1 | 1 | import sys
|
2 | 2 | import os
|
| 3 | +import re |
3 | 4 | import shutil
|
4 | 5 | import platform
|
5 | 6 | import subprocess
|
|
8 | 9 | from setuptools.command.build_py import build_py
|
9 | 10 | from setuptools.command.install import install
|
10 | 11 | from distutils.errors import DistutilsSetupError
|
| 12 | +from distutils.command.install_lib import install_lib as _install_lib |
11 | 13 | from distutils import log
|
12 | 14 | import distutils
|
13 | 15 |
|
|
17 | 19 | build_mpi = False
|
18 | 20 |
|
19 | 21 |
|
| 22 | + |
20 | 23 | def get_build_machine():
|
21 | 24 | machine = platform.machine()
|
22 | 25 | if machine == 'arm64' or machine == 'aarch64':
|
@@ -186,6 +189,7 @@ def build_libcharm(charm_src_dir, build_dir):
|
186 | 189 | for output_dir in lib_output_dirs:
|
187 | 190 | log.info('copying ' + os.path.relpath(lib_src_path) + ' to ' + os.path.relpath(output_dir))
|
188 | 191 | shutil.copy(lib_src_path, output_dir)
|
| 192 | + |
189 | 193 |
|
190 | 194 | # ---- copy charmrun ----
|
191 | 195 | charmrun_src_path = os.path.join(charm_src_dir, 'charm', 'bin', charmrun_filename)
|
@@ -258,6 +262,34 @@ def run(self):
|
258 | 262 | build_libcharm(os.path.join(os.getcwd(), 'charm_src'), self.build_lib)
|
259 | 263 | super(custom_build_ext, self).run()
|
260 | 264 |
|
| 265 | +def batch_rename(src, dst, src_dir_fd=None, dst_dir_fd=None): |
| 266 | + os.rename(src, dst, |
| 267 | + src_dir_fd=src_dir_fd, |
| 268 | + dst_dir_fd=dst_dir_fd) |
| 269 | + if "c_object_store" in src: |
| 270 | + direc = src.rsplit('/', 1) |
| 271 | + install_name_command = "install_name_tool -change lib/libcharm.dylib " |
| 272 | + install_name_command += direc[0] |
| 273 | + install_name_command += "/.libs/libcharm.dylib " |
| 274 | + install_name_command += direc[0] |
| 275 | + install_name_command += "/c_object_store.so" |
| 276 | + log.info(install_name_command) |
| 277 | + os.system(install_name_command) |
| 278 | + return dst |
| 279 | + |
| 280 | +class _renameInstalled(_install_lib): |
| 281 | + def __init__(self, *args, **kwargs): |
| 282 | + _install_lib.__init__(self, *args, **kwargs) |
| 283 | + |
| 284 | + def install(self): |
| 285 | + log.info("Renaming libraries") |
| 286 | + outfiles = _install_lib.install(self) |
| 287 | + matcher = re.compile('\.([^.]+)\.so$') |
| 288 | + renames = [batch_rename(file, re.sub(matcher, '.so', file)) |
| 289 | + for file in outfiles] |
| 290 | + return renames |
| 291 | + |
| 292 | + |
261 | 293 |
|
262 | 294 | extensions = []
|
263 | 295 | py_impl = platform.python_implementation()
|
@@ -370,6 +402,7 @@ def run(self):
|
370 | 402 | ext_modules=extensions,
|
371 | 403 | cmdclass = {'build_py': custom_build_py,
|
372 | 404 | 'build_ext': custom_build_ext,
|
373 |
| - 'install': custom_install}, |
| 405 | + 'install': custom_install, |
| 406 | + 'install_lib': _renameInstalled,}, |
374 | 407 | **additional_setup_keywords
|
375 | 408 | )
|
0 commit comments