Skip to content

Commit 666cd10

Browse files
author
Ritvik Rao
committed
workaround for mac
1 parent fe582e1 commit 666cd10

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

setup.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import os
3+
import re
34
import shutil
45
import platform
56
import subprocess
@@ -8,6 +9,7 @@
89
from setuptools.command.build_py import build_py
910
from setuptools.command.install import install
1011
from distutils.errors import DistutilsSetupError
12+
from distutils.command.install_lib import install_lib as _install_lib
1113
from distutils import log
1214
import distutils
1315

@@ -17,6 +19,7 @@
1719
build_mpi = False
1820

1921

22+
2023
def get_build_machine():
2124
machine = platform.machine()
2225
if machine == 'arm64' or machine == 'aarch64':
@@ -186,6 +189,7 @@ def build_libcharm(charm_src_dir, build_dir):
186189
for output_dir in lib_output_dirs:
187190
log.info('copying ' + os.path.relpath(lib_src_path) + ' to ' + os.path.relpath(output_dir))
188191
shutil.copy(lib_src_path, output_dir)
192+
189193

190194
# ---- copy charmrun ----
191195
charmrun_src_path = os.path.join(charm_src_dir, 'charm', 'bin', charmrun_filename)
@@ -258,6 +262,34 @@ def run(self):
258262
build_libcharm(os.path.join(os.getcwd(), 'charm_src'), self.build_lib)
259263
super(custom_build_ext, self).run()
260264

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+
261293

262294
extensions = []
263295
py_impl = platform.python_implementation()
@@ -370,6 +402,7 @@ def run(self):
370402
ext_modules=extensions,
371403
cmdclass = {'build_py': custom_build_py,
372404
'build_ext': custom_build_ext,
373-
'install': custom_install},
405+
'install': custom_install,
406+
'install_lib': _renameInstalled,},
374407
**additional_setup_keywords
375408
)

0 commit comments

Comments
 (0)