329
|
1
|
|
2 """
|
|
3 Defines task classes that can compile, link etc..
|
|
4 Task can depend upon one another.
|
|
5 """
|
|
6
|
377
|
7 from .tasks import Task, TaskError, register_task
|
393
|
8 from .buildfunctions import c3compile, link, assemble, fix_object, construct
|
377
|
9 from pyyacc import ParserException
|
|
10 from . import CompilerError
|
329
|
11
|
335
|
12
|
377
|
13 @register_task("empty")
|
|
14 class EmptyTask(Task):
|
|
15 """ Basic task that does nothing """
|
|
16 def run(self):
|
|
17 pass
|
|
18
|
|
19
|
|
20 @register_task("echo")
|
|
21 class EchoTask(Task):
|
|
22 """ Simple task that echoes a message """
|
|
23 def run(self):
|
|
24 message = self.arguments['message']
|
|
25 print(message)
|
366
|
26
|
|
27
|
377
|
28 @register_task("property")
|
|
29 class Property(Task):
|
|
30 """ Sets a property to a value """
|
|
31 def run(self):
|
|
32 name = self.arguments['name']
|
|
33 value = self.arguments['value']
|
|
34 self.target.project.set_property(name, value)
|
331
|
35
|
|
36
|
393
|
37 @register_task("build")
|
|
38 class ConstructTask(Task):
|
|
39 """ Builds another build description file (build.xml) """
|
|
40 def run(self):
|
|
41 project = self.get_argument('file')
|
|
42 construct(project)
|
|
43
|
|
44
|
377
|
45 @register_task("assemble")
|
|
46 class AssembleTask(Task):
|
393
|
47 """ Task that can runs the assembler over the source and enters the
|
334
|
48 output into an object file """
|
329
|
49
|
|
50 def run(self):
|
377
|
51 target = self.get_argument('target')
|
|
52 source = self.relpath(self.get_argument('source'))
|
|
53 output_filename = self.relpath(self.get_argument('output'))
|
|
54
|
|
55 try:
|
|
56 output = assemble(source, target)
|
|
57 except ParserException as e:
|
|
58 raise TaskError('Error during assembly:' + str(e))
|
|
59 except CompilerError as e:
|
|
60 raise TaskError('Error during assembly:' + str(e))
|
381
|
61 except OSError as e:
|
|
62 raise TaskError('Error:' + str(e))
|
377
|
63 with open(output_filename, 'w') as f:
|
|
64 output.save(f)
|
366
|
65 self.logger.debug('Assembling finished')
|
329
|
66
|
|
67
|
377
|
68 @register_task("compile")
|
|
69 class C3cTask(Task):
|
334
|
70 """ Task that compiles C3 source for some target into an object file """
|
329
|
71 def run(self):
|
377
|
72 target = self.get_argument('target')
|
|
73 sources = self.open_file_set(self.arguments['sources'])
|
|
74 output_filename = self.relpath(self.get_argument('output'))
|
|
75 if 'includes' in self.arguments:
|
|
76 includes = self.open_file_set(self.arguments['includes'])
|
|
77 else:
|
|
78 includes = []
|
329
|
79
|
377
|
80 output = c3compile(sources, includes, target)
|
|
81 # Store output:
|
393
|
82 with open(output_filename, 'w') as output_file:
|
|
83 output.save(output_file)
|
329
|
84
|
|
85
|
377
|
86 @register_task("link")
|
|
87 class LinkTask(Task):
|
334
|
88 """ Link together a collection of object files """
|
377
|
89 def run(self):
|
383
|
90 layout = self.relpath(self.get_argument('layout'))
|
385
|
91 target = self.get_argument('target')
|
377
|
92 objects = self.open_file_set(self.get_argument('objects'))
|
385
|
93 output_filename = self.relpath(self.get_argument('output'))
|
334
|
94
|
337
|
95 try:
|
385
|
96 output_obj = link(objects, layout, target)
|
337
|
97 except CompilerError as e:
|
|
98 raise TaskError(e.msg)
|
385
|
99
|
|
100 # Store output:
|
393
|
101 with open(output_filename, 'w') as output_file:
|
|
102 output_obj.save(output_file)
|
329
|
103
|
|
104
|
385
|
105 @register_task("objcopy")
|
377
|
106 class ObjCopyTask(Task):
|
|
107 def run(self):
|
385
|
108 image_name = self.get_argument('imagename')
|
|
109 output_filename = self.relpath(self.get_argument('output'))
|
|
110 object_filename = self.relpath(self.get_argument('objectfile'))
|
329
|
111
|
385
|
112 obj = fix_object(object_filename)
|
|
113 image = obj.get_image(image_name)
|
393
|
114 with open(output_filename, 'wb') as output_file:
|
|
115 output_file.write(image)
|