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 import copy | 5 import copy |
6 import ntpath | 6 import ntpath |
7 import os | 7 import os |
8 import posixpath | 8 import posixpath |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
(...skipping 2617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2628 """ | 2628 """ |
2629 if name not in properties: | 2629 if name not in properties: |
2630 properties[name] = {} | 2630 properties[name] = {} |
2631 values = properties[name] | 2631 values = properties[name] |
2632 if value not in values: | 2632 if value not in values: |
2633 values[value] = [] | 2633 values[value] = [] |
2634 conditions = values[value] | 2634 conditions = values[value] |
2635 conditions.append(condition) | 2635 conditions.append(condition) |
2636 | 2636 |
2637 | 2637 |
2638 MSBUILD_PROPERTY_ORDER = [ | |
gab
2012/05/09 15:27:11
Does this mean we will need to add each new proper
bradn
2012/05/10 01:48:52
So I'm gonna swap this all out for the topological
| |
2639 'OutDir', | |
2640 'IntDir', # IntDir is usually defined is terms of OutDir so put it later. | |
gab
2012/05/09 15:27:11
typo: is => in
bradn
2012/05/10 01:48:52
Done.
| |
2641 'TargetName', | |
2642 'TargetPath', | |
2643 'ExecutablePath', | |
2644 ] | |
2645 | |
2646 | |
2647 def _MSBuildPropertyRank(name): | |
2648 """Decide a rank for a property name. | |
2649 | |
2650 Returns: | |
2651 A numerical value which is lower if a property should be | |
2652 defined earlier. | |
2653 Place unknown property names last (as other typically don't | |
2654 rely on them). | |
2655 """ | |
2656 try: | |
2657 return MSBUILD_PROPERTY_ORDER.index(name) | |
2658 except ValueError: | |
2659 return len(MSBUILD_PROPERTY_ORDER) | |
2660 | |
2661 | |
2662 def _CompareMSBuildProperties(a, b): | |
2663 """Compare two property pairs (name, values). | |
2664 | |
2665 Order of definition in msbuild matters. In general we don't make | |
2666 use of properties defined at the same level, but there are exceptions. | |
2667 This function defines a sort order that is mostly alphabetical, | |
2668 with a few items that commonly are used in self reference brought to the | |
2669 front. | |
2670 | |
2671 Args: | |
2672 a: (name, values) pair. | |
2673 b: (name, values) pair. | |
2674 Returns: | |
2675 -1, 0, 1 for comparison. | |
2676 """ | |
2677 result = cmp(_MSBuildPropertyRank(a[0]), _MSBuildPropertyRank(b[0])) | |
2678 if result != 0: | |
2679 return result | |
2680 return cmp(a, b) | |
2681 | |
2682 | |
2638 def _GetMSBuildPropertyGroup(spec, label, properties): | 2683 def _GetMSBuildPropertyGroup(spec, label, properties): |
2639 """Returns a PropertyGroup definition for the specified properties. | 2684 """Returns a PropertyGroup definition for the specified properties. |
2640 | 2685 |
2641 Arguments: | 2686 Arguments: |
2642 spec: The target project dict. | 2687 spec: The target project dict. |
2643 label: An optional label for the PropertyGroup. | 2688 label: An optional label for the PropertyGroup. |
2644 properties: The dictionary to be converted. The key is the name of the | 2689 properties: The dictionary to be converted. The key is the name of the |
2645 property. The value is itself a dictionary; its key is the value and | 2690 property. The value is itself a dictionary; its key is the value and |
2646 the value a list of condition for which this value is true. | 2691 the value a list of condition for which this value is true. |
2647 """ | 2692 """ |
2648 group = ['PropertyGroup'] | 2693 group = ['PropertyGroup'] |
2649 if label: | 2694 if label: |
2650 group.append({'Label': label}) | 2695 group.append({'Label': label}) |
2651 num_configurations = len(spec['configurations']) | 2696 num_configurations = len(spec['configurations']) |
2652 for name, values in sorted(properties.iteritems()): | 2697 for name, values in sorted(properties.iteritems(), _CompareMSBuildProperties): |
2653 for value, conditions in sorted(values.iteritems()): | 2698 for value, conditions in sorted(values.iteritems()): |
2654 if len(conditions) == num_configurations: | 2699 if len(conditions) == num_configurations: |
2655 # If the value is the same all configurations, | 2700 # If the value is the same all configurations, |
2656 # just add one unconditional entry. | 2701 # just add one unconditional entry. |
2657 group.append([name, value]) | 2702 group.append([name, value]) |
2658 else: | 2703 else: |
2659 for condition in conditions: | 2704 for condition in conditions: |
2660 group.append([name, {'Condition': condition}, value]) | 2705 group.append([name, {'Condition': condition}, value]) |
2661 return [group] | 2706 return [group] |
2662 | 2707 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3064 action_spec.extend( | 3109 action_spec.extend( |
3065 # TODO(jeanluc) 'Document' for all or just if as_sources? | 3110 # TODO(jeanluc) 'Document' for all or just if as_sources? |
3066 [['FileType', 'Document'], | 3111 [['FileType', 'Document'], |
3067 ['Command', command], | 3112 ['Command', command], |
3068 ['Message', description], | 3113 ['Message', description], |
3069 ['Outputs', outputs] | 3114 ['Outputs', outputs] |
3070 ]) | 3115 ]) |
3071 if additional_inputs: | 3116 if additional_inputs: |
3072 action_spec.append(['AdditionalInputs', additional_inputs]) | 3117 action_spec.append(['AdditionalInputs', additional_inputs]) |
3073 actions_spec.append(action_spec) | 3118 actions_spec.append(action_spec) |
OLD | NEW |