| Index: Source/bindings/scripts/compute_interfaces_info.py
|
| diff --git a/Source/bindings/scripts/compute_dependencies.py b/Source/bindings/scripts/compute_interfaces_info.py
|
| similarity index 51%
|
| rename from Source/bindings/scripts/compute_dependencies.py
|
| rename to Source/bindings/scripts/compute_interfaces_info.py
|
| index f7e0257e8507a03316f5f74de9b3089041bacfb5..d0516d97c25fb83dbcaf3410f18e5229f10d7c75 100755
|
| --- a/Source/bindings/scripts/compute_dependencies.py
|
| +++ b/Source/bindings/scripts/compute_interfaces_info.py
|
| @@ -28,12 +28,63 @@
|
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| +"""Compute global interface information, including public information, dependencies, and inheritance.
|
| +
|
| +Computed data is stored in a global variable, |interfaces_info|, and written as
|
| +output (concretely, exported as a pickle). This is then used by the IDL compiler
|
| +itself, so it does not need to compute global information itself, and so that
|
| +inter-IDL dependencies are clear, since they are all computed here.
|
| +
|
| +The |interfaces_info| pickle is a *global* dependency: any changes cause a full
|
| +rebuild. This is to avoid having to compute which public data is visible by
|
| +which IDL files on a file-by-file basis, which is very complex for little
|
| +benefit.
|
| +|interfaces_info| should thus only contain data about an interface that
|
| +contains paths or is needed by *other* interfaces, e.g., path data (to abstract
|
| +the compiler from OS-specific file paths) or public data (to avoid having to
|
| +read other interfaces unnecessarily).
|
| +It should *not* contain full information about an interface (e.g., all
|
| +extended attributes), as this would cause unnecessary rebuilds.
|
| +
|
| +|interfaces_info| is a dict, keyed by |interface_name|.
|
| +
|
| +Current keys are:
|
| +* dependencies:
|
| + 'implements_interfaces': targets of 'implements' statements
|
| + 'referenced_interfaces': reference interfaces that are introspected
|
| + (currently just targets of [PutForwards])
|
| +
|
| +* inheritance:
|
| + 'ancestors': all ancestor interfaces
|
| + 'inherited_extended_attributes': inherited extended attributes
|
| + (all controlling memory management)
|
| +
|
| +* public:
|
| + 'is_callback_interface': bool, callback interface or not
|
| + 'implemented_as': value of [ImplementedAs=...] on interface (C++ class name)
|
| +
|
| +* paths:
|
| + 'full_path': path to the IDL file, so can lookup an IDL by interface name
|
| + 'include_path': path for use in C++ #include directives
|
| + 'dependencies_full_paths': paths to dependencies (for merging into main)
|
| + 'dependencies_include_paths': paths for use in C++ #include directives
|
| +
|
| +Note that all of these are stable information, unlikely to change without
|
| +moving or deleting files (hence requiring a full rebuild anyway) or significant
|
| +code changes (for inherited extended attributes).
|
| +
|
| +FIXME: also generates EventNames.in; factor out. http://crbug.com/341748
|
| +FIXME: also generates InterfaceDependencies.txt for Perl. http://crbug.com/239771
|
| +
|
| +Design doc: http://www.chromium.org/developers/design-documents/idl-build
|
| +"""
|
| +
|
| import optparse
|
| import os
|
| -import cPickle as pickle
|
| import posixpath
|
| -import re
|
| -import string
|
| +import sys
|
| +
|
| +from utilities import get_file_contents, write_file, write_pickle_file, get_interface_extended_attributes_from_idl, is_callback_interface_from_idl, get_partial_interface_name_from_idl, get_implemented_interfaces_from_idl, get_parent_interface, get_put_forward_interfaces_from_idl
|
|
|
| module_path = os.path.dirname(__file__)
|
| source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir))
|
| @@ -44,13 +95,7 @@ INHERITED_EXTENDED_ATTRIBUTES = set([
|
| 'WillBeGarbageCollected',
|
| ])
|
|
|
| -
|
| -# interfaces_info is *exported* (in a pickle), and should only contain data
|
| -# about an interface that contains paths or is needed by *other* interfaces,
|
| -# i.e., file layout data (to abstract the compiler from file paths) or
|
| -# public data (to avoid having to read other interfaces unnecessarily).
|
| -# It should *not* contain full information about an interface (e.g., all
|
| -# extended attributes), as this would cause unnecessary rebuilds.
|
| +# Main variable (filled in and exported)
|
| interfaces_info = {}
|
|
|
| # Auxiliary variables (not visible to future build steps)
|
| @@ -59,11 +104,6 @@ parent_interfaces = {}
|
| extended_attributes_by_interface = {} # interface name -> extended attributes
|
|
|
|
|
| -class IdlBadFilenameError(Exception):
|
| - """Raised if an IDL filename disagrees with the interface name in the file."""
|
| - pass
|
| -
|
| -
|
| class IdlInterfaceFileNotFoundError(Exception):
|
| """Raised if the IDL file implementing an interface cannot be found."""
|
| pass
|
| @@ -76,11 +116,6 @@ def parse_options():
|
| parser.add_option('--idl-files-list', help='file listing IDL files')
|
| parser.add_option('--interface-dependencies-file', help='output file')
|
| parser.add_option('--interfaces-info-file', help='output pickle file')
|
| - parser.add_option('--window-constructors-file', help='output file')
|
| - parser.add_option('--workerglobalscope-constructors-file', help='output file')
|
| - parser.add_option('--sharedworkerglobalscope-constructors-file', help='output file')
|
| - parser.add_option('--dedicatedworkerglobalscope-constructors-file', help='output file')
|
| - parser.add_option('--serviceworkerglobalscope-constructors-file', help='output file')
|
| parser.add_option('--write-file-only-if-changed', type='int', help='if true, do not write an output file if it would be identical to the existing one, which avoids unnecessary rebuilds in ninja')
|
| options, args = parser.parse_args()
|
| if options.event_names_file is None:
|
| @@ -89,16 +124,6 @@ def parse_options():
|
| parser.error('Must specify an output file using --interface-dependencies-file.')
|
| if options.interfaces_info_file is None:
|
| parser.error('Must specify an output file using --interfaces-info-file.')
|
| - if options.window_constructors_file is None:
|
| - parser.error('Must specify an output file using --window-constructors-file.')
|
| - if options.workerglobalscope_constructors_file is None:
|
| - parser.error('Must specify an output file using --workerglobalscope-constructors-file.')
|
| - if options.sharedworkerglobalscope_constructors_file is None:
|
| - parser.error('Must specify an output file using --sharedworkerglobalscope-constructors-file.')
|
| - if options.dedicatedworkerglobalscope_constructors_file is None:
|
| - parser.error('Must specify an output file using --dedicatedworkerglobalscope-constructors-file.')
|
| - if options.serviceworkerglobalscope_constructors_file is None:
|
| - parser.error('Must specify an output file using --serviceworkerglobalscope-constructors-file.')
|
| if options.idl_files_list is None:
|
| parser.error('Must specify a file listing IDL files using --idl-files-list.')
|
| if options.write_file_only_if_changed is None:
|
| @@ -108,121 +133,6 @@ def parse_options():
|
|
|
|
|
| ################################################################################
|
| -# Basic file reading/writing
|
| -################################################################################
|
| -
|
| -def get_file_contents(idl_filename):
|
| - with open(idl_filename) as idl_file:
|
| - lines = idl_file.readlines()
|
| - return ''.join(lines)
|
| -
|
| -
|
| -def write_file(new_lines, destination_filename, only_if_changed):
|
| - if only_if_changed and os.path.isfile(destination_filename):
|
| - with open(destination_filename) as destination_file:
|
| - if destination_file.readlines() == new_lines:
|
| - return
|
| - with open(destination_filename, 'w') as destination_file:
|
| - destination_file.write(''.join(new_lines))
|
| -
|
| -
|
| -def write_pickle_file(pickle_filename, data, only_if_changed):
|
| - if only_if_changed and os.path.isfile(pickle_filename):
|
| - with open(pickle_filename) as pickle_file:
|
| - if pickle.load(pickle_file) == data:
|
| - return
|
| - with open(pickle_filename, 'w') as pickle_file:
|
| - pickle.dump(data, pickle_file)
|
| -
|
| -
|
| -################################################################################
|
| -# IDL parsing
|
| -#
|
| -# We use regular expressions for parsing; this is incorrect (Web IDL is not a
|
| -# regular language), but simple and sufficient in practice.
|
| -# Leading and trailing context (e.g. following '{') used to avoid false matches.
|
| -################################################################################
|
| -
|
| -def get_partial_interface_name_from_idl(file_contents):
|
| - match = re.search(r'partial\s+interface\s+(\w+)\s*{', file_contents)
|
| - return match and match.group(1)
|
| -
|
| -
|
| -# identifier-A implements identifier-B;
|
| -# http://www.w3.org/TR/WebIDL/#idl-implements-statements
|
| -def get_implemented_interfaces_from_idl(file_contents, interface_name):
|
| - def get_implemented(left_identifier, right_identifier):
|
| - # identifier-A must be the current interface
|
| - if left_identifier != interface_name:
|
| - raise IdlBadFilenameError("Identifier on the left of the 'implements' statement should be %s in %s.idl, but found %s" % (interface_name, interface_name, left_identifier))
|
| - return right_identifier
|
| -
|
| - implements_re = (r'^\s*'
|
| - r'(\w+)\s+'
|
| - r'implements\s+'
|
| - r'(\w+)\s*'
|
| - r';')
|
| - implements_matches = re.finditer(implements_re, file_contents, re.MULTILINE)
|
| - implements_pairs = [(match.group(1), match.group(2))
|
| - for match in implements_matches]
|
| - return [get_implemented(left, right) for left, right in implements_pairs]
|
| -
|
| -
|
| -def is_callback_interface_from_idl(file_contents):
|
| - match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents)
|
| - return bool(match)
|
| -
|
| -
|
| -def get_parent_interface(file_contents):
|
| - match = re.search(r'interface\s+'
|
| - r'\w+\s*'
|
| - r':\s*(\w+)\s*'
|
| - r'{',
|
| - file_contents)
|
| - return match and match.group(1)
|
| -
|
| -
|
| -def get_interface_extended_attributes_from_idl(file_contents):
|
| - match = re.search(r'\[(.*)\]\s*'
|
| - r'((callback|partial)\s+)?'
|
| - r'(interface|exception)\s+'
|
| - r'\w+\s*'
|
| - r'(:\s*\w+\s*)?'
|
| - r'{',
|
| - file_contents, flags=re.DOTALL)
|
| - if not match:
|
| - return {}
|
| - # Strip comments
|
| - # re.compile needed b/c Python 2.6 doesn't support flags in re.sub
|
| - single_line_comment_re = re.compile(r'//.*$', flags=re.MULTILINE)
|
| - block_comment_re = re.compile(r'/\*.*?\*/', flags=re.MULTILINE | re.DOTALL)
|
| - extended_attributes_string = re.sub(single_line_comment_re, '', match.group(1))
|
| - extended_attributes_string = re.sub(block_comment_re, '', extended_attributes_string)
|
| - extended_attributes = {}
|
| - # FIXME: this splitting is WRONG: it fails on ExtendedAttributeArgList like
|
| - # 'NamedConstructor=Foo(a, b)'
|
| - parts = [extended_attribute.strip()
|
| - for extended_attribute in extended_attributes_string.split(',')
|
| - # Discard empty parts, which may exist due to trailing comma
|
| - if extended_attribute.strip()]
|
| - for part in parts:
|
| - name, _, value = map(string.strip, part.partition('='))
|
| - extended_attributes[name] = value
|
| - return extended_attributes
|
| -
|
| -
|
| -def get_put_forward_interfaces_from_idl(file_contents):
|
| - put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+'
|
| - r'readonly\s+'
|
| - r'attribute\s+'
|
| - r'(\w+)')
|
| - return sorted(set(match.group(1)
|
| - for match in re.finditer(put_forwards_pattern,
|
| - file_contents,
|
| - flags=re.DOTALL)))
|
| -
|
| -
|
| -################################################################################
|
| # Write files
|
| ################################################################################
|
|
|
| @@ -244,7 +154,7 @@ def write_dependencies_file(dependencies_filename, only_if_changed):
|
| An IDL that is a dependency of another IDL (e.g. P.idl) does not have its
|
| own line in the dependency file.
|
| """
|
| - # FIXME: remove text format once Perl gone (Python uses pickle)
|
| + # FIXME: remove this file once Perl is gone http://crbug.com/239771
|
| dependencies_list = sorted(
|
| (interface_info['full_path'], sorted(interface_info['dependencies_full_paths']))
|
| for interface_info in interfaces_info.values())
|
| @@ -256,6 +166,7 @@ def write_dependencies_file(dependencies_filename, only_if_changed):
|
| def write_event_names_file(destination_filename, only_if_changed):
|
| # Generate event names for all interfaces that inherit from Event,
|
| # including Event itself.
|
| + # FIXME: factor out. http://crbug.com/341748
|
| event_names = set(
|
| interface_name
|
| for interface_name, interface_info in interfaces_info.iteritems()
|
| @@ -288,16 +199,8 @@ def write_event_names_file(destination_filename, only_if_changed):
|
| write_file(lines, destination_filename, only_if_changed)
|
|
|
|
|
| -def write_global_constructors_partial_interface(interface_name, destination_filename, constructor_attributes_list, only_if_changed):
|
| - lines = (['partial interface %s {\n' % interface_name] +
|
| - [' %s;\n' % constructor_attribute
|
| - for constructor_attribute in sorted(constructor_attributes_list)] +
|
| - ['};\n'])
|
| - write_file(lines, destination_filename, only_if_changed)
|
| -
|
| -
|
| ################################################################################
|
| -# Dependency resolution
|
| +# Computations
|
| ################################################################################
|
|
|
| def include_path(idl_filename, implemented_as=None):
|
| @@ -325,8 +228,7 @@ def add_paths_to_partials_dict(partial_interface_name, full_path, this_include_p
|
| paths_dict['include_paths'].append(this_include_path)
|
|
|
|
|
| -def generate_dependencies(idl_filename):
|
| - """Compute dependencies for IDL file, returning True if main (non-partial) interface"""
|
| +def compute_individual_info(idl_filename):
|
| full_path = os.path.realpath(idl_filename)
|
| idl_file_contents = get_file_contents(full_path)
|
|
|
| @@ -340,7 +242,7 @@ def generate_dependencies(idl_filename):
|
| partial_interface_name = get_partial_interface_name_from_idl(idl_file_contents)
|
| if partial_interface_name:
|
| add_paths_to_partials_dict(partial_interface_name, full_path, this_include_path)
|
| - return False
|
| + return
|
|
|
| # If not a partial interface, the basename is the interface name
|
| interface_name, _ = os.path.splitext(os.path.basename(idl_filename))
|
| @@ -362,68 +264,15 @@ def generate_dependencies(idl_filename):
|
| if implemented_as:
|
| interfaces_info[interface_name]['implemented_as'] = implemented_as
|
|
|
| - return True
|
| -
|
| -
|
| -def generate_constructor_attribute_list(interface_name, extended_attributes):
|
| - extended_attributes_list = [
|
| - name + '=' + extended_attributes[name]
|
| - for name in 'Conditional', 'PerContextEnabled', 'RuntimeEnabled'
|
| - if name in extended_attributes]
|
| - if extended_attributes_list:
|
| - extended_string = '[%s] ' % ', '.join(extended_attributes_list)
|
| - else:
|
| - extended_string = ''
|
| -
|
| - attribute_string = 'attribute {interface_name}Constructor {interface_name}'.format(interface_name=interface_name)
|
| - attributes_list = [extended_string + attribute_string]
|
| -
|
| - # In addition to the regular property, for every [NamedConstructor]
|
| - # extended attribute on an interface, a corresponding property MUST exist
|
| - # on the ECMAScript global object.
|
| - if 'NamedConstructor' in extended_attributes:
|
| - named_constructor = extended_attributes['NamedConstructor']
|
| - # Extract function name, namely everything before opening '('
|
| - constructor_name = re.sub(r'\(.*', '', named_constructor)
|
| - # Note the reduplicated 'ConstructorConstructor'
|
| - attribute_string = 'attribute %sConstructorConstructor %s' % (interface_name, constructor_name)
|
| - attributes_list.append(extended_string + attribute_string)
|
| -
|
| - return attributes_list
|
| -
|
| -
|
| -def record_global_constructors_and_extended_attributes(idl_filename, global_constructors):
|
| - interface_name, _ = os.path.splitext(os.path.basename(idl_filename))
|
| - full_path = os.path.realpath(idl_filename)
|
| - idl_file_contents = get_file_contents(full_path)
|
| - extended_attributes = get_interface_extended_attributes_from_idl(idl_file_contents)
|
| -
|
| - # Record extended attributes
|
| + # Record auxiliary information
|
| extended_attributes_by_interface[interface_name] = extended_attributes
|
| -
|
| - # Record global constructors
|
| - if (not is_callback_interface_from_idl(idl_file_contents) and
|
| - 'NoInterfaceObject' not in extended_attributes):
|
| - global_contexts = extended_attributes.get('GlobalContext', 'Window').split('&')
|
| - new_constructor_list = generate_constructor_attribute_list(interface_name, extended_attributes)
|
| - for global_object in global_contexts:
|
| - global_constructors[global_object].extend(new_constructor_list)
|
| -
|
| - # Record parents
|
| parent = get_parent_interface(idl_file_contents)
|
| if parent:
|
| parent_interfaces[interface_name] = parent
|
|
|
|
|
| -def record_extended_attributes(idl_filename):
|
| - interface_name, _ = os.path.splitext(os.path.basename(idl_filename))
|
| - full_path = os.path.realpath(idl_filename)
|
| - idl_file_contents = get_file_contents(full_path)
|
| - extended_attributes = get_interface_extended_attributes_from_idl(idl_file_contents)
|
| - extended_attributes_by_interface[interface_name] = extended_attributes
|
| -
|
| -
|
| -def generate_ancestors_and_inherited_extended_attributes(interface_name):
|
| +def compute_inheritance_info(interface_name):
|
| + """Computes inheritance information, namely ancestors and inherited extended attributes."""
|
| interface_info = interfaces_info[interface_name]
|
| interface_extended_attributes = extended_attributes_by_interface[interface_name]
|
| inherited_extended_attributes = dict(
|
| @@ -445,8 +294,8 @@ def generate_ancestors_and_inherited_extended_attributes(interface_name):
|
| interface_info['ancestors'] = ancestors
|
| for ancestor in ancestors:
|
| # Extended attributes are missing if an ancestor is an interface that
|
| - # we're not processing, notably real IDL files if only processing test
|
| - # IDL files, or generated support files.
|
| + # we're not processing, namely real IDL files if only processing test
|
| + # IDL files.
|
| ancestor_extended_attributes = extended_attributes_by_interface.get(ancestor, {})
|
| inherited_extended_attributes.update(dict(
|
| (key, value)
|
| @@ -456,39 +305,18 @@ def generate_ancestors_and_inherited_extended_attributes(interface_name):
|
| interface_info['inherited_extended_attributes'] = inherited_extended_attributes
|
|
|
|
|
| -def parse_idl_files(idl_files, global_constructors_filenames):
|
| - """Compute dependencies between IDL files, and return constructors on global objects.
|
| -
|
| - Primary effect is computing info about main interfaces, stored in global
|
| - interfaces_info.
|
| - The keys are the interfaces for which bindings are generated;
|
| - this does not include interfaces implemented by another interface.
|
| +def compute_interfaces_info(idl_files):
|
| + """Compute information about IDL files.
|
|
|
| - Returns:
|
| - global_constructors:
|
| - dict of global objects -> list of constructors on that object
|
| + Information is stored in global interfaces_info.
|
| """
|
| - global_constructors = dict([
|
| - (global_object, [])
|
| - for global_object in global_constructors_filenames])
|
| -
|
| - # Generate dependencies, and (for main IDL files), record
|
| - # global_constructors and extended_attributes_by_interface.
|
| + # Compute information for individual files
|
| for idl_filename in idl_files:
|
| - # Test skips partial interfaces
|
| - if generate_dependencies(idl_filename):
|
| - record_global_constructors_and_extended_attributes(idl_filename, global_constructors)
|
| + compute_individual_info(idl_filename)
|
|
|
| + # Once all individual files handled, can compute inheritance information
|
| for interface_name in interfaces_info:
|
| - generate_ancestors_and_inherited_extended_attributes(interface_name)
|
| -
|
| - # Add constructors on global objects to partial interfaces
|
| - # These are all partial interfaces, but the files are dynamically generated,
|
| - # so they need to be handled separately from static partial interfaces.
|
| - for global_object, constructor_filename in global_constructors_filenames.iteritems():
|
| - if global_object in interfaces_info:
|
| - # No include path needed, as already included in the header file
|
| - add_paths_to_partials_dict(global_object, constructor_filename)
|
| + compute_inheritance_info(interface_name)
|
|
|
| # An IDL file's dependencies are partial interface files that extend it,
|
| # and files for other interfaces that this interfaces implements.
|
| @@ -517,8 +345,6 @@ def parse_idl_files(idl_files, global_constructors_filenames):
|
| partial_interfaces_include_paths +
|
| implemented_interfaces_include_paths)
|
|
|
| - return global_constructors
|
| -
|
|
|
| ################################################################################
|
|
|
| @@ -535,23 +361,11 @@ def main():
|
| idl_files.extend(args)
|
|
|
| only_if_changed = options.write_file_only_if_changed
|
| - global_constructors_filenames = {
|
| - 'Window': options.window_constructors_file,
|
| - 'WorkerGlobalScope': options.workerglobalscope_constructors_file,
|
| - 'SharedWorkerGlobalScope': options.sharedworkerglobalscope_constructors_file,
|
| - 'DedicatedWorkerGlobalScope': options.dedicatedworkerglobalscope_constructors_file,
|
| - 'ServiceWorkerGlobalScope': options.serviceworkerglobalscope_constructors_file,
|
| - }
|
| -
|
| - global_constructors = parse_idl_files(idl_files, global_constructors_filenames)
|
| -
|
| - write_dependencies_file(options.interface_dependencies_file, only_if_changed)
|
| + compute_interfaces_info(idl_files)
|
| write_pickle_file(options.interfaces_info_file, interfaces_info, only_if_changed)
|
| - for interface_name, filename in global_constructors_filenames.iteritems():
|
| - if interface_name in interfaces_info:
|
| - write_global_constructors_partial_interface(interface_name, filename, global_constructors[interface_name], only_if_changed)
|
| + write_dependencies_file(options.interface_dependencies_file, only_if_changed)
|
| write_event_names_file(options.event_names_file, only_if_changed)
|
|
|
|
|
| if __name__ == '__main__':
|
| - main()
|
| + sys.exit(main())
|
|
|