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.''' |
9 | 9 |
10 import os | 10 import os |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 | 103 |
104 | 104 |
105 def _FormatSource(get_key, root, lang, output_dir): | 105 def _FormatSource(get_key, root, lang, output_dir): |
106 from grit.format import rc_header | 106 from grit.format import rc_header |
107 from grit.node import include, structure, message | 107 from grit.node import include, structure, message |
108 yield _FormatSourceHeader(root) | 108 yield _FormatSourceHeader(root) |
109 tids = rc_header.GetIds(root) | 109 tids = rc_header.GetIds(root) |
110 seen = set() | 110 seen = set() |
111 active_descendants = [item for item in root.ActiveDescendants()] | 111 active_descendants = [item for item in root.ActiveDescendants()] |
112 for item in root: | 112 for item in root: |
113 if isinstance(item, (include.IncludeNode, | 113 if not isinstance(item, (include.IncludeNode, |
114 structure.StructureNode, | 114 structure.StructureNode, |
115 message.MessageNode)): | 115 message.MessageNode)): |
tony
2014/08/06 21:13:31
This code and the isinstance checks below are a li
Lei Zhang
2014/08/06 21:41:08
Done.
| |
116 key = get_key(item) | 116 continue |
117 tid = item.attrs['name'] | 117 key = get_key(item) |
118 if tid in tids and key not in seen: | 118 tid = item.attrs['name'] |
119 seen.add(key) | 119 if tid not in tids or key in seen: |
120 # For messages, only include the active ones | 120 continue |
121 if not isinstance(item, message.MessageNode) \ | 121 seen.add(key) |
122 or item in active_descendants: | 122 should_yield = True |
123 yield ' {"%s", %s},\n' % (key, tid) | 123 if isinstance(item, message.MessageNode): |
124 # For messages, only include the active ones. | |
125 should_yield = item in active_descendants | |
126 elif isinstance(item, structure.StructureNode): | |
127 # For structures, it depends... | |
128 if not root.ShouldOutputAllResourceDefines(): | |
129 should_yield = item in active_descendants | |
130 if should_yield: | |
131 yield ' {"%s", %s},\n' % (key, tid) | |
124 yield _FormatSourceFooter(root) | 132 yield _FormatSourceFooter(root) |
125 | 133 |
126 | 134 |
127 def _GetItemName(item): | 135 def _GetItemName(item): |
128 return item.attrs['name'] | 136 return item.attrs['name'] |
129 | 137 |
130 | 138 |
131 def _GetItemPath(item): | 139 def _GetItemPath(item): |
132 return item.GetInputPath().replace("\\", "/") | 140 return item.GetInputPath().replace("\\", "/") |
OLD | NEW |