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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 back_deps: set of Targets that have a dependency on this Target. | 176 back_deps: set of Targets that have a dependency on this Target. |
177 visited: used during iteration to indicate whether we've visited this target. | 177 visited: used during iteration to indicate whether we've visited this target. |
178 This is used for two iterations, once in building the set of Targets and | 178 This is used for two iterations, once in building the set of Targets and |
179 again in _GetBuildTargets(). | 179 again in _GetBuildTargets(). |
180 name: fully qualified name of the target. | 180 name: fully qualified name of the target. |
181 requires_build: True if the target type is such that it needs to be built. | 181 requires_build: True if the target type is such that it needs to be built. |
182 See _DoesTargetTypeRequireBuild for details. | 182 See _DoesTargetTypeRequireBuild for details. |
183 added_to_compile_targets: used when determining if the target was added to the | 183 added_to_compile_targets: used when determining if the target was added to the |
184 set of targets that needs to be built. | 184 set of targets that needs to be built. |
185 in_roots: true if this target is a descendant of one of the root nodes. | 185 in_roots: true if this target is a descendant of one of the root nodes. |
186 is_executable: true if the type of target is executable.""" | 186 is_executable: true if the type of target is executable. |
187 is_static_library: true if the type of target is static_library. | |
188 is_or_has_executable_ancestor: true if the target is executable, or if there | |
189 is a target in back_deps that is executable.""" | |
187 def __init__(self, name): | 190 def __init__(self, name): |
188 self.deps = set() | 191 self.deps = set() |
189 self.match_status = MATCH_STATUS_TBD | 192 self.match_status = MATCH_STATUS_TBD |
190 self.back_deps = set() | 193 self.back_deps = set() |
191 self.name = name | 194 self.name = name |
192 # TODO(sky): I don't like hanging this off Target. This state is specific | 195 # TODO(sky): I don't like hanging this off Target. This state is specific |
193 # to certain functions and should be isolated there. | 196 # to certain functions and should be isolated there. |
194 self.visited = False | 197 self.visited = False |
195 self.requires_build = False | 198 self.requires_build = False |
196 self.added_to_compile_targets = False | 199 self.added_to_compile_targets = False |
197 self.in_roots = False | 200 self.in_roots = False |
198 self.is_executable = False | 201 self.is_executable = False |
202 self.is_static_library = False | |
203 self.is_or_has_executable_ancestor = False | |
199 | 204 |
200 | 205 |
201 class Config(object): | 206 class Config(object): |
202 """Details what we're looking for | 207 """Details what we're looking for |
203 files: set of files to search for | 208 files: set of files to search for |
204 targets: see file description for details.""" | 209 targets: see file description for details.""" |
205 def __init__(self): | 210 def __init__(self): |
206 self.files = [] | 211 self.files = [] |
207 self.targets = set() | 212 self.targets = set() |
208 | 213 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 target_name = targets_to_visit.pop() | 307 target_name = targets_to_visit.pop() |
303 created_target, target = _GetOrCreateTargetByName(targets, target_name) | 308 created_target, target = _GetOrCreateTargetByName(targets, target_name) |
304 if created_target: | 309 if created_target: |
305 roots.add(target) | 310 roots.add(target) |
306 elif target.visited: | 311 elif target.visited: |
307 continue | 312 continue |
308 | 313 |
309 target.visited = True | 314 target.visited = True |
310 target.requires_build = _DoesTargetTypeRequireBuild( | 315 target.requires_build = _DoesTargetTypeRequireBuild( |
311 target_dicts[target_name]) | 316 target_dicts[target_name]) |
312 target.is_executable = target_dicts[target_name]['type'] == 'executable' | 317 target_type = target_dicts[target_name]['type'] |
318 target.is_executable = target_type == 'executable' | |
319 target.is_static_library = target_type == 'static_library' | |
313 | 320 |
314 build_file = gyp.common.ParseQualifiedTarget(target_name)[0] | 321 build_file = gyp.common.ParseQualifiedTarget(target_name)[0] |
315 if not build_file in build_file_in_files: | 322 if not build_file in build_file_in_files: |
316 build_file_in_files[build_file] = \ | 323 build_file_in_files[build_file] = \ |
317 _WasBuildFileModified(build_file, data, files, toplevel_dir) | 324 _WasBuildFileModified(build_file, data, files, toplevel_dir) |
318 | 325 |
319 if build_file in build_files: | 326 if build_file in build_files: |
320 build_file_targets.add(target) | 327 build_file_targets.add(target) |
321 | 328 |
322 # If a build file (or any of its included files) is modified we assume all | 329 # If a build file (or any of its included files) is modified we assume all |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 that need to be built (and are in |roots|) to |result|. | 406 that need to be built (and are in |roots|) to |result|. |
400 roots: set of root targets. | 407 roots: set of root targets. |
401 add_if_no_ancestor: If true and there are no ancestors of |target| then add | 408 add_if_no_ancestor: If true and there are no ancestors of |target| then add |
402 |target| to |result|. |target| must still be in |roots|. | 409 |target| to |result|. |target| must still be in |roots|. |
403 result: targets that need to be built are added here.""" | 410 result: targets that need to be built are added here.""" |
404 if target.visited: | 411 if target.visited: |
405 return | 412 return |
406 | 413 |
407 target.visited = True | 414 target.visited = True |
408 target.in_roots = not target.back_deps and target in roots | 415 target.in_roots = not target.back_deps and target in roots |
416 target.is_or_has_executable_ancestor = target.is_executable | |
409 | 417 |
410 for back_dep_target in target.back_deps: | 418 for back_dep_target in target.back_deps: |
411 _AddBuildTargets(back_dep_target, roots, False, result) | 419 _AddBuildTargets(back_dep_target, roots, False, result) |
412 target.added_to_compile_targets |= back_dep_target.added_to_compile_targets | 420 target.added_to_compile_targets |= back_dep_target.added_to_compile_targets |
413 target.in_roots |= back_dep_target.in_roots | 421 target.in_roots |= back_dep_target.in_roots |
422 target.is_or_has_executable_ancestor |= ( | |
423 back_dep_target.is_or_has_executable_ancestor) | |
414 | 424 |
415 # Always add 'executable' targets. Even though they may be built by other | 425 # Always add 'executable' targets. Even though they may be built by other |
416 # targets that depend upon them it makes detection of what is going to be | 426 # targets that depend upon them it makes detection of what is going to be |
417 # built easier. | 427 # built easier. |
428 # And always add static_libraries that have no dependencies on them from | |
429 # executables. This is necessary as the other dependencies on them may be | |
430 # static libraries themselves, which are not compile time dependencies. | |
418 if target.in_roots and \ | 431 if target.in_roots and \ |
419 (target.is_executable or | 432 (target.is_executable or |
420 (not target.added_to_compile_targets and | 433 (not target.added_to_compile_targets and |
421 (add_if_no_ancestor or target.requires_build))): | 434 (add_if_no_ancestor or target.requires_build)) or |
435 (target.is_static_library and add_if_no_ancestor and | |
436 not target.is_or_has_executable_ancestor)): | |
Nico
2015/06/08 17:37:56
you care about "is_or_has_linked_ancestor", right?
sky
2015/06/08 17:46:26
Done.
| |
422 result.add(target) | 437 result.add(target) |
423 target.added_to_compile_targets = True | 438 target.added_to_compile_targets = True |
424 | 439 |
425 | 440 |
426 def _GetBuildTargets(matching_targets, roots): | 441 def _GetBuildTargets(matching_targets, roots): |
427 """Returns the set of Targets that require a build. | 442 """Returns the set of Targets that require a build. |
428 matching_targets: targets that changed and need to be built. | 443 matching_targets: targets that changed and need to be built. |
429 roots: set of root targets in the build files to search from.""" | 444 roots: set of root targets in the build files to search from.""" |
430 result = set() | 445 result = set() |
431 for target in matching_targets: | 446 for target in matching_targets: |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 result_dict = { 'targets': matched_search_targets, | 575 result_dict = { 'targets': matched_search_targets, |
561 'status': found_dependency_string if matching_targets else | 576 'status': found_dependency_string if matching_targets else |
562 no_dependency_string, | 577 no_dependency_string, |
563 'build_targets': build_targets} | 578 'build_targets': build_targets} |
564 if invalid_targets: | 579 if invalid_targets: |
565 result_dict['invalid_targets'] = invalid_targets | 580 result_dict['invalid_targets'] = invalid_targets |
566 _WriteOutput(params, **result_dict) | 581 _WriteOutput(params, **result_dict) |
567 | 582 |
568 except Exception as e: | 583 except Exception as e: |
569 _WriteOutput(params, error=str(e)) | 584 _WriteOutput(params, error=str(e)) |
OLD | NEW |