summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDown Thomas <downthomas@yahoo.com>2019-12-08 19:38:27 -0500
committerder richter <der.richter@gmx.de>2019-12-15 12:33:25 +0100
commit698a6a27473dfd2826b2726ad535764f5ebc2623 (patch)
tree5aa333b7bb14f045cc1cc617274195affd5f47f6
parent2dbe33ce838852fb5e16449b21cf438e7e1f2027 (diff)
downloadmpv-698a6a27473dfd2826b2726ad535764f5ebc2623.tar.bz2
mpv-698a6a27473dfd2826b2726ad535764f5ebc2623.tar.xz
osxbundle: simplify process_libraries() to eliminate leafs()
Instead of traversing across leafs() which can lead to an infinite loop issue with cross-linked libraries, use the dictionary (libs_dict) created by libraries() to create a set (libs_set) of every unique library. Every value in libs_dict is also a key in libs_dict, so every unique library linked to mpv will be a key in libs_dict. Use set() on libs_dict to return a set of the keys from libs_dict, and remove binary from the set so that a duplicate of the binary is not added to the libs directory. Iterate over libs_set to bundle dylibs while using the libs_dict to determine which install_names to change.
-rwxr-xr-xTOOLS/dylib-unhell.py30
1 files changed, 8 insertions, 22 deletions
diff --git a/TOOLS/dylib-unhell.py b/TOOLS/dylib-unhell.py
index fe26f38e67..19ef4118fa 100755
--- a/TOOLS/dylib-unhell.py
+++ b/TOOLS/dylib-unhell.py
@@ -61,29 +61,19 @@ def libraries(objfile, result = dict()):
return result
-def leafs(libs_dict, processed = []):
- result = []
- processed = set(processed)
-
- for objfile, libs in libs_dict.items():
- if libs <= processed:
- result.append(objfile)
-
- return result
-
def lib_path(binary):
return os.path.join(os.path.dirname(binary), 'lib')
def lib_name(lib):
return os.path.join("@executable_path", "lib", os.path.basename(lib))
-def process_libraries(libs_dict, binary, processed = []):
- ls = leafs(libs_dict, processed)
- diff = set(ls) - set(processed)
- if diff == set([binary]):
- return
+def process_libraries(libs_dict, binary):
+ libs_set = set(libs_dict)
+ # Remove binary from libs_set to prevent a duplicate of the binary being
+ # added to the libs directory.
+ libs_set.remove(binary)
- for src in diff:
+ for src in libs_set:
name = lib_name(src)
dst = os.path.join(lib_path(binary), os.path.basename(src))
@@ -94,12 +84,10 @@ def process_libraries(libs_dict, binary, processed = []):
if src in libs_dict[binary]:
install_name_tool_change(src, name, binary)
- for p in processed:
+ for p in libs_set:
if p in libs_dict[src]:
install_name_tool_change(p, lib_name(p), dst)
- return ls
-
def process_swift_libraries(binary):
command = ['xcrun', '--find', 'swift-stdlib-tool']
swiftStdlibTool = subprocess.check_output(command, universal_newlines=True).strip()
@@ -130,9 +118,7 @@ def main():
libs = libraries(binary)
print(">> copying and processing all linked libraries")
- libs_processed = process_libraries(libs, binary)
- while libs_processed is not None:
- libs_processed = process_libraries(libs, binary, libs_processed)
+ process_libraries(libs, binary)
print(">> removing rpath definitions towards dev tools")
remove_dev_tools_rapths(binary)