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

Unified Diff: pylib/gyp/generator/analyzer.py

Issue 383893003: Fixes two bugs in analyzer (Closed) Base URL: http://gyp.googlecode.com/svn/trunk
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/analyzer/gyptest-analyzer.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pylib/gyp/generator/analyzer.py
===================================================================
--- pylib/gyp/generator/analyzer.py (revision 1948)
+++ pylib/gyp/generator/analyzer.py (working copy)
@@ -55,6 +55,23 @@
return ''
return target[0:(last_index + 1)]
+def __ResolveParent(path, base_path_components):
+ """Resolves |path|, which starts with at least one '../'. Returns an empty
+ string if the path shouldn't be considered. See __AddSources() for a
+ description of |base_path_components|."""
+ depth = 0
+ while path.startswith('../'):
+ depth += 1
+ path = path[3:]
+ # Relative includes may go outside the source tree. For example, an action may
+ # have inputs in /usr/include, which are not in the source tree.
+ if depth > len(base_path_components):
+ return ''
+ if depth == len(base_path_components):
+ return path
+ return '/'.join(base_path_components[0:len(base_path_components) - depth]) + \
+ '/' + path
+
def __AddSources(sources, base_path, base_path_components, result):
"""Extracts valid sources from |sources| and adds them to |result|. Each
source file is relative to |base_path|, but may contain '..'. To make
@@ -69,12 +86,9 @@
# variable expansion may lead to //.
source = source[0] + source[1:].replace('//', '/')
if source.startswith('../'):
- path_components = base_path_components[:]
- # Resolve relative paths.
- while source.startswith('../'):
- path_components.pop(len(path_components) - 1)
- source = source[3:]
- result.append('/'.join(path_components) + source)
+ source = __ResolveParent(source, base_path_components)
+ if len(source):
+ result.append(source)
continue
result.append(base_path + source)
« no previous file with comments | « no previous file | test/analyzer/gyptest-analyzer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698