Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: pylib/gyp/common.py

Issue 18991011: On Windows, don't try to create relative paths across different drives (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright (c) 2012 Google Inc. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from __future__ import with_statement 5 from __future__ import with_statement
6 6
7 import errno 7 import errno
8 import filecmp 8 import filecmp
9 import os.path 9 import os.path
10 import re 10 import re
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 @memoize 124 @memoize
125 def RelativePath(path, relative_to): 125 def RelativePath(path, relative_to):
126 # Assuming both |path| and |relative_to| are relative to the current 126 # Assuming both |path| and |relative_to| are relative to the current
127 # directory, returns a relative path that identifies path relative to 127 # directory, returns a relative path that identifies path relative to
128 # relative_to. 128 # relative_to.
129 129
130 # Convert to normalized (and therefore absolute paths). 130 # Convert to normalized (and therefore absolute paths).
131 path = os.path.realpath(path) 131 path = os.path.realpath(path)
132 relative_to = os.path.realpath(relative_to) 132 relative_to = os.path.realpath(relative_to)
133 133
134 # On Windows, we can't create a relative path to a different drive, so just
135 # use the absolute path.
136 if os.name == 'nt':
scottmg 2013/07/19 16:51:17 i'm not sure whether this will work on cygwin... i
borenet 2013/07/19 17:58:42 Changed to use sys.platform == "win32". I just ve
137 if (os.path.splitdrive(path)[0].lower() !=
138 os.path.splitdrive(relative_to)[0].lower()):
139 return path
140
134 # Split the paths into components. 141 # Split the paths into components.
135 path_split = path.split(os.path.sep) 142 path_split = path.split(os.path.sep)
136 relative_to_split = relative_to.split(os.path.sep) 143 relative_to_split = relative_to.split(os.path.sep)
137 144
138 # Determine how much of the prefix the two paths share. 145 # Determine how much of the prefix the two paths share.
139 prefix_len = len(os.path.commonprefix([path_split, relative_to_split])) 146 prefix_len = len(os.path.commonprefix([path_split, relative_to_split]))
140 147
141 # Put enough ".." components to back up out of relative_to to the common 148 # Put enough ".." components to back up out of relative_to to the common
142 # prefix, and then append the part of path_split after the common prefix. 149 # prefix, and then append the part of path_split after the common prefix.
143 relative_split = [os.path.pardir] * (len(relative_to_split) - prefix_len) + \ 150 relative_split = [os.path.pardir] * (len(relative_to_split) - prefix_len) + \
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 return 489 return
483 visited.add(node) 490 visited.add(node)
484 visiting.add(node) 491 visiting.add(node)
485 for neighbor in get_edges(node): 492 for neighbor in get_edges(node):
486 Visit(neighbor) 493 Visit(neighbor)
487 visiting.remove(node) 494 visiting.remove(node)
488 ordered_nodes.insert(0, node) 495 ordered_nodes.insert(0, node)
489 for node in sorted(graph): 496 for node in sorted(graph):
490 Visit(node) 497 Visit(node)
491 return ordered_nodes 498 return ordered_nodes
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698