OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (C) 2009 Google Inc. All rights reserved. | 3 # Copyright (C) 2009 Google Inc. All rights reserved. |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 OUTPUT_FILE1 etc. are filenames of output files. | 46 OUTPUT_FILE1 etc. are filenames of output files. |
47 | 47 |
48 Design doc: http://www.chromium.org/developers/design-documents/idl-build | 48 Design doc: http://www.chromium.org/developers/design-documents/idl-build |
49 """ | 49 """ |
50 | 50 |
51 import errno | 51 import errno |
52 import os | 52 import os |
53 import re | 53 import re |
54 import sys | 54 import sys |
55 | 55 |
56 from utilities import idl_filename_to_interface_name, read_idl_files_list_from_f
ile | 56 from utilities import should_generate_impl_file_from_idl, get_file_contents, idl
_filename_to_component, idl_filename_to_interface_name, read_idl_files_list_from
_file |
57 | 57 |
58 # A regexp for finding Conditional attributes in interface definitions. | 58 # A regexp for finding Conditional attributes in interface definitions. |
59 CONDITIONAL_PATTERN = re.compile( | 59 CONDITIONAL_PATTERN = re.compile( |
60 r'\[' | 60 r'\[' |
61 r'[^\]]*' | 61 r'[^\]]*' |
62 r'Conditional=([\_0-9a-zA-Z]*)' | 62 r'Conditional=([\_0-9a-zA-Z]*)' |
63 r'[^\]]*' | 63 r'[^\]]*' |
64 r'\]\s*' | 64 r'\]\s*' |
65 r'((callback|partial)\s+)?' | 65 r'((callback|partial)\s+)?' |
66 r'interface\s+' | 66 r'interface\s+' |
(...skipping 26 matching lines...) Expand all Loading... |
93 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 93 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
94 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 94 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
95 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 95 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
96 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 96 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
97 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 97 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
98 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 98 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
99 */ | 99 */ |
100 """ | 100 """ |
101 | 101 |
102 | 102 |
103 def extract_conditional(idl_file_path): | 103 def extract_conditional(idl_contents): |
104 """Find [Conditional] interface extended attribute.""" | 104 """Find [Conditional] interface extended attribute.""" |
105 with open(idl_file_path) as idl_file: | |
106 idl_contents = idl_file.read() | |
107 | 105 |
108 match = CONDITIONAL_PATTERN.search(idl_contents) | 106 match = CONDITIONAL_PATTERN.search(idl_contents) |
109 if not match: | 107 if not match: |
110 return None | 108 return None |
111 return match.group(1) | 109 return match.group(1) |
112 | 110 |
113 | 111 |
114 def extract_meta_data(file_paths): | 112 def extract_meta_data(file_paths): |
115 """Extracts conditional and interface name from each IDL file.""" | 113 """Extracts conditional and interface name from each IDL file.""" |
116 meta_data_list = [] | 114 meta_data_list = [] |
117 | 115 |
118 for file_path in file_paths: | 116 for file_path in file_paths: |
119 if not file_path.endswith('.idl'): | 117 if not file_path.endswith('.idl'): |
120 print 'WARNING: non-IDL file passed: "%s"' % file_path | 118 print 'WARNING: non-IDL file passed: "%s"' % file_path |
121 continue | 119 continue |
122 if not os.path.exists(file_path): | 120 if not os.path.exists(file_path): |
123 print 'WARNING: file not found: "%s"' % file_path | 121 print 'WARNING: file not found: "%s"' % file_path |
124 continue | 122 continue |
125 | 123 |
| 124 idl_file_contents = get_file_contents(file_path) |
| 125 if not should_generate_impl_file_from_idl(idl_file_contents): |
| 126 continue |
| 127 |
126 # Extract interface name from file name | 128 # Extract interface name from file name |
127 interface_name = idl_filename_to_interface_name(file_path) | 129 interface_name = idl_filename_to_interface_name(file_path) |
128 | 130 |
129 meta_data = { | 131 meta_data = { |
130 'conditional': extract_conditional(file_path), | 132 'conditional': extract_conditional(idl_file_contents), |
131 'name': interface_name, | 133 'name': interface_name, |
132 } | 134 } |
133 meta_data_list.append(meta_data) | 135 meta_data_list.append(meta_data) |
134 | 136 |
135 return meta_data_list | 137 return meta_data_list |
136 | 138 |
137 | 139 |
138 def generate_content(component_dir, files_meta_data_this_partition, prefix): | 140 def generate_content(component_dir, aggregate_partial_interfaces, files_meta_dat
a_this_partition): |
139 # Add fixed content. | 141 # Add fixed content. |
140 output = [COPYRIGHT_TEMPLATE, | 142 output = [COPYRIGHT_TEMPLATE, |
141 '#define NO_IMPLICIT_ATOMICSTRING\n\n'] | 143 '#define NO_IMPLICIT_ATOMICSTRING\n\n'] |
142 | 144 |
143 # List all includes segmented by if and endif. | 145 # List all includes segmented by if and endif. |
144 prev_conditional = None | 146 prev_conditional = None |
145 files_meta_data_this_partition.sort(key=lambda e: e['conditional']) | 147 files_meta_data_this_partition.sort(key=lambda e: e['conditional']) |
146 for meta_data in files_meta_data_this_partition: | 148 for meta_data in files_meta_data_this_partition: |
147 conditional = meta_data['conditional'] | 149 conditional = meta_data['conditional'] |
148 if prev_conditional != conditional: | 150 if prev_conditional != conditional: |
149 if prev_conditional: | 151 if prev_conditional: |
150 output.append('#endif\n') | 152 output.append('#endif\n') |
151 if conditional: | 153 if conditional: |
152 output.append('\n#if ENABLE(%s)\n' % conditional) | 154 output.append('\n#if ENABLE(%s)\n' % conditional) |
153 prev_conditional = conditional | 155 prev_conditional = conditional |
154 | 156 |
155 output.append('#include "bindings/%s/%s/%s%s.cpp"\n' % | 157 if aggregate_partial_interfaces: |
156 (component_dir, prefix.lower(), prefix, meta_data['name'])
) | 158 cpp_filename = 'V8%sPartial.cpp' % meta_data['name'] |
| 159 else: |
| 160 cpp_filename = 'V8%s.cpp' % meta_data['name'] |
| 161 |
| 162 output.append('#include "bindings/%s/v8/%s"\n' % |
| 163 (component_dir, cpp_filename)) |
157 | 164 |
158 if prev_conditional: | 165 if prev_conditional: |
159 output.append('#endif\n') | 166 output.append('#endif\n') |
160 | 167 |
161 return ''.join(output) | 168 return ''.join(output) |
162 | 169 |
163 | 170 |
164 def write_content(content, output_file_name): | 171 def write_content(content, output_file_name): |
165 parent_path, file_name = os.path.split(output_file_name) | 172 parent_path, file_name = os.path.split(output_file_name) |
166 if not os.path.exists(parent_path): | 173 if not os.path.exists(parent_path): |
167 print 'Creating directory: %s' % parent_path | 174 print 'Creating directory: %s' % parent_path |
168 os.makedirs(parent_path) | 175 os.makedirs(parent_path) |
169 with open(output_file_name, 'w') as f: | 176 with open(output_file_name, 'w') as f: |
170 f.write(content) | 177 f.write(content) |
171 | 178 |
172 | 179 |
173 def main(args): | 180 def main(args): |
174 if len(args) <= 4: | 181 if len(args) <= 4: |
175 raise Exception('Expected at least 5 arguments.') | 182 raise Exception('Expected at least 5 arguments.') |
176 if (args[1] == '--dart'): | 183 component_dir = args[1] |
177 component_dir = args[2] | 184 input_file_name = args[2] |
178 input_file_name = args[3] | |
179 prefix = 'Dart' | |
180 else: | |
181 component_dir = args[1] | |
182 input_file_name = args[2] | |
183 prefix = 'V8' | |
184 in_out_break_index = args.index('--') | 185 in_out_break_index = args.index('--') |
185 output_file_names = args[in_out_break_index + 1:] | 186 output_file_names = args[in_out_break_index + 1:] |
186 | 187 |
187 idl_file_names = read_idl_files_list_from_file(input_file_name) | 188 idl_file_names = read_idl_files_list_from_file(input_file_name) |
| 189 components = set([idl_filename_to_component(filename) |
| 190 for filename in idl_file_names]) |
| 191 if len(components) != 1: |
| 192 raise Exception('Cannot aggregate generated codes in different component
s') |
| 193 aggregate_partial_interfaces = component_dir not in components |
| 194 |
188 files_meta_data = extract_meta_data(idl_file_names) | 195 files_meta_data = extract_meta_data(idl_file_names) |
189 total_partitions = len(output_file_names) | 196 total_partitions = len(output_file_names) |
190 for partition, file_name in enumerate(output_file_names): | 197 for partition, file_name in enumerate(output_file_names): |
191 files_meta_data_this_partition = [ | 198 files_meta_data_this_partition = [ |
192 meta_data for meta_data in files_meta_data | 199 meta_data for meta_data in files_meta_data |
193 if hash(meta_data['name']) % total_partitions == partition] | 200 if hash(meta_data['name']) % total_partitions == partition] |
194 file_contents = generate_content(component_dir, | 201 file_contents = generate_content(component_dir, |
195 files_meta_data_this_partition, | 202 aggregate_partial_interfaces, |
196 prefix) | 203 files_meta_data_this_partition) |
197 write_content(file_contents, file_name) | 204 write_content(file_contents, file_name) |
198 | 205 |
199 | 206 |
200 if __name__ == '__main__': | 207 if __name__ == '__main__': |
201 sys.exit(main(sys.argv)) | 208 sys.exit(main(sys.argv)) |
OLD | NEW |