diff --git a/pack/find_dlls.py b/pack/find_dlls.py index ee52047..5c824cb 100644 --- a/pack/find_dlls.py +++ b/pack/find_dlls.py @@ -2,12 +2,15 @@ import re import sys import ctypes.util +import concurrent.futures +from datetime import datetime +def get_datetime(): + now = datetime.now() + return now.strftime("%Y-%m-%d %H:%M:%S.%f") -def get_dependencies(file_path, checked_dlls=None): - if checked_dlls is None: - checked_dlls = set() - +def get_dependencies(file_path): + new_dlls = [] # ldd cannot find dlls for 32-bit platform result = subprocess.run( ["objdump", "-p", file_path], capture_output=True, text=True @@ -20,23 +23,47 @@ def get_dependencies(file_path, checked_dlls=None): if matches: dll_name = matches[0].strip() dll_path = ctypes.util.find_library(dll_name) - if dll_path and dll_path not in checked_dlls: - checked_dlls.add(dll_path) - checked_dlls.update(get_dependencies(dll_path, checked_dlls)) + if dll_path: + new_dlls.append(dll_path) - return checked_dlls + return new_dlls + +def get_all_dependencies(file_path): + checked_dlls=set() + with concurrent.futures.ThreadPoolExecutor() as executor: + try: + workers_num = executor._max_workers + print(f"Max {workers_num} workers", flush=True) + except Exception: + pass + futures = [executor.submit(get_dependencies, file_path)] + while futures: + for completed in concurrent.futures.as_completed(futures): + new_dlls = completed.result() + futures.remove(completed) + for dll in new_dlls: + if dll in checked_dlls: + continue + futures.append(executor.submit(get_dependencies, dll)) + checked_dlls.add(dll) + + return checked_dlls def copy_dependencies(file_path): - dependencies = get_dependencies(file_path) - print("dependencies:", flush=True) + + print(f"{get_datetime()} Getting dependencies", flush=True) + dependencies = get_all_dependencies(file_path) + print(f"dependencies: {len(dependencies)}", flush=True) print(dependencies, flush=True) + print(f"{get_datetime()} Copying dependencies", flush=True) for dependency in dependencies: # ignore dlls in system32 if "system32" in dependency.lower(): continue subprocess.run(["cp", dependency, "./"]) + print(f"{get_datetime()} Done", flush=True) copy_dependencies(sys.argv[1])