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, build_files): | |
2566 """ | |
2567 Return only the targets that are deep dependencies of the targets specified | |
2568 in |build_files|. | |
2569 """ | |
2570 wanted_targets = {} | |
2571 for target in flat_list: | |
2572 if gyp.common.BuildFile(target) in build_files: | |
2573 wanted_targets[target] = targets[target] | |
2574 for dependency in dependency_nodes[target].DeepDependencies(): | |
2575 wanted_targets[dependency] = targets[dependency] | |
2576 | |
2577 wanted_flat_list = [t for t in flat_list if t in wanted_targets] | |
2578 return [wanted_targets, wanted_flat_list] | |
2579 | |
2580 | |
2565 def VerifyNoCollidingTargets(targets): | 2581 def VerifyNoCollidingTargets(targets): |
2566 """Verify that no two targets in the same directory share the same name. | 2582 """Verify that no two targets in the same directory share the same name. |
2567 | 2583 |
2568 Arguments: | 2584 Arguments: |
2569 targets: A list of targets in the form 'path/to/file.gyp:target_name'. | 2585 targets: A list of targets in the form 'path/to/file.gyp:target_name'. |
2570 """ | 2586 """ |
2571 # Keep a dict going from 'subdirectory:target_name' to 'foo.gyp'. | 2587 # Keep a dict going from 'subdirectory:target_name' to 'foo.gyp'. |
2572 used = {} | 2588 used = {} |
2573 for target in targets: | 2589 for target in targets: |
2574 # Separate out 'path/to/file.gyp, 'target_name' from | 2590 # Separate out 'path/to/file.gyp, 'target_name' from |
2575 # 'path/to/file.gyp:target_name'. | 2591 # 'path/to/file.gyp:target_name'. |
2576 path, name = target.rsplit(':', 1) | 2592 path, name = target.rsplit(':', 1) |
2577 # Separate out 'path/to', 'file.gyp' from 'path/to/file.gyp'. | 2593 # Separate out 'path/to', 'file.gyp' from 'path/to/file.gyp'. |
2578 subdir, gyp = os.path.split(path) | 2594 subdir, gyp = os.path.split(path) |
2579 # Use '.' for the current directory '', so that the error messages make | 2595 # Use '.' for the current directory '', so that the error messages make |
2580 # more sense. | 2596 # more sense. |
2581 if not subdir: | 2597 if not subdir: |
2582 subdir = '.' | 2598 subdir = '.' |
2583 # Prepare a key like 'path/to:target_name'. | 2599 # Prepare a key like 'path/to:target_name'. |
2584 key = subdir + ':' + name | 2600 key = subdir + ':' + name |
2585 if key in used: | 2601 if key in used: |
2586 # Complain if this target is already used. | 2602 # Complain if this target is already used. |
2587 raise GypError('Duplicate target name "%s" in directory "%s" used both ' | 2603 raise GypError('Duplicate target name "%s" in directory "%s" used both ' |
2588 'in "%s" and "%s".' % (name, subdir, gyp, used[key])) | 2604 'in "%s" and "%s".' % (name, subdir, gyp, used[key])) |
2589 used[key] = gyp | 2605 used[key] = gyp |
2590 | 2606 |
2591 | 2607 |
2592 def Load(build_files, variables, includes, depth, generator_input_info, check, | 2608 def Load(build_files, variables, includes, depth, generator_input_info, check, |
2593 circular_check, parallel): | 2609 circular_check, parallel, prune_targets): |
2594 # Set up path_sections and non_configuration_keys with the default data plus | 2610 # Set up path_sections and non_configuration_keys with the default data plus |
2595 # the generator-specifc data. | 2611 # the generator-specifc data. |
2596 global path_sections | 2612 global path_sections |
2597 path_sections = base_path_sections[:] | 2613 path_sections = base_path_sections[:] |
2598 path_sections.extend(generator_input_info['path_sections']) | 2614 path_sections.extend(generator_input_info['path_sections']) |
2599 | 2615 |
2600 global non_configuration_keys | 2616 global non_configuration_keys |
2601 non_configuration_keys = base_non_configuration_keys[:] | 2617 non_configuration_keys = base_non_configuration_keys[:] |
2602 non_configuration_keys.extend(generator_input_info['non_configuration_keys']) | 2618 non_configuration_keys.extend(generator_input_info['non_configuration_keys']) |
2603 | 2619 |
2604 # TODO(mark) handle variants if the generator doesn't want them directly. | 2620 # TODO(mark) handle variants if the generator doesn't want them directly. |
2605 generator_handles_variants = \ | 2621 generator_handles_variants = \ |
2606 generator_input_info['generator_handles_variants'] | 2622 generator_input_info['generator_handles_variants'] |
2607 | 2623 |
2608 global absolute_build_file_paths | 2624 global absolute_build_file_paths |
2609 absolute_build_file_paths = \ | 2625 absolute_build_file_paths = \ |
2610 generator_input_info['generator_wants_absolute_build_file_paths'] | 2626 generator_input_info['generator_wants_absolute_build_file_paths'] |
2611 | 2627 |
2612 global multiple_toolsets | 2628 global multiple_toolsets |
2613 multiple_toolsets = generator_input_info[ | 2629 multiple_toolsets = generator_input_info[ |
2614 'generator_supports_multiple_toolsets'] | 2630 'generator_supports_multiple_toolsets'] |
2615 | 2631 |
2616 # A generator can have other lists (in addition to sources) be processed | 2632 # A generator can have other lists (in addition to sources) be processed |
2617 # for rules. | 2633 # for rules. |
2618 extra_sources_for_rules = generator_input_info['extra_sources_for_rules'] | 2634 extra_sources_for_rules = generator_input_info['extra_sources_for_rules'] |
2619 | 2635 |
2636 # Normalize paths everywhere. This is important because paths will be | |
scottmg
2013/09/26 22:11:07
Why did this need to move?
| |
2637 # used as keys to the data dict and for references between input files. | |
2638 build_files = [os.path.normpath(i) for i in build_files] | |
2639 | |
2620 # Load build files. This loads every target-containing build file into | 2640 # Load build files. This loads every target-containing build file into |
2621 # the |data| dictionary such that the keys to |data| are build file names, | 2641 # the |data| dictionary such that the keys to |data| are build file names, |
2622 # and the values are the entire build file contents after "early" or "pre" | 2642 # and the values are the entire build file contents after "early" or "pre" |
2623 # processing has been done and includes have been resolved. | 2643 # processing has been done and includes have been resolved. |
2624 # NOTE: data contains both "target" files (.gyp) and "includes" (.gypi), as | 2644 # NOTE: data contains both "target" files (.gyp) and "includes" (.gypi), as |
2625 # well as meta-data (e.g. 'included_files' key). 'target_build_files' keeps | 2645 # well as meta-data (e.g. 'included_files' key). 'target_build_files' keeps |
2626 # track of the keys corresponding to "target" files. | 2646 # track of the keys corresponding to "target" files. |
2627 data = {'target_build_files': set()} | 2647 data = {'target_build_files': set()} |
2628 aux_data = {} | 2648 aux_data = {} |
2629 for build_file in build_files: | 2649 for build_file in build_files: |
2630 # Normalize paths everywhere. This is important because paths will be | |
2631 # used as keys to the data dict and for references between input files. | |
2632 build_file = os.path.normpath(build_file) | |
2633 try: | 2650 try: |
2634 if parallel: | 2651 if parallel: |
2635 LoadTargetBuildFileParallel(build_file, data, aux_data, | 2652 LoadTargetBuildFileParallel(build_file, data, aux_data, |
2636 variables, includes, depth, check) | 2653 variables, includes, depth, check) |
2637 else: | 2654 else: |
2638 LoadTargetBuildFile(build_file, data, aux_data, | 2655 LoadTargetBuildFile(build_file, data, aux_data, |
2639 variables, includes, depth, check, True) | 2656 variables, includes, depth, check, True) |
2640 except Exception, e: | 2657 except Exception, e: |
2641 gyp.common.ExceptionAppend(e, 'while trying to load %s' % build_file) | 2658 gyp.common.ExceptionAppend(e, 'while trying to load %s' % build_file) |
2642 raise | 2659 raise |
(...skipping 28 matching lines...) Expand all Loading... | |
2671 # Make sure every dependency appears at most once. | 2688 # Make sure every dependency appears at most once. |
2672 RemoveDuplicateDependencies(targets) | 2689 RemoveDuplicateDependencies(targets) |
2673 | 2690 |
2674 if circular_check: | 2691 if circular_check: |
2675 # Make sure that any targets in a.gyp don't contain dependencies in other | 2692 # Make sure that any targets in a.gyp don't contain dependencies in other |
2676 # .gyp files that further depend on a.gyp. | 2693 # .gyp files that further depend on a.gyp. |
2677 VerifyNoGYPFileCircularDependencies(targets) | 2694 VerifyNoGYPFileCircularDependencies(targets) |
2678 | 2695 |
2679 [dependency_nodes, flat_list] = BuildDependencyList(targets) | 2696 [dependency_nodes, flat_list] = BuildDependencyList(targets) |
2680 | 2697 |
2698 if prune_targets: | |
2699 # Remove, from |targets| and |flat_list|, the targets that are not deep | |
2700 # dependencies of the targets specified in |build_files|. | |
2701 [targets, flat_list] = PruneUnwantedTargets( | |
scottmg
2013/09/26 22:11:07
[ ] around targets, flat_list is odd here. Just re
| |
2702 targets, flat_list, dependency_nodes, build_files) | |
2703 | |
2681 # Check that no two targets in the same directory have the same name. | 2704 # Check that no two targets in the same directory have the same name. |
2682 VerifyNoCollidingTargets(flat_list) | 2705 VerifyNoCollidingTargets(flat_list) |
2683 | 2706 |
2684 # Handle dependent settings of various types. | 2707 # Handle dependent settings of various types. |
2685 for settings_type in ['all_dependent_settings', | 2708 for settings_type in ['all_dependent_settings', |
2686 'direct_dependent_settings', | 2709 'direct_dependent_settings', |
2687 'link_settings']: | 2710 'link_settings']: |
2688 DoDependentSettings(settings_type, flat_list, targets, dependency_nodes) | 2711 DoDependentSettings(settings_type, flat_list, targets, dependency_nodes) |
2689 | 2712 |
2690 # Take out the dependent settings now that they've been published to all | 2713 # 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) | 2764 ValidateRunAsInTarget(target, target_dict, build_file) |
2742 ValidateActionsInTarget(target, target_dict, build_file) | 2765 ValidateActionsInTarget(target, target_dict, build_file) |
2743 | 2766 |
2744 # Generators might not expect ints. Turn them into strs. | 2767 # Generators might not expect ints. Turn them into strs. |
2745 TurnIntIntoStrInDict(data) | 2768 TurnIntIntoStrInDict(data) |
2746 | 2769 |
2747 # TODO(mark): Return |data| for now because the generator needs a list of | 2770 # 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 | 2771 # build files that came in. In the future, maybe it should just accept |
2749 # a list, and not the whole data dict. | 2772 # a list, and not the whole data dict. |
2750 return [flat_list, targets, data] | 2773 return [flat_list, targets, data] |
OLD | NEW |