mirror of
git://git.yoctoproject.org/poky.git
synced 2025-07-19 21:09:03 +02:00

Dead symlinks, or symlinks to existing files will show up in 'files' of an os.walk, but symlinks to existing directories show up in 'dirs', so we need to consider both. As one example where this is an issue, the symlink from /usr/lib/ssl/certs was left pointing to /etc/ssl/certs rather than the relative path when the sdk was built on hosts where the latter exists. (From OE-Core rev: c5b522378fff13962a5187d9d09979866f805cb5) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
32 lines
967 B
Python
Executable File
32 lines
967 B
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
import os
|
|
|
|
# Take a sysroot directory and turn all the abolute symlinks and turn them into
|
|
# relative ones such that the sysroot is usable within another system.
|
|
|
|
if len(sys.argv) != 2:
|
|
print("Usage is " + sys.argv[0] + "<directory>")
|
|
sys.exit(1)
|
|
|
|
topdir = sys.argv[1]
|
|
topdir = os.path.abspath(topdir)
|
|
|
|
def handlelink(filep, subdir):
|
|
link = os.readlink(filep)
|
|
if link[0] != "/":
|
|
return
|
|
if link.startswith(topdir):
|
|
return
|
|
#print("Replacing %s with %s for %s" % (link, topdir+link, filep))
|
|
print("Replacing %s with %s for %s" % (link, os.path.relpath(topdir+link, subdir), filep))
|
|
os.unlink(filep)
|
|
os.symlink(os.path.relpath(topdir+link, subdir), filep)
|
|
|
|
for subdir, dirs, files in os.walk(topdir):
|
|
for f in dirs + files:
|
|
filep = os.path.join(subdir, f)
|
|
if os.path.islink(filep):
|
|
#print("Considering %s" % filep)
|
|
handlelink(filep, subdir)
|