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 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 match_status: one of the MatchStatus values. | 171 match_status: one of the MatchStatus values. |
172 back_deps: set of Targets that have a dependency on this Target. | 172 back_deps: set of Targets that have a dependency on this Target. |
173 visited: used during iteration to indicate whether we've visited this target. | 173 visited: used during iteration to indicate whether we've visited this target. |
174 This is used for two iterations, once in building the set of Targets and | 174 This is used for two iterations, once in building the set of Targets and |
175 again in _GetBuildTargets(). | 175 again in _GetBuildTargets(). |
176 name: fully qualified name of the target. | 176 name: fully qualified name of the target. |
177 requires_build: True if the target type is such that it needs to be built. | 177 requires_build: True if the target type is such that it needs to be built. |
178 See _DoesTargetTypeRequireBuild for details. | 178 See _DoesTargetTypeRequireBuild for details. |
179 added_to_compile_targets: used when determining if the target was added to the | 179 added_to_compile_targets: used when determining if the target was added to the |
180 set of targets that needs to be built. | 180 set of targets that needs to be built. |
181 in_roots: true if this target is a descendant of one of the root nodes.""" | 181 in_roots: true if this target is a descendant of one of the root nodes. |
| 182 is_executable: true if the type of target is executable.""" |
182 def __init__(self, name): | 183 def __init__(self, name): |
183 self.deps = set() | 184 self.deps = set() |
184 self.match_status = MATCH_STATUS_TBD | 185 self.match_status = MATCH_STATUS_TBD |
185 self.back_deps = set() | 186 self.back_deps = set() |
186 self.name = name | 187 self.name = name |
187 # TODO(sky): I don't like hanging this off Target. This state is specific | 188 # TODO(sky): I don't like hanging this off Target. This state is specific |
188 # to certain functions and should be isolated there. | 189 # to certain functions and should be isolated there. |
189 self.visited = False | 190 self.visited = False |
190 self.requires_build = False | 191 self.requires_build = False |
191 self.added_to_compile_targets = False | 192 self.added_to_compile_targets = False |
192 self.in_roots = False | 193 self.in_roots = False |
| 194 self.is_executable = False |
193 | 195 |
194 | 196 |
195 class Config(object): | 197 class Config(object): |
196 """Details what we're looking for | 198 """Details what we're looking for |
197 files: set of files to search for | 199 files: set of files to search for |
198 targets: see file description for details.""" | 200 targets: see file description for details.""" |
199 def __init__(self): | 201 def __init__(self): |
200 self.files = [] | 202 self.files = [] |
201 self.targets = set() | 203 self.targets = set() |
202 | 204 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 target_name = targets_to_visit.pop() | 297 target_name = targets_to_visit.pop() |
296 created_target, target = _GetOrCreateTargetByName(targets, target_name) | 298 created_target, target = _GetOrCreateTargetByName(targets, target_name) |
297 if created_target: | 299 if created_target: |
298 roots.add(target) | 300 roots.add(target) |
299 elif target.visited: | 301 elif target.visited: |
300 continue | 302 continue |
301 | 303 |
302 target.visited = True | 304 target.visited = True |
303 target.requires_build = _DoesTargetTypeRequireBuild( | 305 target.requires_build = _DoesTargetTypeRequireBuild( |
304 target_dicts[target_name]) | 306 target_dicts[target_name]) |
| 307 target.is_executable = target_dicts[target_name]['type'] == 'executable' |
305 | 308 |
306 build_file = gyp.common.ParseQualifiedTarget(target_name)[0] | 309 build_file = gyp.common.ParseQualifiedTarget(target_name)[0] |
307 if not build_file in build_file_in_files: | 310 if not build_file in build_file_in_files: |
308 build_file_in_files[build_file] = \ | 311 build_file_in_files[build_file] = \ |
309 _WasBuildFileModified(build_file, data, files) | 312 _WasBuildFileModified(build_file, data, files) |
310 | 313 |
311 if build_file in build_files: | 314 if build_file in build_files: |
312 build_file_targets.add(target) | 315 build_file_targets.add(target) |
313 | 316 |
314 # If a build file (or any of its included files) is modified we assume all | 317 # If a build file (or any of its included files) is modified we assume all |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 return | 400 return |
398 | 401 |
399 target.visited = True | 402 target.visited = True |
400 target.in_roots = not target.back_deps and target in roots | 403 target.in_roots = not target.back_deps and target in roots |
401 | 404 |
402 for back_dep_target in target.back_deps: | 405 for back_dep_target in target.back_deps: |
403 _AddBuildTargets(back_dep_target, roots, False, result) | 406 _AddBuildTargets(back_dep_target, roots, False, result) |
404 target.added_to_compile_targets |= back_dep_target.added_to_compile_targets | 407 target.added_to_compile_targets |= back_dep_target.added_to_compile_targets |
405 target.in_roots |= back_dep_target.in_roots | 408 target.in_roots |= back_dep_target.in_roots |
406 | 409 |
407 if not target.added_to_compile_targets and target.in_roots and \ | 410 # Always add 'executable' targets. Even though they may be built by other |
408 (add_if_no_ancestor or target.requires_build): | 411 # targets that depend upon them it makes detection of what is going to be |
| 412 # built easier. |
| 413 if target.in_roots and \ |
| 414 (target.is_executable or |
| 415 (not target.added_to_compile_targets and |
| 416 (add_if_no_ancestor or target.requires_build))): |
409 result.add(target) | 417 result.add(target) |
410 target.added_to_compile_targets = True | 418 target.added_to_compile_targets = True |
411 | 419 |
412 | 420 |
413 def _GetBuildTargets(matching_targets, roots): | 421 def _GetBuildTargets(matching_targets, roots): |
414 """Returns the set of Targets that require a build. | 422 """Returns the set of Targets that require a build. |
415 matching_targets: targets that changed and need to be built. | 423 matching_targets: targets that changed and need to be built. |
416 roots: set of root targets in the build files to search from.""" | 424 roots: set of root targets in the build files to search from.""" |
417 result = set() | 425 result = set() |
418 for target in matching_targets: | 426 for target in matching_targets: |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 result_dict = { 'targets': matched_search_targets, | 551 result_dict = { 'targets': matched_search_targets, |
544 'status': found_dependency_string if matching_targets else | 552 'status': found_dependency_string if matching_targets else |
545 no_dependency_string, | 553 no_dependency_string, |
546 'build_targets': build_targets} | 554 'build_targets': build_targets} |
547 if warning: | 555 if warning: |
548 result_dict['warning'] = warning | 556 result_dict['warning'] = warning |
549 _WriteOutput(params, **result_dict) | 557 _WriteOutput(params, **result_dict) |
550 | 558 |
551 except Exception as e: | 559 except Exception as e: |
552 _WriteOutput(params, error=str(e)) | 560 _WriteOutput(params, error=str(e)) |
OLD | NEW |