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

Side by Side Diff: pylib/gyp/generator/analyzer.py

Issue 534793002: Makes matching of build files work when absolute (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 3 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 | no next file » | 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 config_path) the path of a json file that dictates the files 7 the generator flag config_path) the path of a json file that dictates the files
8 and targets to search for. The following keys are supported: 8 and targets to search for. The following keys are supported:
9 files: list of paths (relative) of the files to search for. 9 files: list of paths (relative) of the files to search for.
10 targets: list of targets to search for. The target names are unqualified. 10 targets: list of targets to search for. The target names are unqualified.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if debug: 121 if debug:
122 print 'AddSource', org_source, result[len(result) - 1] 122 print 'AddSource', org_source, result[len(result) - 1]
123 123
124 124
125 def _ExtractSourcesFromAction(action, base_path, base_path_components, 125 def _ExtractSourcesFromAction(action, base_path, base_path_components,
126 results): 126 results):
127 if 'inputs' in action: 127 if 'inputs' in action:
128 _AddSources(action['inputs'], base_path, base_path_components, results) 128 _AddSources(action['inputs'], base_path, base_path_components, results)
129 129
130 130
131 def _ToLocalPath(toplevel_dir, path):
132 """Converts |path| to a path relative to |toplevel_dir|."""
133 if path == toplevel_dir:
134 return ''
135 if path.startswith(toplevel_dir + '/'):
scottmg 2014/09/02 22:06:45 will there be any problems with \ here?
sky 2014/09/02 22:11:29 Paths should have been mapped to / by the time we
136 return path[len(toplevel_dir) + len('/'):]
137 return path
138
139
131 def _ExtractSources(target, target_dict, toplevel_dir): 140 def _ExtractSources(target, target_dict, toplevel_dir):
132 # |target| is either absolute or relative and in the format of the OS. Gyp 141 # |target| is either absolute or relative and in the format of the OS. Gyp
133 # source paths are always posix. Convert |target| to a posix path relative to 142 # source paths are always posix. Convert |target| to a posix path relative to
134 # |toplevel_dir_|. This is done to make it easy to build source paths. 143 # |toplevel_dir_|. This is done to make it easy to build source paths.
135 base_path = _ToGypPath(target) 144 base_path = posixpath.dirname(_ToLocalPath(toplevel_dir, _ToGypPath(target)))
136 if base_path == toplevel_dir:
137 base_path = ''
138 elif base_path.startswith(toplevel_dir + '/'):
139 base_path = base_path[len(toplevel_dir) + len('/'):]
140 base_path = posixpath.dirname(base_path)
141 base_path_components = base_path.split('/') 145 base_path_components = base_path.split('/')
142 146
143 # Add a trailing '/' so that _AddSources() can easily build paths. 147 # Add a trailing '/' so that _AddSources() can easily build paths.
144 if len(base_path): 148 if len(base_path):
145 base_path += '/' 149 base_path += '/'
146 150
147 if debug: 151 if debug:
148 print 'ExtractSources', target, base_path 152 print 'ExtractSources', target, base_path
149 153
150 results = [] 154 results = []
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 except IOError: 220 except IOError:
217 raise Exception('Unable to open file ' + config_path) 221 raise Exception('Unable to open file ' + config_path)
218 except ValueError as e: 222 except ValueError as e:
219 raise Exception('Unable to parse config file ' + config_path + str(e)) 223 raise Exception('Unable to parse config file ' + config_path + str(e))
220 if not isinstance(config, dict): 224 if not isinstance(config, dict):
221 raise Exception('config_path must be a JSON file containing a dictionary') 225 raise Exception('config_path must be a JSON file containing a dictionary')
222 self.files = config.get('files', []) 226 self.files = config.get('files', [])
223 self.targets = set(config.get('targets', [])) 227 self.targets = set(config.get('targets', []))
224 228
225 229
226 def _WasBuildFileModified(build_file, data, files): 230 def _WasBuildFileModified(build_file, data, files, toplevel_dir):
227 """Returns true if the build file |build_file| is either in |files| or 231 """Returns true if the build file |build_file| is either in |files| or
228 one of the files included by |build_file| is in |files|.""" 232 one of the files included by |build_file| is in |files|. |toplevel_dir| is
229 if _ToGypPath(build_file) in files: 233 the root of the source tree."""
234 if _ToLocalPath(toplevel_dir, _ToGypPath(build_file)) in files:
230 if debug: 235 if debug:
231 print 'gyp file modified', build_file 236 print 'gyp file modified', build_file
232 return True 237 return True
233 238
234 # First element of included_files is the file itself. 239 # First element of included_files is the file itself.
235 if len(data[build_file]['included_files']) <= 1: 240 if len(data[build_file]['included_files']) <= 1:
236 return False 241 return False
237 242
238 for include_file in data[build_file]['included_files'][1:]: 243 for include_file in data[build_file]['included_files'][1:]:
239 # |included_files| are relative to the directory of the |build_file|. 244 # |included_files| are relative to the directory of the |build_file|.
240 rel_include_file = \ 245 rel_include_file = \
241 _ToGypPath(gyp.common.UnrelativePath(include_file, build_file)) 246 _ToGypPath(gyp.common.UnrelativePath(include_file, build_file))
242 if rel_include_file in files: 247 if _ToLocalPath(toplevel_dir, rel_include_file) in files:
243 if debug: 248 if debug:
244 print 'included gyp file modified, gyp_file=', build_file, \ 249 print 'included gyp file modified, gyp_file=', build_file, \
245 'included file=', rel_include_file 250 'included file=', rel_include_file
246 return True 251 return True
247 return False 252 return False
248 253
249 254
250 def _GetOrCreateTargetByName(targets, target_name): 255 def _GetOrCreateTargetByName(targets, target_name):
251 """Creates or returns the Target at targets[target_name]. If there is no 256 """Creates or returns the Target at targets[target_name]. If there is no
252 Target for |target_name| one is created. Returns a tuple of whether a new 257 Target for |target_name| one is created. Returns a tuple of whether a new
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 continue 307 continue
303 308
304 target.visited = True 309 target.visited = True
305 target.requires_build = _DoesTargetTypeRequireBuild( 310 target.requires_build = _DoesTargetTypeRequireBuild(
306 target_dicts[target_name]) 311 target_dicts[target_name])
307 target.is_executable = target_dicts[target_name]['type'] == 'executable' 312 target.is_executable = target_dicts[target_name]['type'] == 'executable'
308 313
309 build_file = gyp.common.ParseQualifiedTarget(target_name)[0] 314 build_file = gyp.common.ParseQualifiedTarget(target_name)[0]
310 if not build_file in build_file_in_files: 315 if not build_file in build_file_in_files:
311 build_file_in_files[build_file] = \ 316 build_file_in_files[build_file] = \
312 _WasBuildFileModified(build_file, data, files) 317 _WasBuildFileModified(build_file, data, files, toplevel_dir)
313 318
314 if build_file in build_files: 319 if build_file in build_files:
315 build_file_targets.add(target) 320 build_file_targets.add(target)
316 321
317 # If a build file (or any of its included files) is modified we assume all 322 # If a build file (or any of its included files) is modified we assume all
318 # targets in the file are modified. 323 # targets in the file are modified.
319 if build_file_in_files[build_file]: 324 if build_file_in_files[build_file]:
320 print 'matching target from modified build file', target_name 325 print 'matching target from modified build file', target_name
321 target.match_status = MATCH_STATUS_MATCHES 326 target.match_status = MATCH_STATUS_MATCHES
322 matching_targets.append(target) 327 matching_targets.append(target)
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 result_dict = { 'targets': matched_search_targets, 556 result_dict = { 'targets': matched_search_targets,
552 'status': found_dependency_string if matching_targets else 557 'status': found_dependency_string if matching_targets else
553 no_dependency_string, 558 no_dependency_string,
554 'build_targets': build_targets} 559 'build_targets': build_targets}
555 if warning: 560 if warning:
556 result_dict['warning'] = warning 561 result_dict['warning'] = warning
557 _WriteOutput(params, **result_dict) 562 _WriteOutput(params, **result_dict)
558 563
559 except Exception as e: 564 except Exception as e:
560 _WriteOutput(params, error=str(e)) 565 _WriteOutput(params, error=str(e))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698