Skip to content

Commit

Permalink
Fix rpaths for M1 dylibs that use libgfortan.
Browse files Browse the repository at this point in the history
  • Loading branch information
culler committed Nov 20, 2022
1 parent 54e872f commit 61f43db
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Sage_framework/fix_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def __init__(self, path):
self.rpaths.append(rpath.decode('ascii'))

def relative_path(self, path):
"""
Return a relative path from the directory containing this file to
the directory containing the file wiht the give path.
"""
nodes = path.split(os.path.sep)
try:
local_nodes = nodes[nodes.index('local'):]
Expand Down Expand Up @@ -89,7 +93,12 @@ def build_rpath(relpath):
else:
return prefix
for dylib in self.dylibs:
if dylib.startswith('/'):
if dylib.startswith('/opt'):
# Special case for libgfortan on arm64. Simulate the library being
# installed in our bundle.
installed_path = os.path.join(LOCAL_LIB, os.path.basename(dylib))
relpaths.append(self.relative_path(installed_path))
elif dylib.startswith('/'):
relpaths.append(self.relative_path(dylib))
elif dylib.startswith('@rpath'):
for rpath in rpaths:
Expand All @@ -100,11 +109,6 @@ def build_rpath(relpath):
relpaths.append(self.relative_path(expanded_dylib))
elif dylib.startswith('@'):
continue
# Special case for libgfortan on arm64. Simulate the library being
# installed in our bundle.
elif dylib.startswith('/opt'):
installed_path = os.path.join(LOCAL_LIB, os.path.basename(dylib))
relpaths.append(self.relative_path(installed_path))
else:
raise RuntimeError('Unrecognized load path %s'%dylib)
fixed = [rpath for rpath in self.rpaths if rpath.startswith('@loader_path')]
Expand Down Expand Up @@ -218,7 +222,6 @@ def fix_files(repo, directory):
with open(os.path.join(repo, 'sage', 'VERSION.txt')) as input_file:
m = get_version.match(input_file.readline())
sage_version = m.groups()[0]
#symlink = os.path.join(os.path.sep, 'var', 'tmp', 'sage-%s-current'%sage_version)
LOCAL_LIB = LOCAL_LIB.replace('X.X', sage_version)
repo = os.path.abspath(repo)
# fix_files(repo, symlink.encode('ascii'), directory)
fix_files(repo, directory)

0 comments on commit 61f43db

Please sign in to comment.