Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve install_name fixing #212

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ build/$(APP_NAME).app/Contents/%: Contents/%
mkdir -p $(@D)
cp -a $< $@

build/$(APP_NAME).app/Contents/Resources/$(APP_NAME).dmg: build/$(APP_NAME)-build.sparsebundle build/$(APP_NAME).app/Contents/Resources/icon.icns fix_install_names.sh
build/$(APP_NAME).app/Contents/Resources/$(APP_NAME).dmg: build/$(APP_NAME)-build.sparsebundle build/$(APP_NAME).app/Contents/Resources/icon.icns relativize_install_names.py
[ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME)
hdiutil attach \
build/$(APP_NAME)-build.sparsebundle \
-shadow
cd $(VOLUME) \
&& "$(CURDIR)/fix_install_names.sh"
&& "$(CURDIR)/relativize_install_names.py"
cp build/$(APP_NAME).app/Contents/Resources/icon.icns $(VOLUME)/.VolumeIcon.icns
SetFile -c icnC $(VOLUME)/.VolumeIcon.icns
SetFile -a C $(VOLUME)
Expand Down
34 changes: 0 additions & 34 deletions fix_install_names.sh

This file was deleted.

51 changes: 51 additions & 0 deletions relativize_install_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3

import os
import subprocess
import itertools

from pathlib import Path

OPENFOAM_VERSION = int(subprocess.run(["bin/foamEtcFile", "-show-api"], stdout=subprocess.PIPE, check=True).stdout)

libs = {}

# Find names of OpenFOAM libraries
if OPENFOAM_VERSION < 2312: # References are already relative in OpenFOAM >= 2312
# See https://develop.openfoam.com/Development/openfoam/-/issues/2948
MPI_LIB_PATH = list(Path("platforms").glob("*/lib/*mpi*"))[0]
DUMMY_LIB_PTH = list(Path("platforms").glob("*/lib/dummy"))[0]

for openfoam_lib in Path("platforms").glob("*/lib/**/*.dylib"):
# Replace references to dummy MPI libraries with the actual MPI libraries
if openfoam_lib.parent == DUMMY_LIB_PTH:
libs[openfoam_lib] = MPI_LIB_PATH / openfoam_lib.name
else:
libs[openfoam_lib] = openfoam_lib

# Find names of dependency libraries
DEPS_PATH = Path("usr")
DEPS_PATH_RESOLVED = DEPS_PATH.resolve() # In case "usr" is a symlink
for dep_path in (DEPS_PATH_RESOLVED / "opt").iterdir():
dep_libs = itertools.chain(dep_path.rglob("*.so"), dep_path.rglob("*.dylib"))
for dep_lib in dep_libs:
libs[dep_lib] = DEPS_PATH / dep_lib.relative_to(DEPS_PATH_RESOLVED)


def relativize_install_names(file):
otool_stdout = subprocess.run(["otool", "-L", file], stdout=subprocess.PIPE, check=True).stdout.decode()
for old_path,new_path in libs.items():
if str(old_path.absolute()) in otool_stdout:
new_relative_path = os.path.relpath(new_path, start=file.parent)
subprocess.run(["install_name_tool",
"-change",
old_path.absolute(),
f"@loader_path/{new_relative_path}",
file])


for lib in Path("platforms").glob("*/lib/**/*.dylib"):
relativize_install_names(lib)

for bin in Path("platforms").glob("*/bin/*"):
relativize_install_names(bin)