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
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
1
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
2 """
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
3 Defines task classes that can compile, link etc..
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
4 Task can depend upon one another.
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
5 """
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
6
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
7 import logging
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
8
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
9 from .tasks import Task, TaskError, register_task
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
10 from .buildfunctions import c3compile, link, assemble
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
11 from pyyacc import ParserException
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
12 from . import CompilerError
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
13
335
582a1aaa3983 Added long branch format
Windel Bouwman
parents: 334
diff changeset
14
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
15 @register_task("empty")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
16 class EmptyTask(Task):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
17 """ Basic task that does nothing """
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
18 def run(self):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
19 pass
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
20
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
21
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
22 @register_task("echo")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
23 class EchoTask(Task):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
24 """ Simple task that echoes a message """
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
25 def run(self):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
26 message = self.arguments['message']
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
27 print(message)
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 354
diff changeset
28
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 354
diff changeset
29
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
30 @register_task("property")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
31 class Property(Task):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
32 """ Sets a property to a value """
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
33 def run(self):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
34 name = self.arguments['name']
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
35 value = self.arguments['value']
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
36 self.target.project.set_property(name, value)
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
37
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
38
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
39 @register_task("assemble")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
40 class AssembleTask(Task):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
41 """ Task that can runs the assembler over the source and enters the
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
42 output into an object file """
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
43
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
44 def run(self):
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
45 target = self.get_argument('target')
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
46 source = self.relpath(self.get_argument('source'))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
47 output_filename = self.relpath(self.get_argument('output'))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
48
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
49 try:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
50 output = assemble(source, target)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
51 except ParserException as e:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
52 raise TaskError('Error during assembly:' + str(e))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
53 except CompilerError as e:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
54 raise TaskError('Error during assembly:' + str(e))
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 377
diff changeset
55 except OSError as e:
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 377
diff changeset
56 raise TaskError('Error:' + str(e))
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
57 with open(output_filename, 'w') as f:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
58 output.save(f)
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 354
diff changeset
59 self.logger.debug('Assembling finished')
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
60
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
61
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
62 @register_task("compile")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
63 class C3cTask(Task):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
64 """ Task that compiles C3 source for some target into an object file """
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
65 def run(self):
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
66 target = self.get_argument('target')
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
67 sources = self.open_file_set(self.arguments['sources'])
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
68 output_filename = self.relpath(self.get_argument('output'))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
69 if 'includes' in self.arguments:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
70 includes = self.open_file_set(self.arguments['includes'])
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
71 else:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
72 includes = []
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
73
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
74 output = c3compile(sources, includes, target)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
75 # Store output:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
76 with open(output_filename, 'w') as f:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
77 output.save(f)
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
78
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
79
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
80 @register_task("link")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
81 class LinkTask(Task):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
82 """ Link together a collection of object files """
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
83 def run(self):
383
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
84 layout = self.relpath(self.get_argument('layout'))
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
85 objects = self.open_file_set(self.get_argument('objects'))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
86 output_file = self.relpath(self.get_argument('output'))
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
87
337
b00219172a42 Added cool lm3s811 qemu project
Windel Bouwman
parents: 336
diff changeset
88 try:
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
89 output_obj = link(objects, layout)
337
b00219172a42 Added cool lm3s811 qemu project
Windel Bouwman
parents: 336
diff changeset
90 except CompilerError as e:
b00219172a42 Added cool lm3s811 qemu project
Windel Bouwman
parents: 336
diff changeset
91 raise TaskError(e.msg)
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
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
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
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
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
96
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
97
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
98 class ObjCopyTask(Task):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
99 def run(self):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
100 pass
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
101