OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 20 matching lines...) Expand all Loading... |
31 import os.path | 31 import os.path |
32 import re | 32 import re |
33 import string | 33 import string |
34 | 34 |
35 | 35 |
36 def parse_options(): | 36 def parse_options(): |
37 parser = optparse.OptionParser() | 37 parser = optparse.OptionParser() |
38 parser.add_option('--idl-files-list', help='file listing all IDLs') | 38 parser.add_option('--idl-files-list', help='file listing all IDLs') |
39 parser.add_option('--supplemental-dependency-file', help='output file') | 39 parser.add_option('--supplemental-dependency-file', help='output file') |
40 parser.add_option('--window-constructors-file', help='output file') | 40 parser.add_option('--window-constructors-file', help='output file') |
41 parser.add_option('--workercontext-constructors-file', help='output file') | 41 parser.add_option('--workerglobalscope-constructors-file', help='output file
') |
| 42 parser.add_option('--sharedworkerglobalscope-constructors-file', help='outpu
t file') |
| 43 parser.add_option('--dedicatedworkerglobalscope-constructors-file', help='ou
tput file') |
42 parser.add_option('--write-file-only-if-changed', type='int') | 44 parser.add_option('--write-file-only-if-changed', type='int') |
43 options, args = parser.parse_args() | 45 options, args = parser.parse_args() |
44 if options.supplemental_dependency_file is None: | 46 if options.supplemental_dependency_file is None: |
45 parser.error('Must specify an output file using --supplemental-dependenc
y-file.') | 47 parser.error('Must specify an output file using --supplemental-dependenc
y-file.') |
46 if options.window_constructors_file is None: | 48 if options.window_constructors_file is None: |
47 parser.error('Must specify an output file using --window-constructors-fi
le.') | 49 parser.error('Must specify an output file using --window-constructors-fi
le.') |
48 if options.workercontext_constructors_file is None: | 50 if options.workerglobalscope_constructors_file is None: |
49 parser.error('Must specify an output file using --workercontext-construc
tors-file.') | 51 parser.error('Must specify an output file using --workerglobalscope-cons
tructors-file.') |
| 52 if options.workerglobalscope_constructors_file is None: |
| 53 parser.error('Must specify an output file using --sharedworkerglobalscop
e-constructors-file.') |
| 54 if options.workerglobalscope_constructors_file is None: |
| 55 parser.error('Must specify an output file using --dedicatedworkerglobals
cope-constructors-file.') |
50 if options.idl_files_list is None: | 56 if options.idl_files_list is None: |
51 parser.error('Must specify the file listing all IDLs using --idl-files-l
ist.') | 57 parser.error('Must specify the file listing all IDLs using --idl-files-l
ist.') |
52 if options.write_file_only_if_changed is None: | 58 if options.write_file_only_if_changed is None: |
53 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') | 59 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') |
54 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) | 60 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) |
55 if args: | 61 if args: |
56 parser.error('No arguments taken, but "%s" given.' % ' '.join(args)) | 62 parser.error('No arguments taken, but "%s" given.' % ' '.join(args)) |
57 return options | 63 return options |
58 | 64 |
59 | 65 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 141 |
136 | 142 |
137 def generate_global_constructors_partial_interface(interface_name, destination_f
ilename, constructor_attributes_list): | 143 def generate_global_constructors_partial_interface(interface_name, destination_f
ilename, constructor_attributes_list): |
138 with open(destination_filename, 'w') as destination_file: | 144 with open(destination_filename, 'w') as destination_file: |
139 destination_file.write('partial interface %s {\n' % interface_name) | 145 destination_file.write('partial interface %s {\n' % interface_name) |
140 for constructor_attribute in constructor_attributes_list: | 146 for constructor_attribute in constructor_attributes_list: |
141 destination_file.write(' %s;\n' % constructor_attribute) | 147 destination_file.write(' %s;\n' % constructor_attribute) |
142 destination_file.write('};\n') | 148 destination_file.write('};\n') |
143 | 149 |
144 | 150 |
145 def parse_idl_files(idl_files, window_constructors_filename, workercontext_const
ructors_filename): | 151 def parse_idl_files(idl_files, window_constructors_filename, workerglobalscope_c
onstructors_filename, sharedworkerglobalscope_constructors_filename, dedicatedwo
rkerglobalscope_constructors_filename): |
146 interface_name_to_idl_file = {} | 152 interface_name_to_idl_file = {} |
147 idl_file_to_interface_name = {} | 153 idl_file_to_interface_name = {} |
148 supplemental_dependencies = {} | 154 supplemental_dependencies = {} |
149 supplementals = {} | 155 supplementals = {} |
150 window_constructor_attributes_list = [] | 156 window_constructor_attributes_list = [] |
151 workercontext_constructor_attributes_list = [] | 157 workerglobalscope_constructor_attributes_list = [] |
| 158 sharedworkerglobalscope_constructor_attributes_list = [] |
| 159 dedicatedworkerglobalscope_constructor_attributes_list = [] |
152 | 160 |
153 # Populate interface_name_to_idl_file first | 161 # Populate interface_name_to_idl_file first |
154 for idl_file_name in idl_files: | 162 for idl_file_name in idl_files: |
155 full_path = os.path.realpath(idl_file_name) | 163 full_path = os.path.realpath(idl_file_name) |
156 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) | 164 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) |
157 interface_name_to_idl_file[interface_name] = full_path | 165 interface_name_to_idl_file[interface_name] = full_path |
158 | 166 |
159 for idl_file_name in idl_files: | 167 for idl_file_name in idl_files: |
160 full_path = os.path.realpath(idl_file_name) | 168 full_path = os.path.realpath(idl_file_name) |
161 idl_file_contents = get_file_contents(full_path) | 169 idl_file_contents = get_file_contents(full_path) |
162 # Handle partial interfaces | 170 # Handle partial interfaces |
163 partial_interface_name = get_partial_interface_name_from_idl(idl_file_co
ntents) | 171 partial_interface_name = get_partial_interface_name_from_idl(idl_file_co
ntents) |
164 if partial_interface_name: | 172 if partial_interface_name: |
165 supplemental_dependencies[full_path] = [partial_interface_name] | 173 supplemental_dependencies[full_path] = [partial_interface_name] |
166 continue | 174 continue |
167 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) | 175 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) |
168 # Parse 'identifier-A implements identifier-B; statements | 176 # Parse 'identifier-A implements identifier-B; statements |
169 implemented_interfaces = get_implemented_interfaces_from_idl(idl_file_co
ntents, interface_name) | 177 implemented_interfaces = get_implemented_interfaces_from_idl(idl_file_co
ntents, interface_name) |
170 for implemented_interface in implemented_interfaces: | 178 for implemented_interface in implemented_interfaces: |
171 assert implemented_interface in interface_name_to_idl_file, \ | 179 assert implemented_interface in interface_name_to_idl_file, \ |
172 "Could not find a the IDL file where the following implemented interface is defi
ned: %s" % implemented_interface | 180 "Could not find a the IDL file where the following implemented interface is defi
ned: %s" % implemented_interface |
173 supplemental_dependencies.setdefault(interface_name_to_idl_file[impl
emented_interface], []).append(interface_name) | 181 supplemental_dependencies.setdefault(interface_name_to_idl_file[impl
emented_interface], []).append(interface_name) |
174 # Handle [NoInterfaceObject] | 182 # Handle [NoInterfaceObject] |
175 if not is_callback_interface_from_idl(idl_file_contents): | 183 if not is_callback_interface_from_idl(idl_file_contents): |
176 extended_attributes = get_interface_extended_attributes_from_idl(idl
_file_contents) | 184 extended_attributes = get_interface_extended_attributes_from_idl(idl
_file_contents) |
177 if 'NoInterfaceObject' not in extended_attributes: | 185 if 'NoInterfaceObject' not in extended_attributes: |
178 global_context = extended_attributes.get("GlobalContext", "Windo
wOnly") | 186 global_contexts = extended_attributes.get('GlobalContext', 'Wind
ow').split('&') |
179 constructor_list = generate_constructor_attribute_list(interface
_name, extended_attributes) | 187 constructor_list = generate_constructor_attribute_list(interface
_name, extended_attributes) |
180 if global_context != "WorkerOnly": | 188 if 'Window' in global_contexts: |
181 window_constructor_attributes_list.extend(constructor_list) | 189 window_constructor_attributes_list.extend(constructor_list) |
182 if global_context != "WindowOnly": | 190 if 'WorkerGlobalScope' in global_contexts: |
183 workercontext_constructor_attributes_list.extend(constructor
_list) | 191 workerglobalscope_constructor_attributes_list.extend(constru
ctor_list) |
| 192 if 'SharedWorkerGlobalScope' in global_contexts: |
| 193 sharedworkerglobalscope_constructor_attributes_list.extend(c
onstructor_list) |
| 194 if 'DedicatedWorkerGlobalScope' in global_contexts: |
| 195 dedicatedworkerglobalscope_constructor_attributes_list.exten
d(constructor_list) |
184 idl_file_to_interface_name[full_path] = interface_name | 196 idl_file_to_interface_name[full_path] = interface_name |
185 supplementals[full_path] = [] | 197 supplementals[full_path] = [] |
186 | 198 |
187 # Generate Global constructors | 199 # Generate Global constructors |
188 generate_global_constructors_partial_interface("Window", window_constructors
_filename, window_constructor_attributes_list) | |
189 if 'Window' in interface_name_to_idl_file: | 200 if 'Window' in interface_name_to_idl_file: |
| 201 generate_global_constructors_partial_interface("Window", window_construc
tors_filename, window_constructor_attributes_list) |
190 supplemental_dependencies[window_constructors_filename] = ['Window'] | 202 supplemental_dependencies[window_constructors_filename] = ['Window'] |
191 generate_global_constructors_partial_interface("WorkerGlobalScope", workerco
ntext_constructors_filename, workercontext_constructor_attributes_list) | |
192 if 'WorkerGlobalScope' in interface_name_to_idl_file: | 203 if 'WorkerGlobalScope' in interface_name_to_idl_file: |
193 supplemental_dependencies[workercontext_constructors_filename] = ['Worke
rGlobalScope'] | 204 generate_global_constructors_partial_interface("WorkerGlobalScope", work
erglobalscope_constructors_filename, workerglobalscope_constructor_attributes_li
st) |
| 205 supplemental_dependencies[workerglobalscope_constructors_filename] = ['W
orkerGlobalScope'] |
| 206 if 'SharedWorkerGlobalScope' in interface_name_to_idl_file: |
| 207 generate_global_constructors_partial_interface("SharedWorkerGlobalScope"
, sharedworkerglobalscope_constructors_filename, sharedworkerglobalscope_constru
ctor_attributes_list) |
| 208 supplemental_dependencies[sharedworkerglobalscope_constructors_filename]
= ['SharedWorkerGlobalScope'] |
| 209 if 'DedicatedWorkerGlobalScope' in interface_name_to_idl_file: |
| 210 generate_global_constructors_partial_interface("DedicatedWorkerGlobalSco
pe", dedicatedworkerglobalscope_constructors_filename, dedicatedworkerglobalscop
e_constructor_attributes_list) |
| 211 supplemental_dependencies[dedicatedworkerglobalscope_constructors_filena
me] = ['DedicatedWorkerGlobalScope'] |
194 | 212 |
195 # Resolve partial interfaces dependencies | 213 # Resolve partial interfaces dependencies |
196 for idl_file, base_files in supplemental_dependencies.iteritems(): | 214 for idl_file, base_files in supplemental_dependencies.iteritems(): |
197 for base_file in base_files: | 215 for base_file in base_files: |
198 target_idl_file = interface_name_to_idl_file[base_file] | 216 target_idl_file = interface_name_to_idl_file[base_file] |
199 supplementals[target_idl_file].append(idl_file) | 217 supplementals[target_idl_file].append(idl_file) |
200 if idl_file in supplementals: | 218 if idl_file in supplementals: |
201 # Should never occur. Might be needed in corner cases. | 219 # Should never occur. Might be needed in corner cases. |
202 del supplementals[idl_file] | 220 del supplementals[idl_file] |
203 return supplementals | 221 return supplementals |
(...skipping 28 matching lines...) Expand all Loading... |
232 with open(filename, 'w') as out_file: | 250 with open(filename, 'w') as out_file: |
233 out_file.write(''.join(new_lines)) | 251 out_file.write(''.join(new_lines)) |
234 | 252 |
235 | 253 |
236 def main(): | 254 def main(): |
237 options = parse_options() | 255 options = parse_options() |
238 idl_files = [] | 256 idl_files = [] |
239 with open(options.idl_files_list) as idl_files_list_file: | 257 with open(options.idl_files_list) as idl_files_list_file: |
240 for line in idl_files_list_file: | 258 for line in idl_files_list_file: |
241 idl_files.append(string.rstrip(line, '\n')) | 259 idl_files.append(string.rstrip(line, '\n')) |
242 resolved_supplementals = parse_idl_files(idl_files, options.window_construct
ors_file, options.workercontext_constructors_file) | 260 resolved_supplementals = parse_idl_files(idl_files, options.window_construct
ors_file, options.workerglobalscope_constructors_file, options.sharedworkergloba
lscope_constructors_file, options.dedicatedworkerglobalscope_constructors_file) |
243 write_dependency_file(options.supplemental_dependency_file, resolved_supplem
entals, only_if_changed=options.write_file_only_if_changed) | 261 write_dependency_file(options.supplemental_dependency_file, resolved_supplem
entals, only_if_changed=options.write_file_only_if_changed) |
244 | 262 |
245 | 263 |
246 if __name__ == '__main__': | 264 if __name__ == '__main__': |
247 main() | 265 main() |
OLD | NEW |