diff python/ppci/recipe.py @ 377:9667d78ba79e

Switched to xml for project description
author Windel Bouwman
date Fri, 11 Apr 2014 15:47:50 +0200
parents 577ed7fb3fe4
children
line wrap: on
line diff
--- a/python/ppci/recipe.py	Tue Mar 25 19:36:51 2014 +0100
+++ b/python/ppci/recipe.py	Fri Apr 11 15:47:50 2014 +0200
@@ -1,69 +1,52 @@
-import os
-import yaml
+#!/usr/bin/python3
 
-from .buildtasks import Compile, Assemble, Link
-from .objectfile import ObjectFile
-from .target.target_list import targets
+import os
+import xml.dom.minidom
+
+from .tasks import Project, Target
 
 
 class RecipeLoader:
     """ Loads a recipe into a runner from a dictionary or file """
-    def __init__(self, runner):
-        self.runner = runner
-        self.directive_handlers = {}
-        for a in dir(self):
-            if a.startswith('handle_'):
-                f = getattr(self, a)
-                self.directive_handlers[a[7:]] = f
+    def load_file(self, recipe_file):
+        """ Loads a build configuration from file """
+        recipe_dir = os.path.abspath(os.path.dirname(recipe_file))
+        dom = xml.dom.minidom.parse(recipe_file)
+        project = self.load_project(dom)
+        project.set_property('basedir', recipe_dir)
+        return project
 
-    def load_file(self, recipe_file):
-        """ Loads a recipe dictionary from file """
-        self.recipe_dir = os.path.abspath(os.path.dirname(recipe_file))
-        with open(recipe_file, 'r') as f:
-            recipe = yaml.load(f)
-        self.load_dict(recipe)
-
-    def relpath(self, filename):
-        return os.path.join(self.recipe_dir, filename)
-
-    def openfile(self, filename):
-        return open(self.relpath(filename), 'r')
-
-    def handle_compile(self, value):
-        sources = [self.openfile(s) for s in value['sources']]
-        if 'includes' in value:
-            includes = [self.openfile(i) for i in value['includes']]
+    def load_project(self, elem):
+        elem = elem.getElementsByTagName("project")[0]
+        name = elem.getAttribute('name')
+        project = Project(name)
+        if elem.hasAttribute('default'):
+            project.default = elem.getAttribute('default')
         else:
-            includes = []
-        target = targets[value['machine']]
-        output = ObjectFile()
-        task = Compile(sources, includes, target, output)
-        self.runner.add_task(task)
-        return task
-
-    def handle_assemble(self, value):
-        asm_src = self.openfile(value['source'])
-        target = targets[value['machine']]
-        output = ObjectFile()
-        task = Assemble(asm_src, target, output)
-        self.runner.add_task(task)
-        return task
+            project.default = None
 
-    def handle_link(self, value):
-        inputs = value['inputs']
-        objs = []
-        for i in inputs:
-            task = self.load_dict(i)
-            objs.append(task.output)
-        layout = value['layout']
-        output = self.relpath(value['output'])
-        self.runner.add_task(Link(objs, layout, output))
+        for pe in elem.getElementsByTagName("property"):
+            name = pe.getAttribute('name')
+            value = pe.getAttribute('value')
+            project.set_property(name, value)
+        for te in elem.getElementsByTagName("target"):
+            name = te.getAttribute('name')
+            target = Target(name, project)
+            if te.hasAttribute('depends'):
+                dependencies = te.getAttribute('depends').split(',')
+                for dep in dependencies:
+                    target.add_dependency(dep)
+            # print(name)
+            project.add_target(target)
+            for cn in te.childNodes:
+                # print(cn, type(cn))
+                if type(cn) is xml.dom.minidom.Element:
+                    task_name = cn.tagName
+                    task_props = {}
+                    for i in range(cn.attributes.length):
+                        atr = cn.attributes.item(i)
+                        #print(atr, atr.name, atr.value)
+                        task_props[atr.name] = atr.value
+                    target.add_task((task_name, task_props))
+        return project
 
-    def handle_apps(self, value):
-        for a in value:
-            self.load_dict(a)
-
-    def load_dict(self, recipe):
-        for command, value in recipe.items():
-            return self.directive_handlers[command](value)
-