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