Index: pylib/gyp/generator/analyzer.py |
=================================================================== |
--- pylib/gyp/generator/analyzer.py (revision 1950) |
+++ pylib/gyp/generator/analyzer.py (working copy) |
@@ -14,6 +14,8 @@ |
import os |
import posixpath |
+debug = False |
+ |
generator_supports_multiple_toolsets = True |
generator_wants_static_library_dependencies_adjusted = False |
@@ -32,22 +34,6 @@ |
'CONFIGURATION_NAME']: |
generator_default_variables[unused] = '' |
-def __MakeRelativeTargetName(path): |
- """Converts a gyp target name into a relative name. For example, the path to a |
- gyp file may be something like c:\foo\bar.gyp:target, this converts it to |
- bar.gyp. |
- """ |
- prune_path = os.getcwd() |
- if path.startswith(prune_path): |
- path = path[len(prune_path):] |
- if len(path) and path.startswith(os.sep): |
- path = path[len(os.sep):] |
- # Gyp paths are always posix style. |
- path = path.replace('\\', '/') |
- if path.endswith('#target'): |
- path = path[0:len(path) - len('#target')] |
- return path |
- |
def __ExtractBasePath(target): |
"""Extracts the path components of the specified gyp target path.""" |
last_index = target.rfind('/') |
@@ -84,6 +70,7 @@ |
if not len(source) or source.startswith('!!!') or source.startswith('$'): |
continue |
# variable expansion may lead to //. |
+ org_source = source |
source = source[0] + source[1:].replace('//', '/') |
if source.startswith('../'): |
source = __ResolveParent(source, base_path_components) |
@@ -91,18 +78,36 @@ |
result.append(source) |
continue |
result.append(base_path + source) |
+ if debug: |
+ print 'AddSource', org_source, result[len(result) - 1] |
def __ExtractSourcesFromAction(action, base_path, base_path_components, |
results): |
if 'inputs' in action: |
__AddSources(action['inputs'], base_path, base_path_components, results) |
-def __ExtractSources(target, target_dict): |
- base_path = posixpath.dirname(target) |
+def __ExtractSources(target, target_dict, toplevel_dir): |
+ # |target| is either absolute or relative and in the format of the OS. Gyp |
+ # source paths are always posix. Convert |target| to a posix path relative to |
+ # |toplevel_dir_|. This is done to make it easy to build source paths. |
+ if os.sep == '\\' and os.altsep == '/': |
+ base_path = target.replace('\\', '/') |
+ else: |
+ base_path = target |
+ if base_path == toplevel_dir: |
+ base_path = '' |
+ elif base_path.startswith(toplevel_dir + '/'): |
+ base_path = base_path[len(toplevel_dir) + len('/'):] |
+ base_path = posixpath.dirname(base_path) |
base_path_components = base_path.split('/') |
+ |
# Add a trailing '/' so that __AddSources() can easily build paths. |
if len(base_path): |
base_path += '/' |
+ |
+ if debug: |
+ print 'ExtractSources', target, base_path |
+ |
results = [] |
if 'sources' in target_dict: |
__AddSources(target_dict['sources'], base_path, base_path_components, |
@@ -128,29 +133,27 @@ |
self.sources = [] |
self.deps = [] |
-def __GenerateTargets(target_list, target_dicts): |
+def __GenerateTargets(target_list, target_dicts, toplevel_dir): |
"""Generates a dictionary with the key the name of a target and the value a |
- Target.""" |
+ Target. |toplevel_dir| is the root of the source tree.""" |
targets = {} |
# Queue of targets to visit. |
targets_to_visit = target_list[:] |
while len(targets_to_visit) > 0: |
- absolute_target_name = targets_to_visit.pop() |
- # |absolute_target| may be an absolute path and may include #target. |
- # References to targets are relative, so we need to clean the name. |
- relative_target_name = __MakeRelativeTargetName(absolute_target_name) |
- if relative_target_name in targets: |
+ target_name = targets_to_visit.pop() |
+ if target_name in targets: |
continue |
target = Target() |
- targets[relative_target_name] = target |
- target.sources.extend(__ExtractSources(relative_target_name, |
- target_dicts[absolute_target_name])) |
+ targets[target_name] = target |
+ target.sources.extend(__ExtractSources(target_name, |
+ target_dicts[target_name], |
+ toplevel_dir)) |
- for dep in target_dicts[absolute_target_name].get('dependencies', []): |
- targets[relative_target_name].deps.append(__MakeRelativeTargetName(dep)) |
+ for dep in target_dicts[target_name].get('dependencies', []): |
+ targets[target_name].deps.append(dep) |
targets_to_visit.append(dep) |
return targets |
@@ -204,7 +207,12 @@ |
print 'Must specify files to analyze via file_path generator flag' |
return |
- targets = __GenerateTargets(target_list, target_dicts) |
+ toplevel_dir = os.path.abspath(params['options'].toplevel_dir) |
+ if os.sep == '\\' and os.altsep == '/': |
+ toplevel_dir = toplevel_dir.replace('\\', '/') |
+ if debug: |
+ print 'toplevel_dir', toplevel_dir |
+ targets = __GenerateTargets(target_list, target_dicts, toplevel_dir) |
files_set = frozenset(files) |
found_in_all_sources = 0 |
@@ -212,6 +220,8 @@ |
sources = files_set.intersection(target.sources) |
if len(sources): |
print 'Found dependency' |
+ if debug: |
+ print 'Found dependency in', target_name, target.sources |
return |
print 'No dependencies' |