in pkgs/rewrite-nix-paths-macho/rewrite-nix-paths-macho.py [0:0]
def get_dependencies(file_path: Path) -> List[str]:
"""
Uses `otool -l` to parse the LC_LOAD_DYLIB commands and find the
raw, un-resolved dependency paths stored in the binary.
"""
output = run_command(["otool", "-l", str(file_path)])
lines = output.splitlines()
dependencies = []
name_regex = re.compile(r"^\s+name\s+(\S+)\s+\(offset \d+\)")
for i, line in enumerate(lines):
if "cmd LC_LOAD_DYLIB" in line:
# The 'name' field, which contains the path, is consistently
# located two lines after the 'cmd' line in the otool output.
if i + 2 < len(lines):
name_line = lines[i + 2]
match = name_regex.match(name_line)
if match:
dependencies.append(match.group(1))
return dependencies