blob: ccb3c867f014272874f6b8ce405cc03e76b53f73 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Brad Bishopc342db32019-05-15 21:57:59 -04002#
Patrick Williams92b42cb2022-09-03 06:53:57 -05003# Copyright OpenEmbedded Contributors
4#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-only
6#
7
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008import sys
9import 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
14if len(sys.argv) != 2:
15 print("Usage is " + sys.argv[0] + "<directory>")
16 sys.exit(1)
17
18topdir = sys.argv[1]
19topdir = os.path.abspath(topdir)
20
21def 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
32for subdir, dirs, files in os.walk(topdir):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033 for f in dirs + files:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034 filep = os.path.join(subdir, f)
35 if os.path.islink(filep):
36 #print("Considering %s" % filep)
37 handlelink(filep, subdir)