Skip to content

Commit

Permalink
Remove old rpaths in macOS fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlienCowEatCake committed Sep 7, 2024
1 parent cbf6af6 commit 20da394
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
53 changes: 47 additions & 6 deletions buildscripts/helpers/dylibresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def _run_otool(filepath):
return result


def _has_rpath(filepath):
def _get_rpaths(filepath):
result = []
try:
otool_process = subprocess.Popen(['otool', '-l', '-arch', 'all', os.path.abspath(filepath)],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand All @@ -133,12 +134,30 @@ def _has_rpath(filepath):
otool_output = otool_output.decode('utf-8')
otool_process.wait()
if otool_process.returncode == 0:
is_rpath_command = False
rpath_path = ''
for string in otool_output.splitlines():
if re.match('\\s*cmd\\s+LC_RPATH\\s*$', string):
return True
return False
if re.match('\\s*Load\\s+command\\s+[0-9]+\\s*$', string) and is_rpath_command:
if rpath_path not in result:
result.append(rpath_path)
is_rpath_command = False
rpath_path = ''
elif re.match('\\s*cmd\\s+LC_RPATH\\s*$', string):
is_rpath_command = True
elif is_rpath_command:
rpath_path_match = re.match('\\s*path\\s+(.*)\\s+\\(offset\\s+[0-9]+\\)\\s*$', string)
if rpath_path_match:
rpath_path = rpath_path_match.group(1).strip()
if is_rpath_command and rpath_path not in result:
result.append(rpath_path)
except Exception:
pass
return result


def _has_rpath(filepath):
if _get_rpaths(filepath):
return True
return False


Expand All @@ -149,6 +168,20 @@ def _int_add_rpath(filepath, new_rpath):
return int_process.returncode == 0


def _int_delete_rpath(filepath, old_rpath):
int_process = subprocess.Popen(['install_name_tool', '-delete_rpath', old_rpath, os.path.abspath(filepath)],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
int_process.wait()
return int_process.returncode == 0


def _int_rpath(filepath, old_rpath, new_rpath):
int_process = subprocess.Popen(['install_name_tool', '-rpath', old_rpath, new_rpath, os.path.abspath(filepath)],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
int_process.wait()
return int_process.returncode == 0


def _int_id(filepath, new_id):
int_process = subprocess.Popen(['install_name_tool', '-id', new_id, os.path.abspath(filepath)],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand Down Expand Up @@ -403,8 +436,16 @@ def fixup_binaries(dir):
if _int_change(binary, otool_old, otool_new):
print(' -change', otool_old, otool_new)
if use_rpath:
if _int_add_rpath(binary, rpath):
print(' -add_rpath', rpath)
old_rpaths = _get_rpaths(binary)
if len(old_rpaths) == 1:
if old_rpaths[0] != rpath and _int_rpath(binary, old_rpaths[0], rpath):
print(' -rpath', old_rpaths[0], rpath)
else:
for old_rpath in old_rpaths:
if old_rpath != rpath and _int_delete_rpath(binary, old_rpath):
print(' -delete_rpath', old_rpath)
if rpath not in old_rpaths and _int_add_rpath(binary, rpath):
print(' -add_rpath', rpath)
print("======= Done =======")


Expand Down
1 change: 1 addition & 0 deletions buildscripts/osx_qt5.6_clang64_libstdcxx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ for iconengines_plugin in libqsvgicon.dylib ; do
cp -a "${QTPLUGINS_PATH}/iconengines/${iconengines_plugin}" "${PLUGINS_PATH}/iconengines/"
done
arch -x86_64 ${CMD_DEPLOY} "${APPNAME}.app" -verbose=2
/usr/bin/python3 "${SOURCE_PATH}/buildscripts/helpers/dylibresolver.py" "${APPNAME}.app" "${QT_PATH}/lib"
TRANSLATIONS_PATH="${RES_PATH}/translations"
mkdir -p "${TRANSLATIONS_PATH}"
for lang in $(find "${RES_PATH}" -name '*.lproj' | sed 's|.*/|| ; s|\..*||') ; do
Expand Down

0 comments on commit 20da394

Please sign in to comment.