Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | import sys |
| 7 | import os |
| 8 | |
| 9 | # Take a sysroot directory and turn all the abolute symlinks and turn them into |
| 10 | # relative ones such that the sysroot is usable within another system. |
| 11 | |
| 12 | if len(sys.argv) != 2: |
| 13 | print("Usage is " + sys.argv[0] + "<directory>") |
| 14 | sys.exit(1) |
| 15 | |
| 16 | topdir = sys.argv[1] |
| 17 | topdir = os.path.abspath(topdir) |
| 18 | |
| 19 | def handlelink(filep, subdir): |
| 20 | link = os.readlink(filep) |
| 21 | if link[0] != "/": |
| 22 | return |
| 23 | if link.startswith(topdir): |
| 24 | return |
| 25 | #print("Replacing %s with %s for %s" % (link, topdir+link, filep)) |
| 26 | print("Replacing %s with %s for %s" % (link, os.path.relpath(topdir+link, subdir), filep)) |
| 27 | os.unlink(filep) |
| 28 | os.symlink(os.path.relpath(topdir+link, subdir), filep) |
| 29 | |
| 30 | for subdir, dirs, files in os.walk(topdir): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | for f in dirs + files: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | filep = os.path.join(subdir, f) |
| 33 | if os.path.islink(filep): |
| 34 | #print("Considering %s" % filep) |
| 35 | handlelink(filep, subdir) |