| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Generates interface properties on global objects. | 7 """Generates interface properties on global objects. |
| 8 | 8 |
| 9 Concretely these are implemented as "constructor attributes", meaning | 9 Concretely these are implemented as "constructor attributes", meaning |
| 10 "attributes whose name ends with Constructor" (special-cased by code generator), | 10 "attributes whose name ends with Constructor" (special-cased by code generator), |
| 11 hence "global constructors" for short. | 11 hence "global constructors" for short. |
| 12 | 12 |
| 13 For reference on global objects, see: | 13 For reference on global objects, see: |
| 14 http://heycam.github.io/webidl/#Global | 14 http://heycam.github.io/webidl/#Global |
| 15 http://heycam.github.io/webidl/#Exposed | 15 http://heycam.github.io/webidl/#Exposed |
| 16 | 16 |
| 17 Design document: http://www.chromium.org/developers/design-documents/idl-build | 17 Design document: http://www.chromium.org/developers/design-documents/idl-build |
| 18 """ | 18 """ |
| 19 | 19 |
| 20 # pylint: disable=relative-import |
| 21 |
| 20 import itertools | 22 import itertools |
| 21 import optparse | 23 import optparse |
| 22 import os | 24 import os |
| 23 import cPickle as pickle | |
| 24 import re | 25 import re |
| 25 import sys | 26 import sys |
| 26 | 27 |
| 28 from collections import defaultdict |
| 29 from utilities import get_file_contents |
| 30 from utilities import get_interface_exposed_arguments |
| 31 from utilities import get_interface_extended_attributes_from_idl |
| 32 from utilities import idl_filename_to_interface_name |
| 33 from utilities import is_callback_interface_from_idl |
| 34 from utilities import read_file_to_list |
| 35 from utilities import read_pickle_file |
| 36 from utilities import should_generate_impl_file_from_idl |
| 37 from utilities import write_file |
| 27 from v8_utilities import EXPOSED_EXECUTION_CONTEXT_METHOD | 38 from v8_utilities import EXPOSED_EXECUTION_CONTEXT_METHOD |
| 28 | 39 |
| 29 from collections import defaultdict | |
| 30 from utilities import should_generate_impl_file_from_idl, get_file_contents, idl
_filename_to_interface_name, read_file_to_list, write_file, get_interface_extend
ed_attributes_from_idl, get_interface_exposed_arguments, is_callback_interface_f
rom_idl | |
| 31 | |
| 32 interface_name_to_global_names = {} | 40 interface_name_to_global_names = {} |
| 33 global_name_to_constructors = defaultdict(list) | 41 global_name_to_constructors = defaultdict(list) |
| 34 | 42 |
| 35 | 43 |
| 36 HEADER_FORMAT = """// Stub header file for {{idl_basename}} | 44 HEADER_FORMAT = """// Stub header file for {{idl_basename}} |
| 37 // Required because the IDL compiler assumes that a corresponding header file | 45 // Required because the IDL compiler assumes that a corresponding header file |
| 38 // exists for each IDL file. | 46 // exists for each IDL file. |
| 39 """ | 47 """ |
| 40 | 48 |
| 41 def parse_options(): | 49 def parse_options(): |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 # limits. This is generated at GYP time, which is ok b/c files are static. | 156 # limits. This is generated at GYP time, which is ok b/c files are static. |
| 149 idl_files = read_file_to_list(options.idl_files_list) | 157 idl_files = read_file_to_list(options.idl_files_list) |
| 150 | 158 |
| 151 # Output IDL files (to generate) are passed at the command line, since | 159 # Output IDL files (to generate) are passed at the command line, since |
| 152 # these are in the build directory, which is determined at build time, not | 160 # these are in the build directory, which is determined at build time, not |
| 153 # GYP time. | 161 # GYP time. |
| 154 # These are passed as pairs of GlobalObjectName, GlobalObject.idl | 162 # These are passed as pairs of GlobalObjectName, GlobalObject.idl |
| 155 interface_name_idl_filename = [(args[i], args[i + 1]) | 163 interface_name_idl_filename = [(args[i], args[i + 1]) |
| 156 for i in range(0, len(args), 2)] | 164 for i in range(0, len(args), 2)] |
| 157 | 165 |
| 158 with open(options.global_objects_file) as global_objects_file: | 166 interface_name_to_global_names.update(read_pickle_file(options.global_object
s_file)) |
| 159 interface_name_to_global_names.update(pickle.load(global_objects_file)) | |
| 160 | 167 |
| 161 for idl_filename in idl_files: | 168 for idl_filename in idl_files: |
| 162 record_global_constructors(idl_filename) | 169 record_global_constructors(idl_filename) |
| 163 | 170 |
| 164 # Check for [Exposed] / [Global] mismatch. | 171 # Check for [Exposed] / [Global] mismatch. |
| 165 known_global_names = EXPOSED_EXECUTION_CONTEXT_METHOD.keys() | 172 known_global_names = EXPOSED_EXECUTION_CONTEXT_METHOD.keys() |
| 166 exposed_global_names = frozenset(global_name_to_constructors) | 173 exposed_global_names = frozenset(global_name_to_constructors) |
| 167 if not exposed_global_names.issubset(known_global_names): | 174 if not exposed_global_names.issubset(known_global_names): |
| 168 unknown_global_names = exposed_global_names.difference(known_global_name
s) | 175 unknown_global_names = exposed_global_names.difference(known_global_name
s) |
| 169 raise ValueError('The following global names were used in ' | 176 raise ValueError('The following global names were used in ' |
| 170 '[Exposed=xxx] but do not match any [Global] / ' | 177 '[Exposed=xxx] but do not match any [Global] / ' |
| 171 '[PrimaryGlobal] interface: %s' | 178 '[PrimaryGlobal] interface: %s' |
| 172 % list(unknown_global_names)) | 179 % list(unknown_global_names)) |
| 173 | 180 |
| 174 # Write partial interfaces containing constructor attributes for each | 181 # Write partial interfaces containing constructor attributes for each |
| 175 # global interface. | 182 # global interface. |
| 176 for interface_name, idl_filename in interface_name_idl_filename: | 183 for interface_name, idl_filename in interface_name_idl_filename: |
| 177 constructors = interface_name_to_constructors(interface_name) | 184 constructors = interface_name_to_constructors(interface_name) |
| 178 write_global_constructors_partial_interface( | 185 write_global_constructors_partial_interface( |
| 179 interface_name, idl_filename, constructors) | 186 interface_name, idl_filename, constructors) |
| 180 | 187 |
| 181 | 188 |
| 182 if __name__ == '__main__': | 189 if __name__ == '__main__': |
| 183 sys.exit(main()) | 190 sys.exit(main()) |
| OLD | NEW |