Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 14 matching lines...) Expand all Loading... | |
| 25 generator_default_variables[dirname] = '!!!' | 25 generator_default_variables[dirname] = '!!!' |
| 26 | 26 |
| 27 for unused in ['RULE_INPUT_PATH', 'RULE_INPUT_ROOT', 'RULE_INPUT_NAME', | 27 for unused in ['RULE_INPUT_PATH', 'RULE_INPUT_ROOT', 'RULE_INPUT_NAME', |
| 28 'RULE_INPUT_DIRNAME', 'RULE_INPUT_EXT', | 28 'RULE_INPUT_DIRNAME', 'RULE_INPUT_EXT', |
| 29 'EXECUTABLE_PREFIX', 'EXECUTABLE_SUFFIX', | 29 'EXECUTABLE_PREFIX', 'EXECUTABLE_SUFFIX', |
| 30 'STATIC_LIB_PREFIX', 'STATIC_LIB_SUFFIX', | 30 'STATIC_LIB_PREFIX', 'STATIC_LIB_SUFFIX', |
| 31 'SHARED_LIB_PREFIX', 'SHARED_LIB_SUFFIX', | 31 'SHARED_LIB_PREFIX', 'SHARED_LIB_SUFFIX', |
| 32 'CONFIGURATION_NAME']: | 32 'CONFIGURATION_NAME']: |
| 33 generator_default_variables[unused] = '' | 33 generator_default_variables[unused] = '' |
| 34 | 34 |
| 35 def __MakeRelativeTargetName(path): | 35 def __MakeRelativeTargetName(path, toplevel_dir): |
| 36 """Converts a gyp target name into a relative name. For example, the path to a | 36 """Converts a gyp target name into a relative name. For example, the path to a |
| 37 gyp file may be something like c:\foo\bar.gyp:target, this converts it to | 37 gyp file may be something like c:\foo\bar.gyp:target, this converts it to |
| 38 bar.gyp. | 38 bar.gyp. |
| 39 """ | 39 """ |
| 40 prune_path = os.getcwd() | 40 if path.startswith(toplevel_dir): |
|
Mark Mentovai
2014/07/14 18:10:55
This should be
if path == toplevel_dir or path.s
| |
| 41 if path.startswith(prune_path): | 41 path = path[len(toplevel_dir):] |
| 42 path = path[len(prune_path):] | |
| 43 if len(path) and path.startswith(os.sep): | 42 if len(path) and path.startswith(os.sep): |
| 44 path = path[len(os.sep):] | 43 path = path[len(os.sep):] |
| 45 # Gyp paths are always posix style. | 44 # Gyp paths are always posix style. |
| 46 path = path.replace('\\', '/') | 45 path = path.replace('\\', '/') |
| 47 if path.endswith('#target'): | 46 if path.endswith('#target'): |
| 48 path = path[0:len(path) - len('#target')] | 47 path = path[0:len(path) - len('#target')] |
| 49 return path | 48 return path |
| 50 | 49 |
| 51 def __ExtractBasePath(target): | 50 def __ExtractBasePath(target): |
| 52 """Extracts the path components of the specified gyp target path.""" | 51 """Extracts the path components of the specified gyp target path.""" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 | 120 |
| 122 class Target(object): | 121 class Target(object): |
| 123 """Holds information about a particular target: | 122 """Holds information about a particular target: |
| 124 sources: set of source files defined by this target. This includes inputs to | 123 sources: set of source files defined by this target. This includes inputs to |
| 125 actions and rules. | 124 actions and rules. |
| 126 deps: list of direct dependencies.""" | 125 deps: list of direct dependencies.""" |
| 127 def __init__(self): | 126 def __init__(self): |
| 128 self.sources = [] | 127 self.sources = [] |
| 129 self.deps = [] | 128 self.deps = [] |
| 130 | 129 |
| 131 def __GenerateTargets(target_list, target_dicts): | 130 def __GenerateTargets(target_list, target_dicts, toplevel_dir): |
| 132 """Generates a dictionary with the key the name of a target and the value a | 131 """Generates a dictionary with the key the name of a target and the value a |
| 133 Target.""" | 132 Target. |toplevel_dir| is the root of the source tree.""" |
| 134 targets = {} | 133 targets = {} |
| 135 | 134 |
| 136 # Queue of targets to visit. | 135 # Queue of targets to visit. |
| 137 targets_to_visit = target_list[:] | 136 targets_to_visit = target_list[:] |
| 138 | 137 |
| 139 while len(targets_to_visit) > 0: | 138 while len(targets_to_visit) > 0: |
| 140 absolute_target_name = targets_to_visit.pop() | 139 absolute_target_name = targets_to_visit.pop() |
| 141 # |absolute_target| may be an absolute path and may include #target. | 140 # |absolute_target| may be an absolute path and may include #target. |
| 142 # References to targets are relative, so we need to clean the name. | 141 # References to targets are relative, so we need to clean the name. |
| 143 relative_target_name = __MakeRelativeTargetName(absolute_target_name) | 142 relative_target_name = __MakeRelativeTargetName(absolute_target_name, |
| 143 toplevel_dir) | |
| 144 if relative_target_name in targets: | 144 if relative_target_name in targets: |
| 145 continue | 145 continue |
| 146 | 146 |
| 147 target = Target() | 147 target = Target() |
| 148 targets[relative_target_name] = target | 148 targets[relative_target_name] = target |
| 149 target.sources.extend(__ExtractSources(relative_target_name, | 149 target.sources.extend(__ExtractSources(relative_target_name, |
| 150 target_dicts[absolute_target_name])) | 150 target_dicts[absolute_target_name])) |
| 151 | 151 |
| 152 for dep in target_dicts[absolute_target_name].get('dependencies', []): | 152 for dep in target_dicts[absolute_target_name].get('dependencies', []): |
| 153 targets[relative_target_name].deps.append(__MakeRelativeTargetName(dep)) | 153 targets[relative_target_name].deps.append( |
| 154 __MakeRelativeTargetName(dep, toplevel_dir)) | |
| 154 targets_to_visit.append(dep) | 155 targets_to_visit.append(dep) |
| 155 | 156 |
| 156 return targets | 157 return targets |
| 157 | 158 |
| 158 def __GetFiles(params): | 159 def __GetFiles(params): |
| 159 """Returns the list of files to analyze, or None if none specified.""" | 160 """Returns the list of files to analyze, or None if none specified.""" |
| 160 generator_flags = params.get('generator_flags', {}) | 161 generator_flags = params.get('generator_flags', {}) |
| 161 file_path = generator_flags.get('file_path', None) | 162 file_path = generator_flags.get('file_path', None) |
| 162 if not file_path: | 163 if not file_path: |
| 163 return None | 164 return None |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 operating_system = 'linux' # Keep this legacy behavior for now. | 198 operating_system = 'linux' # Keep this legacy behavior for now. |
| 198 default_variables.setdefault('OS', operating_system) | 199 default_variables.setdefault('OS', operating_system) |
| 199 | 200 |
| 200 def GenerateOutput(target_list, target_dicts, data, params): | 201 def GenerateOutput(target_list, target_dicts, data, params): |
| 201 """Called by gyp as the final stage. Outputs results.""" | 202 """Called by gyp as the final stage. Outputs results.""" |
| 202 files = __GetFiles(params) | 203 files = __GetFiles(params) |
| 203 if not files: | 204 if not files: |
| 204 print 'Must specify files to analyze via file_path generator flag' | 205 print 'Must specify files to analyze via file_path generator flag' |
| 205 return | 206 return |
| 206 | 207 |
| 207 targets = __GenerateTargets(target_list, target_dicts) | 208 targets = __GenerateTargets(target_list, target_dicts, |
| 209 os.path.abspath(params['options'].toplevel_dir)) | |
| 208 | 210 |
| 209 files_set = frozenset(files) | 211 files_set = frozenset(files) |
| 210 found_in_all_sources = 0 | 212 found_in_all_sources = 0 |
| 211 for target_name, target in targets.iteritems(): | 213 for target_name, target in targets.iteritems(): |
| 212 sources = files_set.intersection(target.sources) | 214 sources = files_set.intersection(target.sources) |
| 213 if len(sources): | 215 if len(sources): |
| 214 print 'Found dependency' | 216 print 'Found dependency' |
| 215 return | 217 return |
| 216 | 218 |
| 217 print 'No dependencies' | 219 print 'No dependencies' |
| OLD | NEW |