feat: dylib shorter relative paths

This commit is contained in:
relikd
2025-09-04 23:38:30 +02:00
parent 5d91cf1985
commit 72737f6311

10
brew.py
View File

@@ -1902,6 +1902,13 @@ class Fixer:
parentDir = os.path.dirname(fname) parentDir = os.path.dirname(fname)
repl1 = parentDir.replace(Cellar.CELLAR, '@@HOMEBREW_CELLAR@@', 1) repl1 = parentDir.replace(Cellar.CELLAR, '@@HOMEBREW_CELLAR@@', 1)
repl2 = parentDir.replace(Cellar.ROOT, '@@HOMEBREW_PREFIX@@', 1) repl2 = parentDir.replace(Cellar.ROOT, '@@HOMEBREW_PREFIX@@', 1)
assert repl1.startswith('@@HOMEBREW_CELLAR@@') # ./cellar/pkg/version/
# check if opt-link points to the same package
_, pkgName, pkgVer, *subpath = repl1.split('/')
opt_prefix = f'@@HOMEBREW_PREFIX@@/opt/{pkgName}/'
repl_same = opt_prefix + '/'.join(subpath)
atime = os.path.getatime(fname) atime = os.path.getatime(fname)
mtime = os.path.getmtime(fname) mtime = os.path.getmtime(fname)
@@ -1910,6 +1917,9 @@ class Fixer:
if oldRef.startswith('@@HOMEBREW_CELLAR@@'): if oldRef.startswith('@@HOMEBREW_CELLAR@@'):
newRef = os.path.relpath(oldRef, repl1) newRef = os.path.relpath(oldRef, repl1)
elif oldRef.startswith('@@HOMEBREW_PREFIX@@'): elif oldRef.startswith('@@HOMEBREW_PREFIX@@'):
if oldRef.startswith(opt_prefix):
newRef = os.path.relpath(oldRef, repl_same)
else:
newRef = os.path.relpath(oldRef, repl2) newRef = os.path.relpath(oldRef, repl2)
elif oldRef.startswith('@@'): elif oldRef.startswith('@@'):
Log.warn('unhandled dylib link', oldRef, summary=True) Log.warn('unhandled dylib link', oldRef, summary=True)