Mercurial > lcfOS
annotate python/ppci/buildtasks.py @ 383:173e20a47fda
Added linker description loader
author | Windel Bouwman |
---|---|
date | Sun, 27 Apr 2014 17:40:39 +0200 |
parents | 6df89163e114 |
children | d056b552d3f4 |
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 | |
8 | |
377 | 9 from .tasks import Task, TaskError, register_task |
10 from .buildfunctions import c3compile, link, assemble | |
11 from pyyacc import ParserException | |
12 from . import CompilerError | |
329 | 13 |
335 | 14 |
377 | 15 @register_task("empty") |
16 class EmptyTask(Task): | |
17 """ Basic task that does nothing """ | |
18 def run(self): | |
19 pass | |
20 | |
21 | |
22 @register_task("echo") | |
23 class EchoTask(Task): | |
24 """ Simple task that echoes a message """ | |
25 def run(self): | |
26 message = self.arguments['message'] | |
27 print(message) | |
366 | 28 |
29 | |
377 | 30 @register_task("property") |
31 class Property(Task): | |
32 """ Sets a property to a value """ | |
33 def run(self): | |
34 name = self.arguments['name'] | |
35 value = self.arguments['value'] | |
36 self.target.project.set_property(name, value) | |
331 | 37 |
38 | |
377 | 39 @register_task("assemble") |
40 class AssembleTask(Task): | |
334 | 41 """ Task that can runs the assembler over the source and enters the |
42 output into an object file """ | |
329 | 43 |
44 def run(self): | |
377 | 45 target = self.get_argument('target') |
46 source = self.relpath(self.get_argument('source')) | |
47 output_filename = self.relpath(self.get_argument('output')) | |
48 | |
49 try: | |
50 output = assemble(source, target) | |
51 except ParserException as e: | |
52 raise TaskError('Error during assembly:' + str(e)) | |
53 except CompilerError as e: | |
54 raise TaskError('Error during assembly:' + str(e)) | |
381 | 55 except OSError as e: |
56 raise TaskError('Error:' + str(e)) | |
377 | 57 with open(output_filename, 'w') as f: |
58 output.save(f) | |
366 | 59 self.logger.debug('Assembling finished') |
329 | 60 |
61 | |
377 | 62 @register_task("compile") |
63 class C3cTask(Task): | |
334 | 64 """ Task that compiles C3 source for some target into an object file """ |
329 | 65 def run(self): |
377 | 66 target = self.get_argument('target') |
67 sources = self.open_file_set(self.arguments['sources']) | |
68 output_filename = self.relpath(self.get_argument('output')) | |
69 if 'includes' in self.arguments: | |
70 includes = self.open_file_set(self.arguments['includes']) | |
71 else: | |
72 includes = [] | |
329 | 73 |
377 | 74 output = c3compile(sources, includes, target) |
75 # Store output: | |
76 with open(output_filename, 'w') as f: | |
77 output.save(f) | |
329 | 78 |
79 | |
377 | 80 @register_task("link") |
81 class LinkTask(Task): | |
334 | 82 """ Link together a collection of object files """ |
377 | 83 def run(self): |
383 | 84 layout = self.relpath(self.get_argument('layout')) |
377 | 85 objects = self.open_file_set(self.get_argument('objects')) |
86 output_file = self.relpath(self.get_argument('output')) | |
334 | 87 |
337 | 88 try: |
377 | 89 output_obj = link(objects, layout) |
337 | 90 except CompilerError as e: |
91 raise TaskError(e.msg) | |
377 | 92 # 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
|
93 code = output_obj.get_section('code').data |
377 | 94 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
|
95 f.write(code) |
329 | 96 |
97 | |
377 | 98 class ObjCopyTask(Task): |
99 def run(self): | |
100 pass | |
329 | 101 |