def extract_meta_data(file_paths): """Extracts conditional and interface name from each IDL file.""" meta_data_list = [] for file_path in file_paths: if not file_path.endswith('.idl'): print 'WARNING: non-IDL file passed: "%s"' % file_path continue if not os.path.exists(file_path): print 'WARNING: file not found: "%s"' % file_path continue idl_file_contents = get_file_contents(file_path) if not should_generate_impl_file_from_idl(idl_file_contents): continue # Extract interface name from file name interface_name = idl_filename_to_interface_name(file_path) meta_data = { 'conditional': extract_conditional(idl_file_contents), 'name': interface_name, } meta_data_list.append(meta_data) return meta_data_list
def idl_file_to_global_names(idl_filename): """Returns global names, if any, for an IDL file. If the [Global] or [PrimaryGlobal] extended attribute is declared with an identifier list argument, then those identifiers are the interface's global names; otherwise, the interface has a single global name, which is the interface's identifier (http://heycam.github.io/webidl/#Global). """ 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) interface_name = get_first_interface_name_from_idl(idl_file_contents) global_keys = GLOBAL_EXTENDED_ATTRIBUTES.intersection( extended_attributes.iterkeys()) if not global_keys: return if len(global_keys) > 1: raise ValueError( 'The [Global] and [PrimaryGlobal] extended attributes ' 'MUST NOT be declared on the same interface.') global_key = next(iter(global_keys)) global_value = extended_attributes[global_key] if global_value: return global_value.strip('()').split(',') return [interface_name]
def record_global_constructors(idl_filename): interface_name = idl_filename_to_interface_name(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) # An interface property is produced for every non-callback interface # that does not have [NoInterfaceObject]. # Callback interfaces with constants also have interface properties, # but there are none of these in Blink. # http://heycam.github.io/webidl/#es-interfaces if (is_callback_interface_from_idl(idl_file_contents) or 'NoInterfaceObject' in extended_attributes): return exposed_arguments = get_interface_exposed_arguments(idl_file_contents) if exposed_arguments: # Exposed(Arguments) case for argument in exposed_arguments: if 'RuntimeEnabled' in extended_attributes: raise ValueError('RuntimeEnabled should not be used with Exposed(Arguments)') attributes = extended_attributes.copy() attributes['RuntimeEnabled'] = argument['runtime_enabled'] new_constructors_list = generate_global_constructors_list(interface_name, attributes) global_name_to_constructors[argument['exposed']].extend(new_constructors_list) else: # Exposed=env or Exposed=(env1,...) case exposed_global_names = extended_attributes.get('Exposed', 'Window').strip('()').split(',') new_constructors_list = generate_global_constructors_list(interface_name, extended_attributes) for name in exposed_global_names: global_name_to_constructors[name].extend(new_constructors_list)
def idl_file_to_global_names(idl_filename): """Returns global names, if any, for an IDL file. If the [Global] or [PrimaryGlobal] extended attribute is declared with an identifier list argument, then those identifiers are the interface's global names; otherwise, the interface has a single global name, which is the interface's identifier (http://heycam.github.io/webidl/#Global). """ interface_name = idl_filename_to_interface_name(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) global_keys = GLOBAL_EXTENDED_ATTRIBUTES.intersection( extended_attributes.iterkeys()) if not global_keys: return if len(global_keys) > 1: raise ValueError( 'The [Global] and [PrimaryGlobal] extended attributes ' 'MUST NOT be declared on the same interface.') global_key = next(iter(global_keys)) global_value = extended_attributes[global_key] if global_value: # FIXME: In spec names are comma-separated, which makes parsing very # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959). return global_value.split('&') return [interface_name]
def record_global_constructors(idl_filename): interface_name = idl_filename_to_interface_name(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) # An interface property is produced for every non-callback interface # that does not have [NoInterfaceObject]. # Callback interfaces with constants also have interface properties, # but there are none of these in Blink. # http://heycam.github.io/webidl/#es-interfaces if (is_callback_interface_from_idl(idl_file_contents) or 'NoInterfaceObject' in extended_attributes): return # The [Exposed] extended attribute MUST take an identifier list. Each # identifier in the list MUST be a global name. An interface or interface # member the extended attribute applies to will be exposed only on objects # associated with ECMAScript global environments whose global object # implements an interface that has a matching global name. exposed_global_names = extended_attributes.get( 'Exposed', 'Window').strip('()').split(',') new_constructors_list = generate_global_constructors_list( interface_name, extended_attributes) for exposed_global_name in exposed_global_names: global_name_to_constructors[exposed_global_name].extend( new_constructors_list)
def record_global_constructors(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) # An interface property is produced for every non-callback interface # that does not have [NoInterfaceObject]. # Callback interfaces with constants also have interface properties, # but there are none of these in Blink. # http://heycam.github.io/webidl/#es-interfaces if (is_callback_interface_from_idl(idl_file_contents) or 'NoInterfaceObject' in extended_attributes): return # Check if interface has [Global] / [PrimaryGlobal] extended attributes. interface_name_to_global_names[interface_name] = interface_to_global_names( interface_name, extended_attributes) # The [Exposed] extended attribute MUST take an identifier list. Each # identifier in the list MUST be a global name. An interface or interface # member the extended attribute applies to will be exposed only on objects # associated with ECMAScript global environments whose global object # implements an interface that has a matching global name. # FIXME: In spec names are comma-separated, but that makes parsing very # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959). exposed_global_names = extended_attributes.get('Exposed', 'Window').split('&') new_constructors_list = generate_global_constructors_list( interface_name, extended_attributes) for exposed_global_name in exposed_global_names: global_name_to_constructors[exposed_global_name].extend( new_constructors_list)
def record_global_constructors(idl_filename): interface_name = idl_filename_to_interface_name(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) # An interface property is produced for every non-callback interface # that does not have [NoInterfaceObject]. # Callback interfaces with constants also have interface properties, # but there are none of these in Blink. # http://heycam.github.io/webidl/#es-interfaces if (is_callback_interface_from_idl(idl_file_contents) or 'NoInterfaceObject' in extended_attributes): return # The [Exposed] extended attribute MUST take an identifier list. Each # identifier in the list MUST be a global name. An interface or interface # member the extended attribute applies to will be exposed only on objects # associated with ECMAScript global environments whose global object # implements an interface that has a matching global name. # FIXME: In spec names are comma-separated, but that makes parsing very # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959). exposed_global_names = extended_attributes.get('Exposed', 'Window').split('&') new_constructors_list = generate_global_constructors_list(interface_name, extended_attributes) for exposed_global_name in exposed_global_names: global_name_to_constructors[exposed_global_name].extend(new_constructors_list)
def record_global_constructors(idl_filename): interface_name = idl_filename_to_interface_name(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) # An interface property is produced for every non-callback interface # that does not have [NoInterfaceObject]. # Callback interfaces with constants also have interface properties, # but there are none of these in Blink. # http://heycam.github.io/webidl/#es-interfaces if ((not should_generate_impl_file_from_idl(idl_file_contents)) or is_callback_interface_from_idl(idl_file_contents) or 'NoInterfaceObject' in extended_attributes): return exposed_arguments = get_interface_exposed_arguments(idl_file_contents) if exposed_arguments: # Exposed(Arguments) case for argument in exposed_arguments: if 'RuntimeEnabled' in extended_attributes: raise ValueError('RuntimeEnabled should not be used with Exposed(Arguments)') attributes = extended_attributes.copy() attributes['RuntimeEnabled'] = argument['runtime_enabled'] new_constructors_list = generate_global_constructors_list(interface_name, attributes) global_name_to_constructors[argument['exposed']].extend(new_constructors_list) else: # Exposed=env or Exposed=(env1,...) case exposed_global_names = extended_attributes.get('Exposed', 'Window').strip('()').split(',') new_constructors_list = generate_global_constructors_list(interface_name, extended_attributes) for name in exposed_global_names: global_name_to_constructors[name].extend(new_constructors_list)
def compute_info_individual(idl_filename, component_dir): 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) implemented_as = extended_attributes.get('ImplementedAs') this_include_path = include_path(idl_filename, component_dir, implemented_as) # Handle partial interfaces 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 # If not a partial interface, the basename is the interface name interface_name = idl_filename_to_interface_name(idl_filename) # 'implements' statements can be included in either the file for the # implement*ing* interface (lhs of 'implements') or implement*ed* interface # (rhs of 'implements'). Store both for now, then merge to implement*ing* # interface later. left_interfaces, right_interfaces = get_implements_from_idl( idl_file_contents, interface_name) interfaces_info[interface_name] = { 'component_dir': component_dir, 'extended_attributes': extended_attributes, 'full_path': full_path, 'implemented_as': implemented_as, 'implemented_by_interfaces': left_interfaces, # private, merged to next 'implements_interfaces': right_interfaces, 'include_path': this_include_path, # FIXME: temporary private field, while removing old treatement of # 'implements': http://crbug.com/360435 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterface' in extended_attributes, 'is_callback_interface': is_callback_interface_from_idl(idl_file_contents), 'parent': get_parent_interface(idl_file_contents), # Interfaces that are referenced (used as types) and that we introspect # during code generation (beyond interface-level data ([ImplementedAs], # is_callback_interface, ancestors, and inherited extended attributes): # deep dependencies. # These cause rebuilds of referrers, due to the dependency, so these # should be minimized; currently only targets of [PutForwards]. 'referenced_interfaces': get_put_forward_interfaces_from_idl(idl_file_contents), }
def idl_file_to_global_names(idl_filename): """Returns global names, if any, for an IDL file. If the [Global] or [PrimaryGlobal] extended attribute is declared with an identifier list argument, then those identifiers are the interface's global names; otherwise, the interface has a single global name, which is the interface's identifier (http://heycam.github.io/webidl/#Global). """ interface_name = idl_filename_to_interface_name(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) global_keys = GLOBAL_EXTENDED_ATTRIBUTES.intersection( extended_attributes.iterkeys()) if not global_keys: return if len(global_keys) > 1: raise ValueError('The [Global] and [PrimaryGlobal] extended attributes ' 'MUST NOT be declared on the same interface.') global_key = next(iter(global_keys)) global_value = extended_attributes[global_key] if global_value: return global_value.strip('()').split(',') return [interface_name]
def idl_file_to_global_names(idl_filename): """Returns global names, if any, for an IDL file. If the [Global] or [PrimaryGlobal] extended attribute is declared with an identifier list argument, then those identifiers are the interface's global names; otherwise, the interface has a single global name, which is the interface's identifier (http://heycam.github.io/webidl/#Global). """ interface_name = idl_filename_to_interface_name(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) global_keys = GLOBAL_EXTENDED_ATTRIBUTES.intersection(extended_attributes.iterkeys()) if not global_keys: return if len(global_keys) > 1: raise ValueError( "The [Global] and [PrimaryGlobal] extended attributes " "MUST NOT be declared on the same interface." ) global_key = next(iter(global_keys)) global_value = extended_attributes[global_key] if global_value: # FIXME: In spec names are comma-separated, which makes parsing very # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959). return global_value.split("&") return [interface_name]
def extract_meta_data(file_paths): """Extracts interface name from each IDL file.""" meta_data_list = [] for file_path in file_paths: if not file_path.endswith('.idl'): print 'WARNING: non-IDL file passed: "%s"' % file_path continue if not os.path.exists(file_path): print 'WARNING: file not found: "%s"' % file_path continue idl_file_contents = get_file_contents(file_path) if not should_generate_impl_file_from_idl(idl_file_contents): continue # Extract interface name from file name interface_name = idl_filename_to_interface_name(file_path) meta_data = { 'name': interface_name, } meta_data_list.append(meta_data) return meta_data_list
def idl_files_to_interface_name_global_names(idl_files): """Yields pairs (interface_name, global_names) found in IDL files.""" for idl_filename in idl_files: interface_name = get_first_interface_name_from_idl( get_file_contents(idl_filename)) global_names = idl_file_to_global_names(idl_filename) if global_names: yield interface_name, global_names
def interface_line(full_path): relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, source_dir)) relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep) idl_file_contents = get_file_contents(full_path) extended_attributes = get_interface_extended_attributes_from_idl(idl_file_contents) extended_attributes_list = [ (name, extended_attributes[name]) for name in EXPORTED_EXTENDED_ATTRIBUTES if name in extended_attributes] return (relative_path_posix, extended_attributes_list)
def interface_line(full_path): relative_dir_local = os.path.dirname( os.path.relpath(full_path, REPO_ROOT_DIR)) relative_dir_posix = relative_dir_local.replace(os.sep, posixpath.sep) idl_file_contents = get_file_contents(full_path) interface_name = get_first_interface_name_from_idl(idl_file_contents) extended_attributes = get_interface_extended_attributes_from_idl( idl_file_contents) extended_attributes_list = [(name, extended_attributes[name]) for name in EXPORTED_EXTENDED_ATTRIBUTES if name in extended_attributes] return (relative_dir_posix, interface_name, extended_attributes_list)
def compute_individual_info(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) implemented_as = extended_attributes.get("ImplementedAs") this_include_path = include_path(idl_filename, implemented_as) # Handle partial interfaces 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 # If not a partial interface, the basename is the interface name interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) # 'implements' statements can be included in either the file for the # implement*ing* interface (lhs of 'implements') or implement*ed* interface # (rhs of 'implements'). Store both for now, then merge to implement*ing* # interface later. left_interfaces, right_interfaces = get_implements_from_idl(idl_file_contents, interface_name) interfaces_info[interface_name] = { "full_path": full_path, "implemented_as": implemented_as, "implemented_by_interfaces": left_interfaces, # private, merged to next "implements_interfaces": right_interfaces, "include_path": this_include_path, # FIXME: temporary private field, while removing old treatement of # 'implements': http://crbug.com/360435 "is_legacy_treat_as_partial_interface": "LegacyTreatAsPartialInterface" in extended_attributes, "is_callback_interface": is_callback_interface_from_idl(idl_file_contents), # Interfaces that are referenced (used as types) and that we introspect # during code generation (beyond interface-level data ([ImplementedAs], # is_callback_interface, ancestors, and inherited extended attributes): # deep dependencies. # These cause rebuilds of referrers, due to the dependency, so these # should be minimized; currently only targets of [PutForwards]. "referenced_interfaces": get_put_forward_interfaces_from_idl(idl_file_contents), } # Record inheritance information inherited_extended_attributes_by_interface[interface_name] = dict( (key, value) for key, value in extended_attributes.iteritems() if key in INHERITED_EXTENDED_ATTRIBUTES ) parent = get_parent_interface(idl_file_contents) if parent: parent_interfaces[interface_name] = parent
def interface_line(interface_name): full_path = interfaces_info[interface_name]['full_path'] relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, source_dir)) relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep) idl_file_contents = get_file_contents(full_path) extended_attributes = get_interface_extended_attributes_from_idl(idl_file_contents) extended_attributes_list = [ extended_attribute_string(name, extended_attributes[name]) for name in EXPORTED_EXTENDED_ATTRIBUTES if name in extended_attributes] return '%s %s\n' % (relative_path_posix, ', '.join(extended_attributes_list))
def compute_info_individual(idl_filename, component_dir): 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) implemented_as = extended_attributes.get('ImplementedAs') relative_dir = relative_dir_posix(idl_filename) this_include_path = None if 'NoImplHeader' in extended_attributes else include_path(idl_filename, implemented_as) # Handle partial interfaces 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 # If not a partial interface, the basename is the interface name interface_name = idl_filename_to_interface_name(idl_filename) # 'implements' statements can be included in either the file for the # implement*ing* interface (lhs of 'implements') or implement*ed* interface # (rhs of 'implements'). Store both for now, then merge to implement*ing* # interface later. left_interfaces, right_interfaces = get_implements_from_idl(idl_file_contents, interface_name) interfaces_info[interface_name] = { 'component_dir': component_dir, 'extended_attributes': extended_attributes, 'full_path': full_path, 'implemented_as': implemented_as, 'implemented_by_interfaces': left_interfaces, # private, merged to next 'implements_interfaces': right_interfaces, 'include_path': this_include_path, 'is_callback_interface': is_callback_interface_from_idl(idl_file_contents), 'is_dictionary': is_dictionary_from_idl(idl_file_contents), # FIXME: temporary private field, while removing old treatement of # 'implements': http://crbug.com/360435 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterface' in extended_attributes, 'parent': get_parent_interface(idl_file_contents), # Interfaces that are referenced (used as types) and that we introspect # during code generation (beyond interface-level data ([ImplementedAs], # is_callback_interface, ancestors, and inherited extended attributes): # deep dependencies. # These cause rebuilds of referrers, due to the dependency, so these # should be minimized; currently only targets of [PutForwards]. 'referenced_interfaces': get_put_forward_interfaces_from_idl(idl_file_contents), 'relative_dir': relative_dir, }
def record_global_constructors(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) # An interface property is produced for every non-callback interface # that does not have [NoInterfaceObject]. # Callback interfaces with constants also have interface properties, # but there are none of these in Blink. # http://heycam.github.io/webidl/#es-interfaces if (is_callback_interface_from_idl(idl_file_contents) or 'NoInterfaceObject' in extended_attributes): return global_contexts = extended_attributes.get('GlobalContext', 'Window').split('&') new_constructors_list = generate_global_constructors_list(interface_name, extended_attributes) for interface_name in global_contexts: global_objects[interface_name]['constructors'].extend(new_constructors_list)
def compute_individual_info(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) implemented_as = extended_attributes.get('ImplementedAs') this_include_path = (include_path(idl_filename, implemented_as) if 'ImplementedInBaseClass' not in extended_attributes else None) # Handle partial interfaces 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 # If not a partial interface, the basename is the interface name interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) interfaces_info[interface_name] = { 'full_path': full_path, 'implemented_as': implemented_as, 'implements_interfaces': get_implemented_interfaces_from_idl(idl_file_contents, interface_name), 'include_path': this_include_path, 'is_callback_interface': is_callback_interface_from_idl(idl_file_contents), # Interfaces that are referenced (used as types) and that we introspect # during code generation (beyond interface-level data ([ImplementedAs], # is_callback_interface, ancestors, and inherited extended attributes): # deep dependencies. # These cause rebuilds of referrers, due to the dependency, so these # should be minimized; currently only targets of [PutForwards]. 'referenced_interfaces': get_put_forward_interfaces_from_idl(idl_file_contents), } # Record inheritance information inherited_extended_attributes_by_interface[interface_name] = dict( (key, value) for key, value in extended_attributes.iteritems() if key in INHERITED_EXTENDED_ATTRIBUTES) parent = get_parent_interface(idl_file_contents) if parent: parent_interfaces[interface_name] = parent
def idl_file_to_global_names(idl_filename): """Returns global names, if any, for an IDL file. The identifier argument or identifier list argument the [Global] extended attribute is declared with define the interface's global names (http://heycam.github.io/webidl/#Global). """ 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) interface_name = get_first_interface_name_from_idl(idl_file_contents) if 'Global' not in extended_attributes: return global_value = extended_attributes['Global'] if not global_value: raise ValueError( '[Global] must take an indentifier or an identifier list.\n' + full_path) return map(str.strip, global_value.strip('()').split(','))
def record_global_constructors(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) interface_name = get_first_interface_name_from_idl(idl_file_contents) # An interface property is produced for every non-callback interface # that does not have [NoInterfaceObject]. # http://heycam.github.io/webidl/#es-interfaces if (not should_generate_impl_file_from_idl(idl_file_contents) or is_non_legacy_callback_interface_from_idl(idl_file_contents) or is_interface_mixin_from_idl(idl_file_contents) or 'NoInterfaceObject' in extended_attributes): return exposed_arguments = get_interface_exposed_arguments(idl_file_contents) if exposed_arguments: # Exposed(Arguments) case for argument in exposed_arguments: if 'RuntimeEnabled' in extended_attributes: raise ValueError( 'RuntimeEnabled should not be used with Exposed(Arguments)' ) attributes = extended_attributes.copy() attributes['RuntimeEnabled'] = argument['runtime_enabled'] new_constructors_list = generate_global_constructors_list( interface_name, attributes) global_name_to_constructors[argument['exposed']].extend( new_constructors_list) elif 'Exposed' in extended_attributes: # Exposed=env or Exposed=(env1,...) case exposed_value = extended_attributes.get('Exposed') exposed_global_names = map(str.strip, exposed_value.strip('()').split(',')) new_constructors_list = generate_global_constructors_list( interface_name, extended_attributes) for name in exposed_global_names: global_name_to_constructors[name].extend(new_constructors_list)
def bindings_tests(output_directory, verbose, suppress_diff): executive = Executive() def list_files(directory): files = [] for component in os.listdir(directory): if component not in COMPONENT_DIRECTORY: continue directory_with_component = os.path.join(directory, component) for filename in os.listdir(directory_with_component): files.append(os.path.join(directory_with_component, filename)) return files def diff(filename1, filename2): # Python's difflib module is too slow, especially on long output, so # run external diff(1) command cmd = [ 'diff', '-u', # unified format '-N', # treat absent files as empty filename1, filename2 ] # Return output and don't raise exception, even though diff(1) has # non-zero exit if files differ. return executive.run_command(cmd, error_handler=lambda x: None) def is_cache_file(filename): return filename.endswith('.cache') def delete_cache_files(): # FIXME: Instead of deleting cache files, don't generate them. cache_files = [ path for path in list_files(output_directory) if is_cache_file(os.path.basename(path)) ] for cache_file in cache_files: os.remove(cache_file) def identical_file(reference_filename, output_filename): reference_basename = os.path.basename(reference_filename) if not os.path.isfile(reference_filename): print 'Missing reference file!' print '(if adding new test, update reference files)' print reference_basename print return False if not filecmp.cmp(reference_filename, output_filename): # cmp is much faster than diff, and usual case is "no difference", # so only run diff if cmp detects a difference print 'FAIL: %s' % reference_basename if not suppress_diff: print diff(reference_filename, output_filename) return False if verbose: print 'PASS: %s' % reference_basename return True def identical_output_files(output_files): reference_files = [ os.path.join(REFERENCE_DIRECTORY, os.path.relpath(path, output_directory)) for path in output_files ] return all([ identical_file(reference_filename, output_filename) for (reference_filename, output_filename) in zip(reference_files, output_files) ]) def no_excess_files(output_files): generated_files = set( [os.path.relpath(path, output_directory) for path in output_files]) excess_files = [] for path in list_files(REFERENCE_DIRECTORY): relpath = os.path.relpath(path, REFERENCE_DIRECTORY) # Ignore backup files made by a VCS. if os.path.splitext(relpath)[1] == '.orig': continue if relpath not in generated_files: excess_files.append(relpath) if excess_files: print( 'Excess reference files! ' '(probably cruft from renaming or deleting):\n' + '\n'.join(excess_files)) return False return True try: generate_interface_dependencies() for component in COMPONENT_DIRECTORY: output_dir = os.path.join(output_directory, component) if not os.path.exists(output_dir): os.makedirs(output_dir) options = IdlCompilerOptions(output_directory=output_dir, impl_output_directory=output_dir, cache_directory=None, target_component=component) if component == 'core': partial_interface_output_dir = os.path.join( output_directory, 'modules') if not os.path.exists(partial_interface_output_dir): os.makedirs(partial_interface_output_dir) partial_interface_options = IdlCompilerOptions( output_directory=partial_interface_output_dir, impl_output_directory=None, cache_directory=None, target_component='modules') idl_filenames = [] dictionary_impl_filenames = [] partial_interface_filenames = [] input_directory = os.path.join(TEST_INPUT_DIRECTORY, component) for filename in os.listdir(input_directory): if (filename.endswith('.idl') and # Dependencies aren't built # (they are used by the dependent) filename not in DEPENDENCY_IDL_FILES): idl_path = os.path.realpath( os.path.join(input_directory, filename)) idl_filenames.append(idl_path) idl_basename = os.path.basename(idl_path) name_from_basename, _ = os.path.splitext(idl_basename) definition_name = get_first_interface_name_from_idl( get_file_contents(idl_path)) is_partial_interface_idl = to_snake_case( definition_name) != name_from_basename if not is_partial_interface_idl: interface_info = interfaces_info[definition_name] if interface_info['is_dictionary']: dictionary_impl_filenames.append(idl_path) if component == 'core' and interface_info[ 'dependencies_other_component_full_paths']: partial_interface_filenames.append(idl_path) info_provider = component_info_providers[component] partial_interface_info_provider = component_info_providers[ 'modules'] generate_union_type_containers(CodeGeneratorUnionType, info_provider, options) generate_callback_function_impl(CodeGeneratorCallbackFunction, info_provider, options) generate_bindings(CodeGeneratorV8, info_provider, options, idl_filenames) generate_bindings(CodeGeneratorWebAgentAPI, info_provider, options, idl_filenames) generate_bindings(CodeGeneratorV8, partial_interface_info_provider, partial_interface_options, partial_interface_filenames) generate_dictionary_impl(CodeGeneratorDictionaryImpl, info_provider, options, dictionary_impl_filenames) generate_origin_trial_features(info_provider, options, [ filename for filename in idl_filenames if filename not in dictionary_impl_filenames ]) finally: delete_cache_files() # Detect all changes output_files = list_files(output_directory) passed = identical_output_files(output_files) passed &= no_excess_files(output_files) if passed: if verbose: print print PASS_MESSAGE return 0 print print FAIL_MESSAGE return 1
def bindings_tests(output_directory, verbose, suppress_diff): executive = Executive() def list_files(directory): if not os.path.isdir(directory): return [] files = [] for component in os.listdir(directory): if component not in COMPONENT_DIRECTORY: continue directory_with_component = os.path.join(directory, component) for filename in os.listdir(directory_with_component): files.append(os.path.join(directory_with_component, filename)) return files def diff(filename1, filename2): with open(filename1) as file1: file1_lines = file1.readlines() with open(filename2) as file2: file2_lines = file2.readlines() # Use Python's difflib module so that diffing works across platforms return ''.join(difflib.context_diff(file1_lines, file2_lines)) def is_cache_file(filename): return filename.endswith('.cache') def delete_cache_files(): # FIXME: Instead of deleting cache files, don't generate them. cache_files = [ path for path in list_files(output_directory) if is_cache_file(os.path.basename(path)) ] for cache_file in cache_files: os.remove(cache_file) def identical_file(reference_filename, output_filename): reference_basename = os.path.basename(reference_filename) if not os.path.isfile(reference_filename): print 'Missing reference file!' print '(if adding new test, update reference files)' print reference_basename print return False if not filecmp.cmp(reference_filename, output_filename): # cmp is much faster than diff, and usual case is "no difference", # so only run diff if cmp detects a difference print 'FAIL: %s' % reference_basename if not suppress_diff: print diff(reference_filename, output_filename) return False if verbose: print 'PASS: %s' % reference_basename return True def identical_output_files(output_files): reference_files = [ os.path.join(REFERENCE_DIRECTORY, os.path.relpath(path, output_directory)) for path in output_files ] return all([ identical_file(reference_filename, output_filename) for (reference_filename, output_filename) in zip(reference_files, output_files) ]) def no_excess_files(output_files): generated_files = set( [os.path.relpath(path, output_directory) for path in output_files]) excess_files = [] for path in list_files(REFERENCE_DIRECTORY): relpath = os.path.relpath(path, REFERENCE_DIRECTORY) # Ignore backup files made by a VCS. if os.path.splitext(relpath)[1] == '.orig': continue if relpath not in generated_files: excess_files.append(relpath) if excess_files: print( 'Excess reference files! ' '(probably cruft from renaming or deleting):\n' + '\n'.join(excess_files)) return False return True def make_runtime_features_dict(): input_filename = os.path.join(TEST_INPUT_DIRECTORY, 'runtime_enabled_features.json5') json5_file = Json5File.load_from_files([input_filename]) features_map = {} for feature in json5_file.name_dictionaries: features_map[str(feature['name'])] = { 'in_origin_trial': feature['in_origin_trial'] } return features_map try: generate_interface_dependencies(make_runtime_features_dict()) for component in COMPONENT_DIRECTORY: output_dir = os.path.join(output_directory, component) if not os.path.exists(output_dir): os.makedirs(output_dir) options = IdlCompilerOptions(output_directory=output_dir, impl_output_directory=output_dir, cache_directory=None, target_component=component) if component == 'core': partial_interface_output_dir = os.path.join( output_directory, 'modules') if not os.path.exists(partial_interface_output_dir): os.makedirs(partial_interface_output_dir) partial_interface_options = IdlCompilerOptions( output_directory=partial_interface_output_dir, impl_output_directory=None, cache_directory=None, target_component='modules') idl_filenames = [] dictionary_impl_filenames = [] partial_interface_filenames = [] input_directory = os.path.join(TEST_INPUT_DIRECTORY, component) for filename in os.listdir(input_directory): if (filename.endswith('.idl') and # Dependencies aren't built # (they are used by the dependent) filename not in DEPENDENCY_IDL_FILES): idl_path = os.path.realpath( os.path.join(input_directory, filename)) idl_filenames.append(idl_path) idl_basename = os.path.basename(idl_path) name_from_basename, _ = os.path.splitext(idl_basename) definition_name = get_first_interface_name_from_idl( get_file_contents(idl_path)) is_partial_interface_idl = to_snake_case( definition_name) != name_from_basename if not is_partial_interface_idl: interface_info = interfaces_info[definition_name] if interface_info['is_dictionary']: dictionary_impl_filenames.append(idl_path) if component == 'core' and interface_info[ 'dependencies_other_component_full_paths']: partial_interface_filenames.append(idl_path) info_provider = component_info_providers[component] partial_interface_info_provider = component_info_providers[ 'modules'] generate_union_type_containers(CodeGeneratorUnionType, info_provider, options) generate_callback_function_impl(CodeGeneratorCallbackFunction, info_provider, options) generate_bindings(CodeGeneratorV8, info_provider, options, idl_filenames) generate_bindings(CodeGeneratorV8, partial_interface_info_provider, partial_interface_options, partial_interface_filenames) generate_dictionary_impl(CodeGeneratorDictionaryImpl, info_provider, options, dictionary_impl_filenames) generate_origin_trial_features(info_provider, options, [ filename for filename in idl_filenames if filename not in dictionary_impl_filenames ]) finally: delete_cache_files() # Detect all changes output_files = list_files(output_directory) passed = identical_output_files(output_files) passed &= no_excess_files(output_files) if passed: if verbose: print print PASS_MESSAGE return 0 print print FAIL_MESSAGE return 1