Index: pylib/gyp/common.py |
=================================================================== |
--- pylib/gyp/common.py (revision 1537) |
+++ pylib/gyp/common.py (working copy) |
@@ -128,8 +128,8 @@ |
# relative_to. |
# Convert to absolute (and therefore normalized paths). |
Nico
2012/12/21 22:52:08
Is the comment now out of date?
|
- path = os.path.abspath(path) |
- relative_to = os.path.abspath(relative_to) |
+ path = os.path.realpath(path) |
+ relative_to = os.path.realpath(relative_to) |
# Split the paths into components. |
path_split = path.split(os.path.sep) |
@@ -151,6 +151,20 @@ |
return os.path.join(*relative_split) |
+@memoize |
+def InvertRelativePath(path, toplevel_dir=None): |
+ """Given a path like foo/bar that is relative to toplevel_dir, return |
+ the inverse relative path back to the toplevel_dir. |
+ |
+ E.g. os.path.normpath(os.path.join(path, InvertRelativePath(path))) |
+ should always produce the empty string, unless the path contains symlinks. |
+ """ |
+ if not path: |
+ return path |
+ toplevel_dir = '.' if toplevel_dir is None else toplevel_dir |
+ return RelativePath(toplevel_dir, os.path.join(toplevel_dir, path)) |
+ |
+ |
def FixIfRelativePath(path, relative_to): |
# Like RelativePath but returns |path| unchanged if it is absolute. |
if os.path.isabs(path): |