def main(args): if len(args) <= 4: raise Exception('Expected at least 5 arguments.') component_dir = args[1] input_file_name = abs(args[2]) in_out_break_index = args.index('--') output_file_names = args[in_out_break_index + 1:] idl_file_names = read_idl_files_list_from_file(input_file_name, is_gyp_format=True) components = set( [idl_filename_to_component(filename) for filename in idl_file_names]) if len(components) != 1: raise Exception( 'Cannot aggregate generated codes in different components') aggregate_partial_interfaces = component_dir not in components files_meta_data = extract_meta_data(idl_file_names) total_partitions = len(output_file_names) for partition, file_name in enumerate(output_file_names): files_meta_data_this_partition = [ meta_data for meta_data in files_meta_data if hash(meta_data['name']) % total_partitions == partition ] file_contents = generate_content(component_dir, aggregate_partial_interfaces, files_meta_data_this_partition) write_content(file_contents, abs(file_name))
def main(args): if len(args) <= 4: raise Exception('Expected at least 5 arguments.') component_dir = args[1] input_file_name = abs(args[2]) in_out_break_index = args.index('--') output_file_names = args[in_out_break_index + 1:] with open(input_file_name) as input_file: file_names = sorted([os.path.realpath(line.rstrip('\n')) for line in input_file]) idl_file_names = [file_name for file_name in file_names if not file_name.startswith('/cygdrive')] cygdrive_names = [file_name for file_name in file_names if file_name.startswith('/cygdrive')] idl_file_names.extend(resolve_cygpath(cygdrive_names)) files_meta_data = extract_meta_data(idl_file_names) total_partitions = len(output_file_names) for partition, file_name in enumerate(output_file_names): files_meta_data_this_partition = [ meta_data for meta_data in files_meta_data if hash(meta_data['name']) % total_partitions == partition] file_contents = generate_content(component_dir, files_meta_data_this_partition) write_content(file_contents, abs(file_name))
def main(args): if len(args) <= 4: raise Exception('Expected at least 5 arguments.') component_dir = args[1] input_file_name = abs(args[2]) in_out_break_index = args.index('--') output_file_names = args[in_out_break_index + 1:] idl_file_names = read_idl_files_list_from_file(input_file_name) components = set([idl_filename_to_component(filename) for filename in idl_file_names]) if len(components) != 1: raise Exception('Cannot aggregate generated codes in different components') aggregate_partial_interfaces = component_dir not in components files_meta_data = extract_meta_data(idl_file_names) total_partitions = len(output_file_names) for partition, file_name in enumerate(output_file_names): files_meta_data_this_partition = [ meta_data for meta_data in files_meta_data if hash(meta_data['name']) % total_partitions == partition] file_contents = generate_content(component_dir, aggregate_partial_interfaces, files_meta_data_this_partition) write_content(file_contents, abs(file_name))
def generate_bindings(options, input_filename): idl_compiler = IdlCompilerV8( abs(options.output_directory), cache_directory=abs(options.cache_directory), interfaces_info_filename=abs(options.interfaces_info_file), only_if_changed=options.write_file_only_if_changed, target_component=options.target_component) idl_compiler.compile_file(input_filename)
def main(): options, idl_filename = parse_options() idl_compiler = IdlCompilerV8( abs(options.output_directory), cache_directory=abs(options.cache_directory), interfaces_info_filename=abs(options.interfaces_info_file), only_if_changed=options.write_file_only_if_changed) idl_compiler.compile_file(idl_filename)
def main(): options, filenames = parse_options() component = options.component idl_filenames = read_idl_files_list_from_file(abs(filenames[0])) basenames = [ idl_filename_to_basename(file_path) for file_path in idl_filenames ] file_contents = generate_content(component, basenames) write_content(file_contents, abs(filenames[1]))
def generate_bindings(options, input_filename): info_provider = create_component_info_provider(options.info_dir, options.target_component) idl_compiler = IdlCompilerV8( abs(options.output_directory), cache_directory=abs(options.cache_directory), info_provider=info_provider, only_if_changed=options.write_file_only_if_changed, target_component=options.target_component) idl_compiler.compile_file(input_filename)
def main(): options, filenames = parse_options() component = options.component idl_filenames = read_idl_files_list_from_file(abs(filenames[0]), is_gyp_format=False) interface_names = [ idl_filename_to_interface_name(file_path) for file_path in idl_filenames ] file_contents = generate_content(component, interface_names) write_content(file_contents, abs(filenames[1]))
def main(): assert len(sys.argv) == 4 input_file = abs(sys.argv[1]) output_dir = abs(sys.argv[2]) bison_exe = sys.argv[3] path_to_bison = os.path.split(bison_exe)[0] if path_to_bison: # Make sure this path is in the path so that it can find its auxiliary # binaries (in particular, m4). To avoid other 'm4's being found, insert # at head, rather than tail. os.environ['PATH'] = path_to_bison + os.pathsep + os.environ['PATH'] input_name = os.path.basename(input_file) # Output name without directory and extension. output_basename = os.path.splitext(input_name)[0] + '_generated' output_cc = os.path.join(output_dir, output_basename + '.cc') BISON_HEADER_EXT = '.hh' original_output_h = os.path.join(output_dir, output_basename + BISON_HEADER_EXT) return_code = subprocess.call( [bison_exe, '-d', input_file, '-o', output_cc]) assert return_code == 0 # If the file doesn't exist, this raise an OSError. os.stat(original_output_h) # The generated files contain references to the original "foo.hh" for # #include and #line. We replace them with "foo.h". common_replace_list = [(output_basename + BISON_HEADER_EXT, output_basename + '.h')] # Rewrite the generated header with #include guards. CLANG_FORMAT_DISABLE_LINE = "// clang-format off" output_h = os.path.join(output_dir, output_basename + '.h') header_guard = NameStyleConverter(output_h).to_header_guard() modify_file(original_output_h, [ CLANG_FORMAT_DISABLE_LINE, '#ifndef %s' % header_guard, '#define %s' % header_guard ], ['#endif // %s' % header_guard], replace_list=common_replace_list) os.rename(original_output_h, output_h) modify_file(output_cc, [CLANG_FORMAT_DISABLE_LINE], [], replace_list=common_replace_list)
def generate_bindings(code_generator_class, info_provider, options, input_filenames): idl_compiler = IdlCompiler(output_directory=abs(options.output_directory), cache_directory=options.cache_directory, code_generator_class=code_generator_class, info_provider=info_provider, target_component=options.target_component) for idl_filename in input_filenames: idl_compiler.compile_file(idl_filename)
def include_path(idl_filename, implemented_as=None): """Returns relative path to header file in POSIX format; used in includes. POSIX format is used for consistency of output, so reference tests are platform-independent. """ relative_dir = relative_dir_posix(idl_filename) # The generated relative include path might be wrong if the relative path # points to a parent directory in case of shadow build. To avoid jumbled # relative paths use absolute path instead. if relative_dir.startswith(".."): relative_dir = abs(os.path.dirname(idl_filename)) relative_dir = relative_dir.replace(os.path.sep, posixpath.sep) # IDL file basename is used even if only a partial interface file idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename)) cpp_class_name = implemented_as or idl_file_basename return posixpath.join(relative_dir, cpp_class_name + '.h')
def main(argv): # If file itself executed, cache templates try: cache_dir = abs(argv[1]) dummy_filename = argv[2] except IndexError as err: print 'Usage: %s CACHE_DIR DUMMY_FILENAME' % argv[0] return 1 # Cache templates jinja_env = initialize_jinja_env(cache_dir) template_filenames = [filename for filename in os.listdir(templates_dir) # Skip .svn, directories, etc. if filename.endswith(('.cpp', '.h'))] for template_filename in template_filenames: jinja_env.get_template(template_filename) # Create a dummy file as output for the build system, # since filenames of individual cache files are unpredictable and opaque # (they are hashes of the template path, which varies based on environment) with open(dummy_filename, 'w') as dummy_file: pass # |open| creates or touches the file
# found in the LICENSE file. # usage: rule_bison.py INPUT_FILE OUTPUT_DIR [BISON_EXE] # INPUT_FILE is a path to either CSSGrammar.y or XPathGrammar.y. # OUTPUT_DIR is where the bison-generated .cpp and .h files should be placed. import errno import os import os.path import subprocess import sys from utilities import abs assert len(sys.argv) == 3 or len(sys.argv) == 4 inputFile = abs(sys.argv[1]) outputDir = abs(sys.argv[2]) bisonExe = 'bison' if len(sys.argv) > 3: bisonExe = sys.argv[3] pathToBison = os.path.split(bisonExe)[0] if pathToBison: # Make sure this path is in the path so that it can find its auxiliary # binaries (in particular, m4). To avoid other 'm4's being found, insert # at head, rather than tail. os.environ['PATH'] = pathToBison + os.pathsep + os.environ['PATH'] inputName = os.path.basename(inputFile) assert inputName == 'CSSGrammar.y' or inputName == 'XPathGrammar.y' prefix = {'CSSGrammar.y': 'cssyy', 'XPathGrammar.y': 'xpathyy'}[inputName]
def collect_info(self, idl_filename): """Reads an idl file and collects information which is required by the binding code generation.""" def collect_unforgeable_attributes(definition, idl_filename): """Collects [Unforgeable] attributes so that we can define them on sub-interfaces later. The resulting structure is as follows. interfaces_info[interface_name] = { 'unforgeable_attributes': [IdlAttribute, ...], ... } """ interface_info = {} unforgeable_attributes = get_unforgeable_attributes_from_definition( definition) if not unforgeable_attributes: return interface_info if definition.is_partial: interface_basename = idl_filename_to_interface_name( idl_filename) # TODO(yukishiino): [PartialInterfaceImplementedAs] is treated # in interface_dependency_resolver.transfer_extended_attributes. # Come up with a better way to keep them consistent. for attr in unforgeable_attributes: attr.extended_attributes[ 'PartialInterfaceImplementedAs'] = definition.extended_attributes.get( 'ImplementedAs', interface_basename) interface_info['unforgeable_attributes'] = unforgeable_attributes return interface_info definitions = self.reader.read_idl_file(abs(idl_filename)) this_union_types = collect_union_types_from_definitions(definitions) self.union_types.update(this_union_types) self.typedefs.update(definitions.typedefs) for callback_function_name, callback_function in definitions.callback_functions.iteritems( ): # Set 'component_dir' to specify a directory that callback function files belong to self.callback_functions[callback_function_name] = { 'callback_function': callback_function, 'component_dir': idl_filename_to_component(idl_filename), 'full_path': os.path.realpath(idl_filename), } # Check enum duplication. for enum in definitions.enumerations.values(): if not self.check_enum_consistency(enum): raise Exception('Enumeration "%s" is defined more than once ' 'with different valid values' % enum.name) self.enumerations.update(definitions.enumerations) if definitions.interfaces: definition = next(definitions.interfaces.itervalues()) interface_info = { 'is_callback_interface': definition.is_callback, 'is_dictionary': False, # 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_definition(definition), } elif definitions.dictionaries: definition = next(definitions.dictionaries.itervalues()) interface_info = { 'is_callback_interface': False, 'is_dictionary': True, 'referenced_interfaces': None, } else: return if definition.name not in self.interfaces_info: self.interfaces_info[definition.name] = {} # Remember [Unforgeable] attributes. if definitions.interfaces: merge_dict_recursively( self.interfaces_info[definition.name], collect_unforgeable_attributes(definition, idl_filename)) component = idl_filename_to_component(idl_filename) extended_attributes = definition.extended_attributes implemented_as = extended_attributes.get('ImplementedAs') full_path = os.path.realpath(idl_filename) if interface_info['is_dictionary']: this_include_path = include_path(idl_filename) else: this_include_path = include_path(idl_filename, implemented_as) if definition.is_partial: # We don't create interface_info for partial interfaces, but # adds paths to another dict. partial_include_paths = [] if this_include_path: partial_include_paths.append(this_include_path) self.add_paths_to_partials_dict(definition.name, full_path, partial_include_paths) # Collects C++ header paths which should be included from generated # .cpp files. The resulting structure is as follows. # interfaces_info[interface_name] = { # 'cpp_includes': { # 'core': set(['core/foo/Foo.h', ...]), # 'modules': set(['modules/bar/Bar.h', ...]), # }, # ... # } if this_include_path: merge_dict_recursively( self.interfaces_info[definition.name], {'cpp_includes': { component: set([this_include_path]) }}) return # '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_definitions( definitions, definition.name) interface_info.update({ 'extended_attributes': extended_attributes, 'full_path': full_path, 'union_types': this_union_types, 'implemented_as': implemented_as, 'implemented_by_interfaces': left_interfaces, '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, 'parent': definition.parent, 'relative_dir': relative_dir_posix(idl_filename, source_path), }) merge_dict_recursively(self.interfaces_info[definition.name], interface_info)
# found in the LICENSE file. # usage: rule_bison.py INPUT_FILE OUTPUT_DIR BISON_EXE [DEVELOPER_DIR] # INPUT_FILE is a path to either XPathGrammar.y. # OUTPUT_DIR is where the bison-generated .cpp and .h files should be placed. import errno import os import os.path import subprocess import sys from utilities import abs assert len(sys.argv) == 4 or len(sys.argv) == 5 inputFile = abs(sys.argv[1]) outputDir = abs(sys.argv[2]) bisonExe = sys.argv[3] if len(sys.argv) > 4: os.environ['DEVELOPER_DIR'] = sys.argv[4] pathToBison = os.path.split(bisonExe)[0] if pathToBison: # Make sure this path is in the path so that it can find its auxiliary # binaries (in particular, m4). To avoid other 'm4's being found, insert # at head, rather than tail. os.environ['PATH'] = pathToBison + os.pathsep + os.environ['PATH'] inputName = os.path.basename(inputFile) assert inputName == 'XPathGrammar.y' prefix = {'XPathGrammar.y': 'xpathyy'}[inputName]