OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''This file contains item formatters for resource_map_header and | 6 '''This file contains item formatters for resource_map_header and |
7 resource_map_source files. A resource map is a mapping between resource names | 7 resource_map_source files. A resource map is a mapping between resource names |
8 (string) and the internal resource ID.''' | 8 (string) and the internal resource ID. It is output with an alphabetical order |
9 of resource names.''' | |
9 | 10 |
10 import os | 11 import os |
11 from functools import partial | 12 from functools import partial |
12 | 13 |
13 from grit import util | 14 from grit import util |
14 | 15 |
15 | 16 |
16 def GetFormatter(type): | 17 def GetFormatter(type): |
17 if type == 'resource_map_header': | 18 if type == 'resource_map_header': |
18 return _FormatHeader | 19 return _FormatHeader |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 const size_t %(map_name)sSize = arraysize(%(map_name)s); | 102 const size_t %(map_name)sSize = arraysize(%(map_name)s); |
102 ''' % { 'map_name': GetMapName(root) } | 103 ''' % { 'map_name': GetMapName(root) } |
103 | 104 |
104 | 105 |
105 def _FormatSource(get_key, root, lang, output_dir): | 106 def _FormatSource(get_key, root, lang, output_dir): |
106 from grit.format import rc_header | 107 from grit.format import rc_header |
107 from grit.node import include, structure, message | 108 from grit.node import include, structure, message |
108 yield _FormatSourceHeader(root) | 109 yield _FormatSourceHeader(root) |
109 tids = rc_header.GetIds(root) | 110 tids = rc_header.GetIds(root) |
110 seen = set() | 111 seen = set() |
112 items = [] | |
111 active_descendants = [item for item in root.ActiveDescendants()] | 113 active_descendants = [item for item in root.ActiveDescendants()] |
112 output_all_resource_defines = root.ShouldOutputAllResourceDefines() | 114 output_all_resource_defines = root.ShouldOutputAllResourceDefines() |
113 for item in root: | 115 for item in root: |
114 if not item.IsResourceMapSource(): | 116 if not item.IsResourceMapSource(): |
115 continue | 117 continue |
118 items.append(item) | |
flackr
2015/08/27 22:03:15
nit: Prefer list comprehension over looping to bui
| |
119 items = sorted(items, key=get_key) | |
120 for item in items: | |
116 key = get_key(item) | 121 key = get_key(item) |
117 tid = item.attrs['name'] | 122 tid = item.attrs['name'] |
118 if tid not in tids or key in seen: | 123 if tid not in tids or key in seen: |
flackr
2015/08/27 22:03:15
now that we're sorted by key we should just compar
| |
119 continue | 124 continue |
120 seen.add(key) | 125 seen.add(key) |
121 if item.GeneratesResourceMapEntry(output_all_resource_defines, | 126 if item.GeneratesResourceMapEntry(output_all_resource_defines, |
122 item in active_descendants): | 127 item in active_descendants): |
flackr
2015/08/27 22:03:15
nit: looks like active_descendants should be a set
| |
123 yield ' {"%s", %s},\n' % (key, tid) | 128 yield ' {"%s", %s},\n' % (key, tid) |
124 yield _FormatSourceFooter(root) | 129 yield _FormatSourceFooter(root) |
125 | 130 |
126 | 131 |
127 def _GetItemName(item): | 132 def _GetItemName(item): |
128 return item.attrs['name'] | 133 return item.attrs['name'] |
129 | 134 |
130 | 135 |
131 def _GetItemPath(item): | 136 def _GetItemPath(item): |
132 return item.GetInputPath().replace("\\", "/") | 137 return item.GetInputPath().replace("\\", "/") |
OLD | NEW |