def run(self, project): self.apply_preset(project.presets) # Compile objects first for obj in self.objects: obj.run(project) obj_files = flatten([o.get_files() for o in self.objects]) log(1, 'compile {} -> {}'.format(str(obj_files), self.output)) self.compiler.create_shlib(untempl(self.output, project.props), obj_files, self.linked_libs, self.params)
def parse_prop(node: ET.Element, props: Dict, prefix: str = ''): if not parse_conditional(node, props): return name = prefix + node.attrib['name'] if 'value' in node.attrib and name not in props: # Some properties may just be containers and have no value props[name] = untempl(node.attrib['value'], props) # Nested properties for child in node.iterfind('property'): if child is not node: parse_prop(child, props, prefix=name + '.')
def __init__(self, node: ET.Element, props: Dict, **kwargs): filesets = kwargs['filesets'] if 'source' in node.attrib: # some old files may have these raise ParseError( '`source` attribute is deprecated. Switch to `src`.') if 'source-set' in node.attrib: raise ParseError( '`source-set` attribute is deprecated. Switch to `src-set`.') if 'src' in node.attrib: self.source = [untempl(node.attrib['src'], props)] elif 'src-set' in node.attrib: self.source = filesets[node.attrib['src-set']].get_files() else: self.source = None self.file = untempl( node.attrib['file'], props ) if 'file' in node.attrib else None # file overrides source if specified if self.file: self.output = [self.file] elif 'output' in node.attrib: self.output = [untempl(node.attrib['output'], props)] else: self.output = [path + '.o' for path in self.source] self.compiler = compilers.find( name=node.attrib['compiler'] if 'compiler' in node.attrib else None, # name overrides lang if specified lang=node.attrib['lang'] if 'lang' in node.attrib else None) self._preset_name = node.attrib[ 'preset'] if 'preset' in node.attrib else None self.params = parse_preset(node, props) self.for_shlib = False
def __init__(self, node, props: Dict, **kwargs): # Parse attributes self.output = untempl(node.attrib['output'], props) if 'output' in node.attrib else None self.compiler = compilers.find( name=node.attrib['compiler'] if 'compiler' in node.attrib else None, # name overrides lang if specified lang=node.attrib['lang'] if 'lang' in node.attrib else None) self._preset_name = node.attrib[ 'preset'] if 'preset' in node.attrib else None self.params = parse_preset(node, props) # Parse ingredients (subtags) self.objects = [] self.linked_libs = []
def get_libpath(node: ET.Element, props: Dict) -> str: if 'libpath' in node.attrib: return untempl(node.attrib['libpath'], props)
def __init__(self, node, props: Dict, **kwargs): self.text = untempl(node.text, props) if node.text else ''
def run(self, project): log(0, untempl(self.text, project.props))
def import_xml(self, root: ET.Element, file=''): if root.tag != 'buildcc': raise ParseError( f'file `{file}` is not a buildcc file. (root tag is `{root.tag}`)' ) parse_args = {"props": self.props, "filesets": self.filesets} # Parse imports for node in root.iterfind('import'): file = untempl(node.attrib['file'], self.props) log(3, 'Importing `{}`.'.format(file)) self.import_file(file) # Parse properties def parse_prop(node: ET.Element, props: Dict, prefix: str = ''): if not parse_conditional(node, props): return name = prefix + node.attrib['name'] if 'value' in node.attrib and name not in props: # Some properties may just be containers and have no value props[name] = untempl(node.attrib['value'], props) # Nested properties for child in node.iterfind('property'): if child is not node: parse_prop(child, props, prefix=name + '.') for node in root.iterfind('property'): parse_prop(node, self.props) # Parse presets def get_preset(name): if name in self.presets: # Return it if it already exists return self.presets[name] else: node = root.find("preset[@name='%s']" % name) if node is None: raise KeyError('No preset named {}.'.format(name)) # If the node has a parent, get the parent values first and # then overwrite them with this presets params. if 'parent' in node.attrib: params = get_preset(node.attrib['parent']).copy() params = update_preset(params, parse_preset(node, self.props)) else: params = parse_preset(node, self.props) return params for node in root.iterfind('preset'): preset = get_preset(node.attrib['name']) self.presets[node.attrib['name']] = preset # Parse filesets for node in root.iterfind('fileset'): self.filesets[node.attrib['name']] = FileSet(node, **parse_args) # Parse targets for node in root.iterfind('target'): try: self.targets[node.attrib['name']] = Target(node, **parse_args) except KeyError: raise ParseError('Element missing `name` attribute.')
def __init__(self, node: ET.Element, props: Dict, **kwargs): self.pattern = os.path.abspath( untempl(node.attrib['pattern'], props) )