mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 23:05:42 +00:00
Bug 1722540 - Fix gyp.common.RelativePath
's handling of case. r=firefox-build-system-reviewers,nalexander
For some reason, it's not using os.path.relpath, but also doesn't handle case sensitivity correctly, which os.path.relpath does. However, it has some differences with os.path.relpath that need to be kept: - os.path.relpath throws an exception when both paths have a different drive letter. - os.path.relpath returns os.path.curdir when both paths are identical. - the follow_path_symlink flag is not supported by os.path.relpath. Differential Revision: https://phabricator.services.mozilla.com/D121145
This commit is contained in:
parent
2ac943a89b
commit
3a8c76af74
18
third_party/python/gyp/pylib/gyp/common.py
vendored
18
third_party/python/gyp/pylib/gyp/common.py
vendored
@ -155,24 +155,12 @@ def RelativePath(path, relative_to, follow_path_symlink=True):
|
||||
os.path.splitdrive(relative_to)[0].lower()):
|
||||
return path
|
||||
|
||||
# Split the paths into components.
|
||||
path_split = path.split(os.path.sep)
|
||||
relative_to_split = relative_to.split(os.path.sep)
|
||||
|
||||
# Determine how much of the prefix the two paths share.
|
||||
prefix_len = len(os.path.commonprefix([path_split, relative_to_split]))
|
||||
|
||||
# Put enough ".." components to back up out of relative_to to the common
|
||||
# prefix, and then append the part of path_split after the common prefix.
|
||||
relative_split = [os.path.pardir] * (len(relative_to_split) - prefix_len) + \
|
||||
path_split[prefix_len:]
|
||||
|
||||
if len(relative_split) == 0:
|
||||
relative = os.path.relpath(path, relative_to)
|
||||
if relative == os.path.curdir:
|
||||
# The paths were the same.
|
||||
return ''
|
||||
|
||||
# Turn it back into a string and we're done.
|
||||
return os.path.join(*relative_split)
|
||||
return relative
|
||||
|
||||
|
||||
@memoize
|
||||
|
Loading…
Reference in New Issue
Block a user