def _write_macros_file_v2(self, build_system, output, xml=None): """Write a Macros file for this machine. Arguments: build_system - Format of the file to be written. Currently the only valid values are "Makefile" and "CMake". output - Text I/O object (inheriting from io.TextIOBase) that output should be written to. Typically, this will be the Macros file, opened for writing. """ # Set up writer for this build system. if build_system == "Makefile": writer = MakeMacroWriter(output) elif build_system == "CMake": writer = CMakeMacroWriter(output) else: expect( False, "Unrecognized build system provided to write_macros: " + build_system) # Start processing the file. value_lists = dict() node_list = [] if xml is None: node_list = self.get_nodes("compiler") else: node_list = ET.parse(xml).findall("compiler") for compiler_elem in node_list: block = CompilerBlock(writer, compiler_elem, self._machobj) # If this block matches machine settings, use it. if block.matches_machine(): block.add_settings_to_lists(self.flag_vars, value_lists) # Now that we've scanned through the input, output the variable # settings. vars_written = set() while value_lists: # Variables that are ready to be written. ready_variables = [ var_name for var_name in value_lists.keys() if value_lists[var_name].depends <= vars_written ] expect( len(ready_variables) > 0, "The config_build XML has bad <var> references. " "Check for circular references or variables that " "are in a <var> tag but not actually defined.") big_normal_tree = None big_append_tree = None for var_name in ready_variables: # Note that we're writing this variable. vars_written.add(var_name) # Make the conditional trees and write them out. normal_tree, append_tree = \ value_lists[var_name].to_cond_trees() big_normal_tree = merge_optional_trees(normal_tree, big_normal_tree) big_append_tree = merge_optional_trees(append_tree, big_append_tree) # Remove this variable from the list of variables to handle # next iteration. del value_lists[var_name] if big_normal_tree is not None: big_normal_tree.write_out(writer) if big_append_tree is not None: big_append_tree.write_out(writer)
def _write_macros_file(self, build_system, output, xml=None): """Write a Macros file for this machine. Arguments: build_system - Format of the file to be written. Currently the only valid values are "Makefile" and "CMake". output - Text I/O object (inheriting from io.TextIOBase) that output should be written to. Typically, this will be the Macros file, opened for writing. """ # Set up writer for this build system. if build_system == "Makefile": writer = MakeMacroWriter(output) elif build_system == "CMake": writer = CMakeMacroWriter(output) else: expect( False, "Unrecognized build system provided to write_macros: " + build_system, ) # Start processing the file. value_lists = dict() node_list = [] if xml is None: node_list = self.get_children(name="compiler") else: gen_xml = GenericXML() gen_xml.read_fd(xml) node_list = gen_xml.get_children(name="compiler") for compiler_elem in node_list: block = CompilerBlock(writer, compiler_elem, self._machobj, self) # If this block matches machine settings, use it. if block.matches_machine(): block.add_settings_to_lists(self.flag_vars, value_lists) # Now that we've scanned through the input, output the variable # settings. vars_written = set() while value_lists: # Variables that are ready to be written. ready_variables = [ var_name for var_name in value_lists if value_lists[var_name].dependencies() <= vars_written ] expect( len(ready_variables) > 0, "The file {} has bad $VAR references. " "Check for circular references or variables that " "are used in a $VAR but not actually defined.".format(self.filename), ) big_normal_trees = {} big_append_tree = None for var_name in ready_variables: # Note that we're writing this variable. vars_written.add(var_name) # Make the conditional trees and write them out. normal_trees, append_tree = value_lists[var_name].to_cond_trees() for spec in normal_trees: if spec in big_normal_trees: big_normal_trees[spec] = merge_optional_trees( normal_trees[spec], big_normal_trees[spec] ) else: big_normal_trees[spec] = normal_trees[spec] big_append_tree = merge_optional_trees(append_tree, big_append_tree) # Remove this variable from the list of variables to handle # next iteration. del value_lists[var_name] specificities = sorted(list(big_normal_trees.keys())) for spec in specificities: big_normal_trees[spec].write_out(writer) if big_append_tree is not None: big_append_tree.write_out(writer)