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
|
385
|
10 from .buildfunctions import c3compile, link, assemble, fix_object
|
377
|
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'))
|
385
|
85 target = self.get_argument('target')
|
377
|
86 objects = self.open_file_set(self.get_argument('objects'))
|
385
|
87 output_filename = self.relpath(self.get_argument('output'))
|
334
|
88
|
337
|
89 try:
|
385
|
90 output_obj = link(objects, layout, target)
|
337
|
91 except CompilerError as e:
|
|
92 raise TaskError(e.msg)
|
385
|
93
|
|
94 # Store output:
|
|
95 with open(output_filename, 'w') as f:
|
|
96 output_obj.save(f)
|
329
|
97
|
|
98
|
385
|
99 @register_task("objcopy")
|
377
|
100 class ObjCopyTask(Task):
|
|
101 def run(self):
|
385
|
102 image_name = self.get_argument('imagename')
|
|
103 output_filename = self.relpath(self.get_argument('output'))
|
|
104 object_filename = self.relpath(self.get_argument('objectfile'))
|
329
|
105
|
385
|
106 obj = fix_object(object_filename)
|
|
107 image = obj.get_image(image_name)
|
|
108 with open(output_filename, 'wb') as f:
|
|
109 f.write(image)
|
|
110
|