mirror of https://github.com/mpv-player/mpv.git
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.
This commit is contained in:
parent
2dbe33ce83
commit
698a6a2747
|
@ -61,29 +61,19 @@ def libraries(objfile, result = dict()):
|
||||||
|
|
||||||
return result
|
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):
|
def lib_path(binary):
|
||||||
return os.path.join(os.path.dirname(binary), 'lib')
|
return os.path.join(os.path.dirname(binary), 'lib')
|
||||||
|
|
||||||
def lib_name(lib):
|
def lib_name(lib):
|
||||||
return os.path.join("@executable_path", "lib", os.path.basename(lib))
|
return os.path.join("@executable_path", "lib", os.path.basename(lib))
|
||||||
|
|
||||||
def process_libraries(libs_dict, binary, processed = []):
|
def process_libraries(libs_dict, binary):
|
||||||
ls = leafs(libs_dict, processed)
|
libs_set = set(libs_dict)
|
||||||
diff = set(ls) - set(processed)
|
# Remove binary from libs_set to prevent a duplicate of the binary being
|
||||||
if diff == set([binary]):
|
# added to the libs directory.
|
||||||
return
|
libs_set.remove(binary)
|
||||||
|
|
||||||
for src in diff:
|
for src in libs_set:
|
||||||
name = lib_name(src)
|
name = lib_name(src)
|
||||||
dst = os.path.join(lib_path(binary), os.path.basename(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]:
|
if src in libs_dict[binary]:
|
||||||
install_name_tool_change(src, name, binary)
|
install_name_tool_change(src, name, binary)
|
||||||
|
|
||||||
for p in processed:
|
for p in libs_set:
|
||||||
if p in libs_dict[src]:
|
if p in libs_dict[src]:
|
||||||
install_name_tool_change(p, lib_name(p), dst)
|
install_name_tool_change(p, lib_name(p), dst)
|
||||||
|
|
||||||
return ls
|
|
||||||
|
|
||||||
def process_swift_libraries(binary):
|
def process_swift_libraries(binary):
|
||||||
command = ['xcrun', '--find', 'swift-stdlib-tool']
|
command = ['xcrun', '--find', 'swift-stdlib-tool']
|
||||||
swiftStdlibTool = subprocess.check_output(command, universal_newlines=True).strip()
|
swiftStdlibTool = subprocess.check_output(command, universal_newlines=True).strip()
|
||||||
|
@ -130,9 +118,7 @@ def main():
|
||||||
libs = libraries(binary)
|
libs = libraries(binary)
|
||||||
|
|
||||||
print(">> copying and processing all linked libraries")
|
print(">> copying and processing all linked libraries")
|
||||||
libs_processed = process_libraries(libs, binary)
|
process_libraries(libs, binary)
|
||||||
while libs_processed is not None:
|
|
||||||
libs_processed = process_libraries(libs, binary, libs_processed)
|
|
||||||
|
|
||||||
print(">> removing rpath definitions towards dev tools")
|
print(">> removing rpath definitions towards dev tools")
|
||||||
remove_dev_tools_rapths(binary)
|
remove_dev_tools_rapths(binary)
|
||||||
|
|
Loading…
Reference in New Issue