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