Mercurial > lcfOS
annotate python/ppci/buildtasks.py @ 377:9667d78ba79e
Switched to xml for project description
author | Windel Bouwman |
---|---|
date | Fri, 11 Apr 2014 15:47:50 +0200 |
parents | 39bf68bf1891 |
children | 6df89163e114 |
rev | line source |
---|---|
329 | 1 |
2 """ | |
3 Defines task classes that can compile, link etc.. | |
4 Task can depend upon one another. | |
5 """ | |
6 | |
7 import logging | |
377 | 8 import json |
329 | 9 |
377 | 10 from .tasks import Task, TaskError, register_task |
11 from .buildfunctions import c3compile, link, assemble | |
12 from pyyacc import ParserException | |
13 from . import CompilerError | |
329 | 14 |
335 | 15 |
377 | 16 @register_task("empty") |
17 class EmptyTask(Task): | |
18 """ Basic task that does nothing """ | |
19 def run(self): | |
20 pass | |
21 | |
22 | |
23 @register_task("echo") | |
24 class EchoTask(Task): | |
25 """ Simple task that echoes a message """ | |
26 def run(self): | |
27 message = self.arguments['message'] | |
28 print(message) | |
366 | 29 |
30 | |
377 | 31 @register_task("property") |
32 class Property(Task): | |
33 """ Sets a property to a value """ | |
34 def run(self): | |
35 name = self.arguments['name'] | |
36 value = self.arguments['value'] | |
37 self.target.project.set_property(name, value) | |
331 | 38 |
39 | |
377 | 40 @register_task("assemble") |
41 class AssembleTask(Task): | |
334 | 42 """ Task that can runs the assembler over the source and enters the |
43 output into an object file """ | |
329 | 44 |
45 def run(self): | |
377 | 46 target = self.get_argument('target') |
47 source = self.relpath(self.get_argument('source')) | |
48 output_filename = self.relpath(self.get_argument('output')) | |
49 | |
50 try: | |
51 output = assemble(source, target) | |
52 except ParserException as e: | |
53 raise TaskError('Error during assembly:' + str(e)) | |
54 except CompilerError as e: | |
55 raise TaskError('Error during assembly:' + str(e)) | |
56 with open(output_filename, 'w') as f: | |
57 output.save(f) | |
366 | 58 self.logger.debug('Assembling finished') |
329 | 59 |
60 | |
377 | 61 @register_task("compile") |
62 class C3cTask(Task): | |
334 | 63 """ Task that compiles C3 source for some target into an object file """ |
329 | 64 def run(self): |
377 | 65 target = self.get_argument('target') |
66 sources = self.open_file_set(self.arguments['sources']) | |
67 output_filename = self.relpath(self.get_argument('output')) | |
68 if 'includes' in self.arguments: | |
69 includes = self.open_file_set(self.arguments['includes']) | |
70 else: | |
71 includes = [] | |
329 | 72 |
377 | 73 output = c3compile(sources, includes, target) |
74 # Store output: | |
75 with open(output_filename, 'w') as f: | |
76 output.save(f) | |
329 | 77 |
78 | |
377 | 79 def make_num(txt): |
80 if txt.startswith('0x'): | |
81 return int(txt[2:], 16) | |
82 else: | |
83 return int(txt) | |
329 | 84 |
85 | |
377 | 86 def load_layout(filename): |
87 """ Load a linker layout file which contains directives where sections | |
88 must be placed into memory. """ | |
89 try: | |
90 with open(filename, 'r') as f: | |
91 layout = json.load(f) | |
92 except OSError as e: | |
93 raise TaskError(str(e)) | |
94 for s in layout: | |
95 layout[s] = make_num(layout[s]) | |
96 return layout | |
97 | |
98 | |
99 @register_task("link") | |
100 class LinkTask(Task): | |
334 | 101 """ Link together a collection of object files """ |
377 | 102 def run(self): |
103 layout = load_layout(self.relpath(self.get_argument('layout'))) | |
104 objects = self.open_file_set(self.get_argument('objects')) | |
105 output_file = self.relpath(self.get_argument('output')) | |
334 | 106 |
337 | 107 try: |
377 | 108 output_obj = link(objects, layout) |
337 | 109 except CompilerError as e: |
110 raise TaskError(e.msg) | |
377 | 111 # TODO: use layout here: |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
112 code = output_obj.get_section('code').data |
377 | 113 with open(output_file, 'wb') as f: |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
114 f.write(code) |
329 | 115 |
116 | |
377 | 117 class ObjCopyTask(Task): |
118 def run(self): | |
119 pass | |
329 | 120 |