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 20 matching lines...) Expand all Loading... |
31 pos = filename.find('_') | 31 pos = filename.find('_') |
32 if pos >= len(filename): | 32 if pos >= len(filename): |
33 break | 33 break |
34 filename = filename[:pos] + filename[pos + 1].upper() + filename[pos + 2:] | 34 filename = filename[:pos] + filename[pos + 1].upper() + filename[pos + 2:] |
35 return 'k' + filename | 35 return 'k' + filename |
36 | 36 |
37 | 37 |
38 class HeaderTopLevel(interface.ItemFormatter): | 38 class HeaderTopLevel(interface.ItemFormatter): |
39 '''Create the header file for the resource mapping. This file just declares | 39 '''Create the header file for the resource mapping. This file just declares |
40 an array of name/value pairs.''' | 40 an array of name/value pairs.''' |
41 def Format(self, item, lang='en', begin_item=True, output_dir='.'): | 41 def Format(self, item, lang='en', output_dir='.'): |
42 if not begin_item: | |
43 return '' | |
44 return '''\ | 42 return '''\ |
45 // Copyright (c) %(year)d The Chromium Authors. All rights reserved. | 43 // Copyright (c) %(year)d The Chromium Authors. All rights reserved. |
46 // Use of this source code is governed by a BSD-style license that can be | 44 // Use of this source code is governed by a BSD-style license that can be |
47 // found in the LICENSE file. | 45 // found in the LICENSE file. |
48 // This file is automatically generated by GRIT. Do not edit. | 46 // This file is automatically generated by GRIT. Do not edit. |
49 | 47 |
50 #include <stddef.h> | 48 #include <stddef.h> |
51 | 49 |
52 #ifndef GRIT_RESOURCE_MAP_STRUCT_ | 50 #ifndef GRIT_RESOURCE_MAP_STRUCT_ |
53 #define GRIT_RESOURCE_MAP_STRUCT_ | 51 #define GRIT_RESOURCE_MAP_STRUCT_ |
54 struct GritResourceMap { | 52 struct GritResourceMap { |
55 const char* const name; | 53 const char* const name; |
56 int value; | 54 int value; |
57 }; | 55 }; |
58 #endif // GRIT_RESOURCE_MAP_STRUCT_ | 56 #endif // GRIT_RESOURCE_MAP_STRUCT_ |
59 | 57 |
60 extern const GritResourceMap %(map_name)s[]; | 58 extern const GritResourceMap %(map_name)s[]; |
61 extern const size_t %(map_name)sSize; | 59 extern const size_t %(map_name)sSize; |
62 ''' % { 'year': util.GetCurrentYear(), | 60 ''' % { 'year': util.GetCurrentYear(), |
63 'map_name': GetMapName(item.GetRoot()), | 61 'map_name': GetMapName(item.GetRoot()), |
64 } | 62 } |
65 | 63 |
66 | 64 |
67 class SourceTopLevel(interface.ItemFormatter): | 65 class SourceTopLevel(interface.ItemFormatter): |
68 '''Create the C++ source file for the resource mapping. This class handles | 66 '''Create the C++ source file for the resource mapping. This class handles |
69 the header/footer of the file.''' | 67 the header/footer of the file.''' |
70 def Format(self, item, lang='en', begin_item=True, output_dir='.'): | 68 def Format(self, item, lang='en', output_dir='.'): |
71 if begin_item: | 69 grit_root = item.GetRoot() |
72 grit_root = item.GetRoot() | 70 outputs = grit_root.GetOutputFiles() |
73 outputs = grit_root.GetOutputFiles() | 71 rc_header_file = None |
74 rc_header_file = None | 72 map_header_file = None |
75 map_header_file = None | 73 for output in outputs: |
76 for output in outputs: | 74 if 'rc_header' == output.GetType(): |
77 if 'rc_header' == output.GetType(): | 75 rc_header_file = output.GetFilename() |
78 rc_header_file = output.GetFilename() | 76 elif 'resource_map_header' == output.GetType(): |
79 elif 'resource_map_header' == output.GetType(): | 77 map_header_file = output.GetFilename() |
80 map_header_file = output.GetFilename() | 78 if not rc_header_file or not map_header_file: |
81 if not rc_header_file or not map_header_file: | 79 raise Exception('resource_map_source output type requires ' |
82 raise Exception('resource_map_source output type requires ' | 80 'resource_map_header and rc_header outputs') |
83 'resource_map_header and rc_header outputs') | 81 return '''\ |
84 | |
85 return '''\ | |
86 // Copyright (c) %(year)d The Chromium Authors. All rights reserved. | 82 // Copyright (c) %(year)d The Chromium Authors. All rights reserved. |
87 // Use of this source code is governed by a BSD-style license that can be | 83 // Use of this source code is governed by a BSD-style license that can be |
88 // found in the LICENSE file. | 84 // found in the LICENSE file. |
89 // This file is automatically generated by GRIT. Do not edit. | 85 // This file is automatically generated by GRIT. Do not edit. |
90 | 86 |
91 #include "%(map_header_file)s" | 87 #include "%(map_header_file)s" |
92 | 88 |
93 #include "base/basictypes.h" | 89 #include "base/basictypes.h" |
94 #include "%(rc_header_file)s" | 90 #include "%(rc_header_file)s" |
95 | 91 |
96 const GritResourceMap %(map_name)s[] = { | 92 const GritResourceMap %(map_name)s[] = { |
97 ''' % { 'year': util.GetCurrentYear(), | 93 ''' % { 'year': util.GetCurrentYear(), |
98 'map_header_file': map_header_file, | 94 'map_header_file': map_header_file, |
99 'rc_header_file': rc_header_file, | 95 'rc_header_file': rc_header_file, |
100 'map_name': GetMapName(item.GetRoot()), | 96 'map_name': GetMapName(item.GetRoot()), |
101 } | 97 } |
102 else: | 98 |
103 # Return the footer text. | 99 def FormatEnd(self, item, lang='en', output_dir='.'): |
104 return '''\ | 100 # Return the footer text. |
| 101 return '''\ |
105 }; | 102 }; |
106 | 103 |
107 const size_t %(map_name)sSize = arraysize(%(map_name)s); | 104 const size_t %(map_name)sSize = arraysize(%(map_name)s); |
108 ''' % { 'map_name': GetMapName(item.GetRoot()) } | 105 ''' % { 'map_name': GetMapName(item.GetRoot()) } |
109 | 106 |
110 | 107 |
111 class SourceInclude(interface.ItemFormatter): | 108 class SourceInclude(interface.ItemFormatter): |
112 '''Populate the resource mapping. For each include, we map a string to | 109 '''Populate the resource mapping. For each include, we map a string to |
113 the resource ID.''' | 110 the resource ID.''' |
114 def Format(self, item, lang='en', begin_item=True, output_dir='.'): | 111 def Format(self, item, lang='en', output_dir='.'): |
115 if not begin_item: | |
116 return '' | |
117 return ' {"%s", %s},\n' % (item.attrs['name'], item.attrs['name']) | 112 return ' {"%s", %s},\n' % (item.attrs['name'], item.attrs['name']) |
118 | 113 |
119 | 114 |
120 class SourceFileInclude(interface.ItemFormatter): | 115 class SourceFileInclude(interface.ItemFormatter): |
121 '''Populate the resource mapping. For each include, we map a filename to | 116 '''Populate the resource mapping. For each include, we map a filename to |
122 the resource ID.''' | 117 the resource ID.''' |
123 def Format(self, item, lang='en', begin_item=True, output_dir='.'): | 118 def Format(self, item, lang='en', output_dir='.'): |
124 if not begin_item: | |
125 return '' | |
126 filename = item.attrs['file'].replace("\\", "/") | 119 filename = item.attrs['file'].replace("\\", "/") |
127 return ' {"%s", %s},\n' % (filename, item.attrs['name']) | 120 return ' {"%s", %s},\n' % (filename, item.attrs['name']) |
OLD | NEW |