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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/analyzer/gyptest-analyzer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2014 Google Inc. All rights reserved. 1 # Copyright (c) 2014 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 """ 5 """
6 This script is intended for use as a GYP_GENERATOR. It takes as input (by way of 6 This script is intended for use as a GYP_GENERATOR. It takes as input (by way of
7 the generator flag file_path) the list of relative file paths to consider. If 7 the generator flag file_path) the list of relative file paths to consider. If
8 any target has at least one of the paths as a source (or input to an action or 8 any target has at least one of the paths as a source (or input to an action or
9 rule) then 'Found dependency' is output, otherwise 'No dependencies' is output. 9 rule) then 'Found dependency' is output, otherwise 'No dependencies' is output.
10 """ 10 """
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 path = path[0:len(path) - len('#target')] 48 path = path[0:len(path) - len('#target')]
49 return path 49 return path
50 50
51 def __ExtractBasePath(target): 51 def __ExtractBasePath(target):
52 """Extracts the path components of the specified gyp target path.""" 52 """Extracts the path components of the specified gyp target path."""
53 last_index = target.rfind('/') 53 last_index = target.rfind('/')
54 if last_index == -1: 54 if last_index == -1:
55 return '' 55 return ''
56 return target[0:(last_index + 1)] 56 return target[0:(last_index + 1)]
57 57
58 def __ResolveParent(path, base_path_components):
59 """Resolves |path|, which starts with at least one '../'. Returns an empty
60 string if the path shouldn't be considered. See __AddSources() for a
61 description of |base_path_components|."""
62 depth = 0
63 while path.startswith('../'):
64 depth += 1
65 path = path[3:]
66 # Relative includes may go outside the source tree. For example, an action may
67 # have inputs in /usr/include, which are not in the source tree.
68 if depth > len(base_path_components):
69 return ''
70 if depth == len(base_path_components):
71 return path
72 return '/'.join(base_path_components[0:len(base_path_components) - depth]) + \
73 '/' + path
74
58 def __AddSources(sources, base_path, base_path_components, result): 75 def __AddSources(sources, base_path, base_path_components, result):
59 """Extracts valid sources from |sources| and adds them to |result|. Each 76 """Extracts valid sources from |sources| and adds them to |result|. Each
60 source file is relative to |base_path|, but may contain '..'. To make 77 source file is relative to |base_path|, but may contain '..'. To make
61 resolving '..' easier |base_path_components| contains each of the 78 resolving '..' easier |base_path_components| contains each of the
62 directories in |base_path|. Additionally each source may contain variables. 79 directories in |base_path|. Additionally each source may contain variables.
63 Such sources are ignored as it is assumed dependencies on them are expressed 80 Such sources are ignored as it is assumed dependencies on them are expressed
64 and tracked in some other means.""" 81 and tracked in some other means."""
65 # NOTE: gyp paths are always posix style. 82 # NOTE: gyp paths are always posix style.
66 for source in sources: 83 for source in sources:
67 if not len(source) or source.startswith('!!!') or source.startswith('$'): 84 if not len(source) or source.startswith('!!!') or source.startswith('$'):
68 continue 85 continue
69 # variable expansion may lead to //. 86 # variable expansion may lead to //.
70 source = source[0] + source[1:].replace('//', '/') 87 source = source[0] + source[1:].replace('//', '/')
71 if source.startswith('../'): 88 if source.startswith('../'):
72 path_components = base_path_components[:] 89 source = __ResolveParent(source, base_path_components)
73 # Resolve relative paths. 90 if len(source):
74 while source.startswith('../'): 91 result.append(source)
75 path_components.pop(len(path_components) - 1)
76 source = source[3:]
77 result.append('/'.join(path_components) + source)
78 continue 92 continue
79 result.append(base_path + source) 93 result.append(base_path + source)
80 94
81 def __ExtractSourcesFromAction(action, base_path, base_path_components, 95 def __ExtractSourcesFromAction(action, base_path, base_path_components,
82 results): 96 results):
83 if 'inputs' in action: 97 if 'inputs' in action:
84 __AddSources(action['inputs'], base_path, base_path_components, results) 98 __AddSources(action['inputs'], base_path, base_path_components, results)
85 99
86 def __ExtractSources(target, target_dict): 100 def __ExtractSources(target, target_dict):
87 base_path = posixpath.dirname(target) 101 base_path = posixpath.dirname(target)
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 208
195 files_set = frozenset(files) 209 files_set = frozenset(files)
196 found_in_all_sources = 0 210 found_in_all_sources = 0
197 for target_name, target in targets.iteritems(): 211 for target_name, target in targets.iteritems():
198 sources = files_set.intersection(target.sources) 212 sources = files_set.intersection(target.sources)
199 if len(sources): 213 if len(sources):
200 print 'Found dependency' 214 print 'Found dependency'
201 return 215 return
202 216
203 print 'No dependencies' 217 print 'No dependencies'
OLDNEW
« 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