Dixon/utils/fix_links.py
Russell Gilbert e8c3e0f8c2 Updates RobotNode build and deployment process.
Simplifies the RobotNode build process by linking directly to system gpiod libraries instead of including a local copy. This reduces redundancy and ensures compatibility with the system's gpiod installation.

Adds a deployment script for easier deployment to the robot, streamlining the update process.

Also introduces a script to automatically fix symlinks during cross-compilation, ensuring that links resolve correctly on the target system.
2026-02-17 17:13:16 +00:00

23 lines
908 B
Python

import os
import sys
def fix_links(root_dir):
root_dir = os.path.abspath(root_dir)
for root, dirs, files in os.walk(root_dir):
for name in files + dirs:
path = os.path.join(root, name)
if os.path.islink(path):
target = os.readlink(path)
if target.startswith('/'):
# Calculate the relative path from the current folder back to the sysroot
relative_to_sysroot = os.path.relpath(root_dir, root)
new_target = os.path.normpath(os.path.join(relative_to_sysroot, target.lstrip('/')))
print(f"Fixing: {path} -> {new_target}")
os.unlink(path)
os.symlink(new_target, path)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python3 fix_links.py <directory>")
else:
fix_links(sys.argv[1])