summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/lib/oe/path.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py
index 683b09701c..1fdfa8724f 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -40,6 +40,33 @@ def relative(src, dest):
40 40
41 return os.path.sep.join(relpath) 41 return os.path.sep.join(relpath)
42 42
43def make_relative_symlink(path):
44 """ Convert an absolute symlink to a relative one """
45 if not os.path.islink(path):
46 return
47 link = os.readlink(path)
48 if not os.path.isabs(link):
49 return
50
51 # find the common ancestor directory
52 ancestor = path
53 depth = 0
54 while ancestor and not link.startswith(ancestor):
55 ancestor = ancestor.rpartition('/')[0]
56 depth += 1
57
58 if not ancestor:
59 print "make_relative_symlink() Error: unable to find the common ancestor of %s and its target" % path
60 return
61
62 base = link.partition(ancestor)[2].strip('/')
63 while depth > 1:
64 base = "../" + base
65 depth -= 1
66
67 os.remove(path)
68 os.symlink(base, path)
69
43def format_display(path, metadata): 70def format_display(path, metadata):
44 """ Prepare a path for display to the user. """ 71 """ Prepare a path for display to the user. """
45 rel = relative(metadata.getVar("TOPDIR", True), path) 72 rel = relative(metadata.getVar("TOPDIR", True), path)