OLD | NEW |
1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 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 from compiler.ast import Const | 5 from compiler.ast import Const |
6 from compiler.ast import Dict | 6 from compiler.ast import Dict |
7 from compiler.ast import Discard | 7 from compiler.ast import Discard |
8 from compiler.ast import List | 8 from compiler.ast import List |
9 from compiler.ast import Module | 9 from compiler.ast import Module |
10 from compiler.ast import Node | 10 from compiler.ast import Node |
(...skipping 2544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2555 for index in xrange(0, len(the_list)): | 2555 for index in xrange(0, len(the_list)): |
2556 item = the_list[index] | 2556 item = the_list[index] |
2557 if isinstance(item, int): | 2557 if isinstance(item, int): |
2558 the_list[index] = str(item) | 2558 the_list[index] = str(item) |
2559 elif isinstance(item, dict): | 2559 elif isinstance(item, dict): |
2560 TurnIntIntoStrInDict(item) | 2560 TurnIntIntoStrInDict(item) |
2561 elif isinstance(item, list): | 2561 elif isinstance(item, list): |
2562 TurnIntIntoStrInList(item) | 2562 TurnIntIntoStrInList(item) |
2563 | 2563 |
2564 | 2564 |
| 2565 def PruneUnwantedTargets(targets, flat_list, dependency_nodes, root_targets): |
| 2566 """Return only the targets that are deep dependencies of |root_targets|.""" |
| 2567 qualified_root_targets = [] |
| 2568 for target in root_targets: |
| 2569 target = target.strip() |
| 2570 qualified_targets = gyp.common.FindQualifiedTargets(target, flat_list) |
| 2571 if not qualified_targets: |
| 2572 raise GypError("Could not find target %s" % target) |
| 2573 qualified_root_targets.extend(qualified_targets) |
| 2574 |
| 2575 wanted_targets = {} |
| 2576 for target in qualified_root_targets: |
| 2577 wanted_targets[target] = targets[target] |
| 2578 for dependency in dependency_nodes[target].DeepDependencies(): |
| 2579 wanted_targets[dependency] = targets[dependency] |
| 2580 |
| 2581 wanted_flat_list = [t for t in flat_list if t in wanted_targets] |
| 2582 return wanted_targets, wanted_flat_list |
| 2583 |
| 2584 |
2565 def VerifyNoCollidingTargets(targets): | 2585 def VerifyNoCollidingTargets(targets): |
2566 """Verify that no two targets in the same directory share the same name. | 2586 """Verify that no two targets in the same directory share the same name. |
2567 | 2587 |
2568 Arguments: | 2588 Arguments: |
2569 targets: A list of targets in the form 'path/to/file.gyp:target_name'. | 2589 targets: A list of targets in the form 'path/to/file.gyp:target_name'. |
2570 """ | 2590 """ |
2571 # Keep a dict going from 'subdirectory:target_name' to 'foo.gyp'. | 2591 # Keep a dict going from 'subdirectory:target_name' to 'foo.gyp'. |
2572 used = {} | 2592 used = {} |
2573 for target in targets: | 2593 for target in targets: |
2574 # Separate out 'path/to/file.gyp, 'target_name' from | 2594 # Separate out 'path/to/file.gyp, 'target_name' from |
2575 # 'path/to/file.gyp:target_name'. | 2595 # 'path/to/file.gyp:target_name'. |
2576 path, name = target.rsplit(':', 1) | 2596 path, name = target.rsplit(':', 1) |
2577 # Separate out 'path/to', 'file.gyp' from 'path/to/file.gyp'. | 2597 # Separate out 'path/to', 'file.gyp' from 'path/to/file.gyp'. |
2578 subdir, gyp = os.path.split(path) | 2598 subdir, gyp = os.path.split(path) |
2579 # Use '.' for the current directory '', so that the error messages make | 2599 # Use '.' for the current directory '', so that the error messages make |
2580 # more sense. | 2600 # more sense. |
2581 if not subdir: | 2601 if not subdir: |
2582 subdir = '.' | 2602 subdir = '.' |
2583 # Prepare a key like 'path/to:target_name'. | 2603 # Prepare a key like 'path/to:target_name'. |
2584 key = subdir + ':' + name | 2604 key = subdir + ':' + name |
2585 if key in used: | 2605 if key in used: |
2586 # Complain if this target is already used. | 2606 # Complain if this target is already used. |
2587 raise GypError('Duplicate target name "%s" in directory "%s" used both ' | 2607 raise GypError('Duplicate target name "%s" in directory "%s" used both ' |
2588 'in "%s" and "%s".' % (name, subdir, gyp, used[key])) | 2608 'in "%s" and "%s".' % (name, subdir, gyp, used[key])) |
2589 used[key] = gyp | 2609 used[key] = gyp |
2590 | 2610 |
2591 | 2611 |
2592 def Load(build_files, variables, includes, depth, generator_input_info, check, | 2612 def Load(build_files, variables, includes, depth, generator_input_info, check, |
2593 circular_check, parallel): | 2613 circular_check, parallel, root_targets): |
2594 # Set up path_sections and non_configuration_keys with the default data plus | 2614 # Set up path_sections and non_configuration_keys with the default data plus |
2595 # the generator-specifc data. | 2615 # the generator-specifc data. |
2596 global path_sections | 2616 global path_sections |
2597 path_sections = base_path_sections[:] | 2617 path_sections = base_path_sections[:] |
2598 path_sections.extend(generator_input_info['path_sections']) | 2618 path_sections.extend(generator_input_info['path_sections']) |
2599 | 2619 |
2600 global non_configuration_keys | 2620 global non_configuration_keys |
2601 non_configuration_keys = base_non_configuration_keys[:] | 2621 non_configuration_keys = base_non_configuration_keys[:] |
2602 non_configuration_keys.extend(generator_input_info['non_configuration_keys']) | 2622 non_configuration_keys.extend(generator_input_info['non_configuration_keys']) |
2603 | 2623 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2671 # Make sure every dependency appears at most once. | 2691 # Make sure every dependency appears at most once. |
2672 RemoveDuplicateDependencies(targets) | 2692 RemoveDuplicateDependencies(targets) |
2673 | 2693 |
2674 if circular_check: | 2694 if circular_check: |
2675 # Make sure that any targets in a.gyp don't contain dependencies in other | 2695 # Make sure that any targets in a.gyp don't contain dependencies in other |
2676 # .gyp files that further depend on a.gyp. | 2696 # .gyp files that further depend on a.gyp. |
2677 VerifyNoGYPFileCircularDependencies(targets) | 2697 VerifyNoGYPFileCircularDependencies(targets) |
2678 | 2698 |
2679 [dependency_nodes, flat_list] = BuildDependencyList(targets) | 2699 [dependency_nodes, flat_list] = BuildDependencyList(targets) |
2680 | 2700 |
| 2701 if root_targets: |
| 2702 # Remove, from |targets| and |flat_list|, the targets that are not deep |
| 2703 # dependencies of the targets specified in |root_targets|. |
| 2704 targets, flat_list = PruneUnwantedTargets( |
| 2705 targets, flat_list, dependency_nodes, root_targets) |
| 2706 |
2681 # Check that no two targets in the same directory have the same name. | 2707 # Check that no two targets in the same directory have the same name. |
2682 VerifyNoCollidingTargets(flat_list) | 2708 VerifyNoCollidingTargets(flat_list) |
2683 | 2709 |
2684 # Handle dependent settings of various types. | 2710 # Handle dependent settings of various types. |
2685 for settings_type in ['all_dependent_settings', | 2711 for settings_type in ['all_dependent_settings', |
2686 'direct_dependent_settings', | 2712 'direct_dependent_settings', |
2687 'link_settings']: | 2713 'link_settings']: |
2688 DoDependentSettings(settings_type, flat_list, targets, dependency_nodes) | 2714 DoDependentSettings(settings_type, flat_list, targets, dependency_nodes) |
2689 | 2715 |
2690 # Take out the dependent settings now that they've been published to all | 2716 # Take out the dependent settings now that they've been published to all |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2741 ValidateRunAsInTarget(target, target_dict, build_file) | 2767 ValidateRunAsInTarget(target, target_dict, build_file) |
2742 ValidateActionsInTarget(target, target_dict, build_file) | 2768 ValidateActionsInTarget(target, target_dict, build_file) |
2743 | 2769 |
2744 # Generators might not expect ints. Turn them into strs. | 2770 # Generators might not expect ints. Turn them into strs. |
2745 TurnIntIntoStrInDict(data) | 2771 TurnIntIntoStrInDict(data) |
2746 | 2772 |
2747 # TODO(mark): Return |data| for now because the generator needs a list of | 2773 # TODO(mark): Return |data| for now because the generator needs a list of |
2748 # build files that came in. In the future, maybe it should just accept | 2774 # build files that came in. In the future, maybe it should just accept |
2749 # a list, and not the whole data dict. | 2775 # a list, and not the whole data dict. |
2750 return [flat_list, targets, data] | 2776 return [flat_list, targets, data] |
OLD | NEW |