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('--write-file-only-if-changed', type='int') | 42 parser.add_option('--write-file-only-if-changed', type='int') |
42 options, args = parser.parse_args() | 43 options, args = parser.parse_args() |
43 if options.supplemental_dependency_file is None: | 44 if options.supplemental_dependency_file is None: |
44 parser.error('Must specify an output file using --supplemental-dependenc
y-file.') | 45 parser.error('Must specify an output file using --supplemental-dependenc
y-file.') |
45 if options.window_constructors_file is None: | 46 if options.window_constructors_file is None: |
46 parser.error('Must specify an output file using --window-constructors-fi
le.') | 47 parser.error('Must specify an output file using --window-constructors-fi
le.') |
47 if options.idl_files_list is None: | 48 if options.idl_files_list is None: |
48 parser.error('Must specify the file listing all IDLs using --idl-files-l
ist.') | 49 parser.error('Must specify the file listing all IDLs using --idl-files-l
ist.') |
49 if options.write_file_only_if_changed is None: | 50 if options.write_file_only_if_changed is None: |
50 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') | 51 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 named_constructor = extended_attributes['NamedConstructor'] | 119 named_constructor = extended_attributes['NamedConstructor'] |
119 # Extract function name, namely everything before opening '(' | 120 # Extract function name, namely everything before opening '(' |
120 constructor_name = re.sub(r'\(.*', '', named_constructor) | 121 constructor_name = re.sub(r'\(.*', '', named_constructor) |
121 # Note the reduplicated 'ConstructorConstructor' | 122 # Note the reduplicated 'ConstructorConstructor' |
122 attribute_string = 'attribute %sConstructorConstructor %s' % (interface_
name, constructor_name) | 123 attribute_string = 'attribute %sConstructorConstructor %s' % (interface_
name, constructor_name) |
123 attributes_list.append(extended_string + attribute_string) | 124 attributes_list.append(extended_string + attribute_string) |
124 | 125 |
125 return attributes_list | 126 return attributes_list |
126 | 127 |
127 | 128 |
128 def generate_dom_window_constructors_partial_interface(window_constructors_filen
ame, constructor_attributes_list): | 129 def generate_global_constructors_partial_interface(interface_name, destination_f
ilename, constructor_attributes_list): |
129 with open(window_constructors_filename, 'w') as window_constructors_file: | 130 with open(destination_filename, 'w') as destination_file: |
130 window_constructors_file.write('partial interface DOMWindow {\n') | 131 destination_file.write('partial interface %s {\n' % interface_name) |
131 for constructor_attribute in constructor_attributes_list: | 132 for constructor_attribute in constructor_attributes_list: |
132 window_constructors_file.write(' %s;\n' % constructor_attribute) | 133 destination_file.write(' %s;\n' % constructor_attribute) |
133 window_constructors_file.write('};\n') | 134 destination_file.write('};\n') |
134 | 135 |
135 | 136 |
136 def parse_idl_files(idl_files, window_constructors_filename): | 137 def parse_idl_files(idl_files, window_constructors_filename, workercontext_const
ructors_filename): |
137 interface_name_to_idl_file = {} | 138 interface_name_to_idl_file = {} |
138 idl_file_to_interface_name = {} | 139 idl_file_to_interface_name = {} |
139 supplemental_dependencies = {} | 140 supplemental_dependencies = {} |
140 supplementals = {} | 141 supplementals = {} |
141 constructor_attributes_list = [] | 142 window_constructor_attributes_list = [] |
| 143 workercontext_constructor_attributes_list = [] |
142 | 144 |
143 for idl_file_name in idl_files: | 145 for idl_file_name in idl_files: |
144 full_path = os.path.realpath(idl_file_name) | 146 full_path = os.path.realpath(idl_file_name) |
145 idl_file_contents = get_file_contents(full_path) | 147 idl_file_contents = get_file_contents(full_path) |
146 partial_interface_name = get_partial_interface_name_from_idl(idl_file_co
ntents) | 148 partial_interface_name = get_partial_interface_name_from_idl(idl_file_co
ntents) |
147 if partial_interface_name: | 149 if partial_interface_name: |
148 supplemental_dependencies[full_path] = partial_interface_name | 150 supplemental_dependencies[full_path] = partial_interface_name |
149 continue | 151 continue |
150 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) | 152 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) |
151 if not is_callback_interface_from_idl(idl_file_contents): | 153 if not is_callback_interface_from_idl(idl_file_contents): |
152 extended_attributes = get_interface_extended_attributes_from_idl(idl
_file_contents) | 154 extended_attributes = get_interface_extended_attributes_from_idl(idl
_file_contents) |
153 if 'NoInterfaceObject' not in extended_attributes: | 155 if 'NoInterfaceObject' not in extended_attributes: |
154 constructor_attributes_list.extend(generate_constructor_attribut
e_list(interface_name, extended_attributes)) | 156 global_context = extended_attributes.get("GlobalContext", "Windo
wOnly") |
| 157 constructor_list = generate_constructor_attribute_list(interface
_name, extended_attributes) |
| 158 if global_context != "WorkerOnly": |
| 159 window_constructor_attributes_list.extend(constructor_list) |
| 160 if global_context != "WindowOnly": |
| 161 workercontext_constructor_attributes_list.extend(constructor
_list) |
155 interface_name_to_idl_file[interface_name] = full_path | 162 interface_name_to_idl_file[interface_name] = full_path |
156 idl_file_to_interface_name[full_path] = interface_name | 163 idl_file_to_interface_name[full_path] = interface_name |
157 supplementals[full_path] = [] | 164 supplementals[full_path] = [] |
158 | 165 |
159 generate_dom_window_constructors_partial_interface(window_constructors_filen
ame, constructor_attributes_list) | 166 # Generate Global constructors |
| 167 generate_global_constructors_partial_interface("DOMWindow", window_construct
ors_filename, window_constructor_attributes_list) |
160 if 'DOMWindow' in interface_name_to_idl_file: | 168 if 'DOMWindow' in interface_name_to_idl_file: |
161 supplemental_dependencies[window_constructors_filename] = 'DOMWindow' | 169 supplemental_dependencies[window_constructors_filename] = 'DOMWindow' |
| 170 generate_global_constructors_partial_interface("WorkerContext", workercontex
t_constructors_filename, workercontext_constructor_attributes_list) |
| 171 if 'WorkerContext' in interface_name_to_idl_file: |
| 172 supplemental_dependencies[workercontext_constructors_filename] = 'Worker
Context' |
| 173 |
162 # Resolve partial interfaces dependencies | 174 # Resolve partial interfaces dependencies |
163 for idl_file, base_file in supplemental_dependencies.iteritems(): | 175 for idl_file, base_file in supplemental_dependencies.iteritems(): |
164 target_idl_file = interface_name_to_idl_file[base_file] | 176 target_idl_file = interface_name_to_idl_file[base_file] |
165 supplementals[target_idl_file].append(idl_file) | 177 supplementals[target_idl_file].append(idl_file) |
166 if idl_file in supplementals: | 178 if idl_file in supplementals: |
167 # Should never occur. Might be needed in corner cases. | 179 # Should never occur. Might be needed in corner cases. |
168 del supplementals[idl_file] | 180 del supplementals[idl_file] |
169 return supplementals | 181 return supplementals |
170 | 182 |
171 | 183 |
(...skipping 26 matching lines...) Expand all Loading... |
198 with open(filename, 'w') as out_file: | 210 with open(filename, 'w') as out_file: |
199 out_file.write(''.join(new_lines)) | 211 out_file.write(''.join(new_lines)) |
200 | 212 |
201 | 213 |
202 def main(): | 214 def main(): |
203 options = parse_options() | 215 options = parse_options() |
204 idl_files = [] | 216 idl_files = [] |
205 with open(options.idl_files_list) as idl_files_list_file: | 217 with open(options.idl_files_list) as idl_files_list_file: |
206 for line in idl_files_list_file: | 218 for line in idl_files_list_file: |
207 idl_files.append(string.rstrip(line, '\n')) | 219 idl_files.append(string.rstrip(line, '\n')) |
208 resolved_supplementals = parse_idl_files(idl_files, options.window_construct
ors_file) | 220 resolved_supplementals = parse_idl_files(idl_files, options.window_construct
ors_file, options.workercontext_constructors_file) |
209 write_dependency_file(options.supplemental_dependency_file, resolved_supplem
entals, only_if_changed=options.write_file_only_if_changed) | 221 write_dependency_file(options.supplemental_dependency_file, resolved_supplem
entals, only_if_changed=options.write_file_only_if_changed) |
210 | 222 |
211 | 223 |
212 if __name__ == '__main__': | 224 if __name__ == '__main__': |
213 main() | 225 main() |
OLD | NEW |