| Index: Source/bindings/scripts/interface_merger.py
|
| diff --git a/Source/bindings/scripts/interface_merger.py b/Source/bindings/scripts/interface_merger.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..3069c18270bb8ab8587c1bd17cf73ad2f8409dde
|
| --- /dev/null
|
| +++ b/Source/bindings/scripts/interface_merger.py
|
| @@ -0,0 +1,155 @@
|
| +#!/usr/bin/python
|
| +# Copyright (C) 2013 Google Inc. All rights reserved.
|
| +#
|
| +# Redistribution and use in source and binary forms, with or without
|
| +# modification, are permitted provided that the following conditions are
|
| +# met:
|
| +#
|
| +# * Redistributions of source code must retain the above copyright
|
| +# notice, this list of conditions and the following disclaimer.
|
| +# * Redistributions in binary form must reproduce the above
|
| +# copyright notice, this list of conditions and the following disclaimer
|
| +# in the documentation and/or other materials provided with the
|
| +# distribution.
|
| +# * Neither the name of Google Inc. nor the names of its
|
| +# contributors may be used to endorse or promote products derived from
|
| +# this software without specific prior written permission.
|
| +#
|
| +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| +
|
| +# import blink_idl_parser # FIXME: not checked in yet
|
| +import blink_idl_parser_perl
|
| +import os.path
|
| +import shlex
|
| +
|
| +
|
| +class IdlNotFoundError(Exception):
|
| + # Raised if can't find IDL in dependencies file or additional files list
|
| + pass
|
| +
|
| +
|
| +class InterfaceNotFoundError(Exception):
|
| + # Raised if (partial) interface not found in target
|
| + pass
|
| +
|
| +
|
| +class InvalidDependencyError(Exception):
|
| + # Raised if a supplementary file is not in fact a dependency
|
| + pass
|
| +
|
| +
|
| +def parse_file(target_idl_file, defines, preprocessor, use_perl_parser, verbose):
|
| + """Wrapper function so can switch parser between Perl and Python"""
|
| + if use_perl_parser:
|
| + return blink_idl_parser_perl.parse_file(target_idl_file, defines, preprocessor)
|
| + else:
|
| + if verbose: # otherwise 'verbose' not used
|
| + print 'Not implemented yet'
|
| + # parser = BlinkIDLParser(verbose=verbose)
|
| + # # FIXME: actually "preprocess and parse"
|
| + # return parser.Parse(target_idl_file, defines, preprocessor)
|
| +
|
| +
|
| +def compute_supplementary_idl_files(target_idl_basename, supplementary_dependencies_filename, additional_idl_files_string):
|
| + # The format of a supplemental dependency file:
|
| + #
|
| + # DOMWindow.idl P.idl Q.idl R.idl
|
| + # Document.idl S.idl
|
| + # Event.idl
|
| + # ...
|
| + #
|
| + # The above indicates that DOMWindow.idl is supplemented by P.idl, Q.idl and R.idl,
|
| + # Document.idl is supplemented by S.idl, and Event.idl is supplemented by no IDLs.
|
| + # The IDL that supplements another IDL (e.g. P.idl) never appears in the dependency file.
|
| + supplementary_idl_files = None
|
| + with open(supplementary_dependencies_filename) as supplementary_dependencies_file:
|
| + for line in supplementary_dependencies_file:
|
| + idl_filename, _, dependency_files = line.partition(' ')
|
| + if os.path.basename(idl_filename) == target_idl_basename:
|
| + supplementary_idl_files = dependency_files.split()
|
| +
|
| + if supplementary_idl_files is None:
|
| + # additional_idl_fpiles is list of IDL files which should not be included in
|
| + # DerivedSources*.cpp (i.e. they are not described in the supplemental
|
| + # dependency file) but should generate .h and .cpp files.
|
| + additional_idl_files_list = shlex.split(additional_idl_files_string)
|
| + for additional_idl_filename in additional_idl_files_list:
|
| + if os.path.basename(additional_idl_filename) == target_idl_basename:
|
| + break
|
| + else:
|
| + raise IdlNotFoundError
|
| + return supplementary_idl_files
|
| +
|
| +
|
| +def merge_partial_interface(target_document_interfaces, partial_interface, target_interface_name, interface_name):
|
| + """Merge partial_interface into target_document_interfaces.
|
| +
|
| + No return: modifies target_document_interfaces in place.
|
| + """
|
| + # FIXME: more elegant would be if 'interfaces' were a dict, rather
|
| + # than AST, so we could skip the search and just do:
|
| + # target_data_node = target_document['interfaces'][target_interface_name]
|
| + for target_interface in target_document_interfaces:
|
| + if target_interface['name'] == target_interface_name:
|
| + target_data_node = target_interface
|
| + break
|
| + else:
|
| + raise InterfaceNotFoundError('Could not find interface "{target_interface_name}" in {target_interface_name}.idl.'.format(**locals))
|
| +
|
| + for attribute in partial_interface['attributes']:
|
| + attribute['signature']['extendedAttributes']['ImplementedBy'] = interface_name
|
| + # Add interface-wide extended attributes to each attribute.
|
| + for extended_attribute_name, extended_attribute_value in partial_interface['extendedAttributes'].iteritems():
|
| + attribute['signature']['extendedAttributes'][extended_attribute_name] = extended_attribute_value
|
| + target_data_node['attributes'].append(attribute)
|
| +
|
| + for function in partial_interface['functions']:
|
| + function['signature']['extendedAttributes']['ImplementedBy'] = interface_name
|
| + # Add interface-wide extended attributes to each method.
|
| + for extended_attribute_name, extended_attribute_value in partial_interface['extendedAttributes'].iteritems():
|
| + function['signature']['extendedAttributes'][extended_attribute_name] = extended_attribute_value
|
| + target_data_node['functions'].append(function)
|
| +
|
| + for constant in partial_interface['constants']:
|
| + constant['extendedAttributes']['ImplementedBy'] = interface_name
|
| + # Add interface-wide extended attributes to each constant.
|
| + for extended_attribute_name, extended_attribute_value in partial_interface['extendedAttributes'].iteritems():
|
| + constant['extendedAttributes'][extended_attribute_name] = extended_attribute_value
|
| + target_data_node['constants'].append(constant)
|
| +
|
| + # Replace interface with augmented one
|
| + for i, target_interface in enumerate(target_document_interfaces):
|
| + if target_interface['name'] == target_interface_name:
|
| + target_document_interfaces[i] = target_data_node
|
| +
|
| +
|
| +def merge_partial_interfaces(target_document, target_interface_name, target_idl_file, supplementary_idl_files, options):
|
| + """Merge partial interfaces in supplementary_idl_files into target_document.
|
| +
|
| + No return: modifies target_document in place.
|
| + """
|
| + for idl_file in supplementary_idl_files:
|
| + if idl_file == target_idl_file:
|
| + # FIXME: this should never happen; it's a circular dependency!
|
| + continue
|
| +
|
| + interface_name, _ = os.path.splitext(os.path.basename(idl_file))
|
| + document = parse_file(idl_file, options.defines, options.preprocessor, options.perl_parser, options.verbose)
|
| +
|
| + for interface in document['interfaces']:
|
| + # Supplementary files must contain *only* partial interfaces
|
| + # for the single target interface
|
| + if not(interface['isPartial'] and interface['name'] == target_interface_name):
|
| + raise InvalidDependencyError('%(idl_file) is not a supplementary dependency of %(target_idl_file). There maybe a bug in the the supplementary dependency generator (preprocess_idls.py).')
|
| +
|
| + merge_partial_interface(target_document['interfaces'], interface, target_interface_name, interface_name)
|
|
|