Mercurial > lcfOS
comparison python/ppci/recipe.py @ 342:86b02c98a717 devel
Moved target directory
author | Windel Bouwman |
---|---|
date | Sat, 01 Mar 2014 15:40:31 +0100 |
parents | |
children | b8ad45b3a573 |
comparison
equal
deleted
inserted
replaced
341:4d204f6f7d4e | 342:86b02c98a717 |
---|---|
1 import os | |
2 import yaml | |
3 | |
4 from .buildtasks import Compile, Assemble, Link | |
5 from .objectfile import ObjectFile | |
6 from .target.target_list import target_list | |
7 | |
8 | |
9 targets = {t.name: t for t in target_list} | |
10 targetnames = list(targets.keys()) | |
11 | |
12 class RecipeLoader: | |
13 """ Loads a recipe into a runner from a dictionary or file """ | |
14 def __init__(self): | |
15 self.directive_handlers = {} | |
16 for a in dir(self): | |
17 if a.startswith('handle_'): | |
18 f = getattr(self, a) | |
19 self.directive_handlers[a[7:]] = f | |
20 | |
21 def load_file(self, recipe_file, runner): | |
22 """ Loads a recipe dictionary into a task runner """ | |
23 self.recipe_dir = os.path.abspath(os.path.dirname(recipe_file)) | |
24 with open(recipe_file, 'r') as f: | |
25 recipe = yaml.load(f) | |
26 self.runner = runner | |
27 self.load_dict(recipe) | |
28 | |
29 def relpath(self, filename): | |
30 return os.path.join(self.recipe_dir, filename) | |
31 | |
32 def openfile(self, filename): | |
33 return open(self.relpath(filename), 'r') | |
34 | |
35 def handle_compile(self, value): | |
36 sources = [self.openfile(s) for s in value['sources']] | |
37 includes = [self.openfile(i) for i in value['includes']] | |
38 target = targets[value['machine']] | |
39 output = ObjectFile() | |
40 task = Compile(sources, includes, target, output) | |
41 self.runner.add_task(task) | |
42 return task | |
43 | |
44 def handle_assemble(self, value): | |
45 asm_src = self.openfile(value['source']) | |
46 target = targets[value['machine']] | |
47 output = ObjectFile() | |
48 task = Assemble(asm_src, target, output) | |
49 self.runner.add_task(task) | |
50 return task | |
51 | |
52 def handle_link(self, value): | |
53 inputs = value['inputs'] | |
54 objs = [] | |
55 for i in inputs: | |
56 task = self.load_dict(i) | |
57 objs.append(task.output) | |
58 layout = value['layout'] | |
59 output = self.relpath(value['output']) | |
60 self.runner.add_task(Link(objs, layout, output)) | |
61 | |
62 def handle_apps(self, value): | |
63 for a in value: | |
64 self.load_dict(a) | |
65 | |
66 def load_dict(self, recipe): | |
67 for command, value in recipe.items(): | |
68 return self.directive_handlers[command](value) | |
69 | |
70 | |
71 |